diff --git a/.eslintrc.js b/.eslintrc.js index c35d8fa..3876d96 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -10,7 +10,8 @@ module.exports = { ], "globals": { "CustomizableUI": true, - "CustomizableWidgets": true + "CustomizableWidgets": true, + "SessionStore": true }, "plugins": [ "promise" diff --git a/index.js b/index.js index 522a632..46338e7 100644 --- a/index.js +++ b/index.js @@ -53,6 +53,7 @@ const windowUtils = require("sdk/window/utils"); Cu.import("resource:///modules/CustomizableUI.jsm"); Cu.import("resource:///modules/CustomizableWidgets.jsm"); +Cu.import("resource:///modules/sessionstore/SessionStore.jsm"); // ---------------------------------------------------------------------------- // ContainerService @@ -363,7 +364,14 @@ const ContainerService = { return promise.then(() => { 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(); + + // forget about this tab. 0 is the index of the forgotten tab and 0 + // means the last one. + SessionStore.forgetClosedTab(window, 0); } }).catch(() => null); }, @@ -755,6 +763,7 @@ const ContainerService = { return this._closeTabs(tabsToClose).then(() => { const removed = ContextualIdentityService.remove(args.userContextId); + this._forgetIdentity(args.userContextId); return this._refreshNeeded().then(() => removed ); }); }, @@ -885,8 +894,12 @@ const ContainerService = { tabsToClose.push(tab); } } + this._closeTabs(tabsToClose); + // Let's forget all the previous closed tabs. + this._forgetIdentity(); + const preInstalledIdentities = data.preInstalledIdentities; ContextualIdentityService.getIdentities().forEach(identity => { if (!preInstalledIdentities.includes(identity.userContextId)) { @@ -897,6 +910,23 @@ const ContainerService = { // Let's delete the configuration. 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); + } + } + } + }, }; // ----------------------------------------------------------------------------