Merge pull request #154 from bakulf/delete
Tab created when all the others are closed - issue #151
This commit is contained in:
commit
d7cf5db417
1 changed files with 43 additions and 22 deletions
65
index.js
65
index.js
|
@ -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,26 +264,26 @@ const ContainerService = {
|
||||||
return Promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise(resolve => {
|
const tabsToClose = [];
|
||||||
this._containerTabIterator(args.userContextId, tab => {
|
|
||||||
const object = this._createTabObject(tab);
|
|
||||||
|
|
||||||
// This tab is going to be closed. Let's mark this tabObject as
|
this._containerTabIterator(args.userContextId, tab => {
|
||||||
// non-active.
|
const object = this._createTabObject(tab);
|
||||||
object.active = false;
|
|
||||||
|
|
||||||
getFavicon(object.url).then(url => {
|
// This tab is going to be closed. Let's mark this tabObject as
|
||||||
object.favicon = url;
|
// non-active.
|
||||||
}).catch(() => {
|
object.active = false;
|
||||||
object.favicon = "";
|
|
||||||
});
|
|
||||||
|
|
||||||
this._identitiesState[args.userContextId].hiddenTabUrls.push(object);
|
getFavicon(object.url).then(url => {
|
||||||
tab.close();
|
object.favicon = url;
|
||||||
|
}).catch(() => {
|
||||||
|
object.favicon = "";
|
||||||
});
|
});
|
||||||
|
|
||||||
resolve(null);
|
this._identitiesState[args.userContextId].hiddenTabUrls.push(object);
|
||||||
|
tabsToClose.push(tab);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
});
|
});
|
||||||
|
|
||||||
const removed = ContextualIdentityService.remove(args.userContextId);
|
return this._closeTabs(tabsToClose).then(() => {
|
||||||
|
const removed = ContextualIdentityService.remove(args.userContextId);
|
||||||
this._refreshNeeded().then(() => {
|
return this._refreshNeeded().then(() => removed );
|
||||||
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.
|
||||||
|
|
Loading…
Add table
Reference in a new issue