Forget tabs when hidden or when an identity is removed or when the addon is disabled.

This commit is contained in:
baku 2017-02-18 15:40:54 +01:00
parent 1774c531a2
commit ee571bc0b5
2 changed files with 32 additions and 1 deletions

View file

@ -10,7 +10,8 @@ module.exports = {
], ],
"globals": { "globals": {
"CustomizableUI": true, "CustomizableUI": true,
"CustomizableWidgets": true "CustomizableWidgets": true,
"SessionStore": true
}, },
"plugins": [ "plugins": [
"promise" "promise"

View file

@ -53,6 +53,7 @@ const windowUtils = require("sdk/window/utils");
Cu.import("resource:///modules/CustomizableUI.jsm"); Cu.import("resource:///modules/CustomizableUI.jsm");
Cu.import("resource:///modules/CustomizableWidgets.jsm"); Cu.import("resource:///modules/CustomizableWidgets.jsm");
Cu.import("resource:///modules/sessionstore/SessionStore.jsm");
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// ContainerService // ContainerService
@ -363,7 +364,14 @@ const ContainerService = {
return promise.then(() => { return promise.then(() => {
for (let tab of tabsToClose) { // eslint-disable-line prefer-const for (let tab of tabsToClose) { // eslint-disable-line prefer-const
// after .close() window is null. Let's take it now.
const window = viewFor(tab.window);
tab.close(); tab.close();
// forget about this tab. 0 is the index of the forgotten tab and 0
// means the last one.
SessionStore.forgetClosedTab(window, 0);
} }
}).catch(() => null); }).catch(() => null);
}, },
@ -755,6 +763,7 @@ const ContainerService = {
return this._closeTabs(tabsToClose).then(() => { return this._closeTabs(tabsToClose).then(() => {
const removed = ContextualIdentityService.remove(args.userContextId); const removed = ContextualIdentityService.remove(args.userContextId);
this._forgetIdentity(args.userContextId);
return this._refreshNeeded().then(() => removed ); return this._refreshNeeded().then(() => removed );
}); });
}, },
@ -885,8 +894,12 @@ const ContainerService = {
tabsToClose.push(tab); tabsToClose.push(tab);
} }
} }
this._closeTabs(tabsToClose); this._closeTabs(tabsToClose);
// Let's forget all the previous closed tabs.
this._forgetIdentity();
const preInstalledIdentities = data.preInstalledIdentities; const preInstalledIdentities = data.preInstalledIdentities;
ContextualIdentityService.getIdentities().forEach(identity => { ContextualIdentityService.getIdentities().forEach(identity => {
if (!preInstalledIdentities.includes(identity.userContextId)) { if (!preInstalledIdentities.includes(identity.userContextId)) {
@ -897,6 +910,23 @@ const ContainerService = {
// Let's delete the configuration. // Let's delete the configuration.
delete ss.storage.savedConfiguration; delete ss.storage.savedConfiguration;
}, },
_forgetIdentity(userContextId = 0) {
for (let window of windows.browserWindows) { // eslint-disable-line prefer-const
window = viewFor(window);
const closedTabData = JSON.parse(SessionStore.getClosedTabData(window));
for (let i = closedTabData.length - 1; i >= 0; --i) {
if (!closedTabData[i].state.userContextId) {
continue;
}
if (userContextId === 0 ||
closedTabData[i].state.userContextId === userContextId) {
SessionStore.forgetClosedTab(window, i);
}
}
}
},
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------