Tab created when all the others are closed - issue #151

This commit is contained in:
baku 2017-02-06 14:50:29 +01:00
parent 931417f433
commit 71d8bcbd94

View file

@ -229,6 +229,29 @@ const ContainerService = {
return userContextId in this._identitiesState; return userContextId in this._identitiesState;
}, },
_closeTabs(tabsToClose) {
// We create a new tab only if the current operation closes all the
// existing ones.
if (tabs.length !== tabsToClose.length) {
return Promise.resolve(null);
}
const browserWin = windowUtils.getMostRecentBrowserWindow();
// This should not really happen.
if (!browserWin || !browserWin.gBrowser) {
return Promise.resolve(null);
}
browserWin.gBrowser.addTab();
for (let tab of tabsToClose) { // eslint-disable-line prefer-const
tab.close();
}
return Promise.resolve(null);
},
// Tabs management // Tabs management
hideTabs(args) { hideTabs(args) {
@ -241,7 +264,8 @@ const ContainerService = {
return Promise.resolve(null); return Promise.resolve(null);
} }
return new Promise(resolve => { const tabsToClose = [];
this._containerTabIterator(args.userContextId, tab => { this._containerTabIterator(args.userContextId, tab => {
const object = this._createTabObject(tab); const object = this._createTabObject(tab);
@ -256,11 +280,10 @@ const ContainerService = {
}); });
this._identitiesState[args.userContextId].hiddenTabUrls.push(object); this._identitiesState[args.userContextId].hiddenTabUrls.push(object);
tab.close(); tabsToClose.push(tab);
}); });
resolve(null); return this._closeTabs(tabsToClose);
});
}, },
showTabs(args) { showTabs(args) {
@ -529,16 +552,14 @@ const ContainerService = {
return Promise.reject("removeIdentity must be called with userContextId argument."); return Promise.reject("removeIdentity must be called with userContextId argument.");
} }
const tabsToClose = [];
this._containerTabIterator(args.userContextId, tab => { this._containerTabIterator(args.userContextId, tab => {
tab.close(); tabsToClose.push(tab);
}); });
return this._closeTabs(tabsToClose).then(() => {
const removed = ContextualIdentityService.remove(args.userContextId); const removed = ContextualIdentityService.remove(args.userContextId);
return this._refreshNeeded().then(() => removed );
this._refreshNeeded().then(() => {
return removed;
}).catch(() => {
return removed;
}); });
}, },
@ -782,7 +803,7 @@ ContainerWindow.prototype = {
// containerAddonMagic attribute is a custom attribute we set in order to // containerAddonMagic attribute is a custom attribute we set in order to
// know if this menu has been already converted. // know if this menu has been already converted.
if (!menu || menu.hasAttribute("containerAddonMagic")) { if (!menu || menu.hasAttribute("containerAddonMagic")) {
return Promise.reject(null); return Promise.resolve(null);
} }
// We don't want to recreate the menu each time. // We don't want to recreate the menu each time.