Bug 1340450 - When containers are disabled, it should not be possible to reopen container tabs, r=mdeboer

This commit is contained in:
Andrea Marchesini 2017-02-20 15:55:05 +01:00
parent f256497070
commit b4c474e3d2
5 changed files with 123 additions and 1 deletions

View File

@ -85,6 +85,7 @@ var gPrivacyPane = {
let count = ContextualIdentityService.countContainerTabs(); let count = ContextualIdentityService.countContainerTabs();
if (count == 0) { if (count == 0) {
ContextualIdentityService.disableContainers();
Services.prefs.setBoolPref("privacy.userContext.enabled", false); Services.prefs.setBoolPref("privacy.userContext.enabled", false);
return; return;
} }
@ -105,6 +106,7 @@ var gPrivacyPane = {
okButton, cancelButton, null, null, {}); okButton, cancelButton, null, null, {});
if (rv == 0) { if (rv == 0) {
ContextualIdentityService.closeContainerTabs(); ContextualIdentityService.closeContainerTabs();
ContextualIdentityService.disableContainers();
Services.prefs.setBoolPref("privacy.userContext.enabled", false); Services.prefs.setBoolPref("privacy.userContext.enabled", false);
return; return;
} }

View File

@ -45,7 +45,7 @@ const OBSERVING = [
"quit-application-granted", "browser-lastwindow-close-granted", "quit-application-granted", "browser-lastwindow-close-granted",
"quit-application", "browser:purge-session-history", "quit-application", "browser:purge-session-history",
"browser:purge-domain-data", "browser:purge-domain-data",
"idle-daily", "idle-daily", "clear-origin-attributes-data"
]; ];
// XUL Window properties to (re)store // XUL Window properties to (re)store
@ -748,6 +748,13 @@ var SessionStoreInternal = {
this.onIdleDaily(); this.onIdleDaily();
this._notifyOfClosedObjectsChange(); this._notifyOfClosedObjectsChange();
break; break;
case "clear-origin-attributes-data":
let userContextId = 0;
try {
userContextId = JSON.parse(aData).userContextId;
} catch(e) {}
if (userContextId)
this._forgetTabsWithUserContextId(userContextId);
} }
}, },
@ -2582,6 +2589,33 @@ var SessionStoreInternal = {
return undefined; return undefined;
}, },
// This method deletes all the closedTabs matching userContextId.
_forgetTabsWithUserContextId(userContextId) {
let windowsEnum = Services.wm.getEnumerator("navigator:browser");
while (windowsEnum.hasMoreElements()) {
let window = windowsEnum.getNext();
let windowState = this._windows[window.__SSi];
if (windowState) {
// In order to remove the tabs in the correct order, we store the
// indexes, into an array, then we revert the array and remove closed
// data from the last one going backward.
let indexes = [];
windowState._closedTabs.forEach((closedTab, index) => {
if (closedTab.state.userContextId == userContextId) {
indexes.push(index);
}
});
for (let index of indexes.reverse()) {
this.removeClosedTabData(windowState._closedTabs, index);
}
}
}
// Notify of changes to closed objects.
this._notifyOfClosedObjectsChange();
},
/** /**
* Restores the session state stored in LastSession. This will attempt * Restores the session state stored in LastSession. This will attempt
* to merge data into the current session. If a window was opened at startup * to merge data into the current session. If a window was opened at startup

View File

@ -243,3 +243,5 @@ skip-if = !e10s # GroupedSHistory is e10s-only
[browser_closed_objects_changed_notifications_tabs.js] [browser_closed_objects_changed_notifications_tabs.js]
[browser_closed_objects_changed_notifications_windows.js] [browser_closed_objects_changed_notifications_windows.js]
[browser_disable_containers.js]

View File

@ -0,0 +1,77 @@
"use strict";
/**
* This test is to see if tabs can be reopened when containers are disabled.
*/
Cu.import("resource:///modules/sessionstore/SessionStore.jsm");
async function openAndCloseTab(window, userContextId, url) {
let tab = window.gBrowser.addTab(url, { userContextId });
await promiseBrowserLoaded(tab.linkedBrowser, true, url);
await TabStateFlusher.flush(tab.linkedBrowser);
await promiseRemoveTab(tab);
}
async function openTab(window, userContextId, url) {
let tab = window.gBrowser.addTab(url, { userContextId });
await promiseBrowserLoaded(tab.linkedBrowser, true, url);
await TabStateFlusher.flush(tab.linkedBrowser);
}
async function openWindow(url) {
let win = await promiseNewWindowLoaded();
let flags = Ci.nsIWebNavigation.LOAD_FLAGS_REPLACE_HISTORY;
win.gBrowser.selectedBrowser.loadURIWithFlags(url, flags);
await promiseBrowserLoaded(win.gBrowser.selectedBrowser, true, url);
return win;
}
add_task(function* test_undoCloseById() {
// Clear the lists of closed windows and tabs.
forgetClosedWindows();
while (SessionStore.getClosedTabCount(window)) {
SessionStore.forgetClosedTab(window, 0);
}
// Open a new window.
let win = yield openWindow("about:robots");
// Open and close a tab.
yield openAndCloseTab(win, 0, "about:mozilla");
is(SessionStore.lastClosedObjectType, "tab", "The last closed object is a tab");
// Open and close a container tab.
yield openAndCloseTab(win, 3, "about:about");
is(SessionStore.lastClosedObjectType, "tab", "The last closed object is a tab");
// Restore the last closed tab.
let tab = SessionStore.undoCloseTab(win, 0);
yield promiseBrowserLoaded(tab.linkedBrowser);
is(tab.linkedBrowser.currentURI.spec, "about:about", "The expected tab was re-opened");
is(tab.getAttribute("usercontextid"), 3, "No userContextId for this tab");
// Open a few container tabs.
yield openTab(win, 1, "about:robots");
yield openTab(win, 1, "about:about");
yield openTab(win, 2, "about:profiles");
// Let's simulate the disabling of containers.
ContextualIdentityService.closeContainerTabs();
ContextualIdentityService.disableContainers();
// Let's check we don't have container tab opened.
for (let i = 0; i < win.gBrowser.tabContainer.childNodes.length; ++i) {
let tab = win.gBrowser.tabContainer.childNodes[i];
ok(!tab.hasAttribute("usercontextid"), "No userContextId for this tab");
}
// Restore the last closed tab (we don't want the container tabs).
tab = SessionStore.undoCloseTab(win, 0);
yield promiseBrowserLoaded(tab.linkedBrowser);
is(tab.linkedBrowser.currentURI.spec, "about:mozilla", "The expected tab was re-opened");
ok(!tab.hasAttribute("usercontextid"), "No userContextId for this tab");
// Close the window again.
yield BrowserTestUtils.closeWindow(win);
});

View File

@ -298,6 +298,13 @@ _ContextualIdentityService.prototype = {
}, userContextId); }, userContextId);
}, },
disableContainers() {
for (let identity of this._identities) {
Services.obs.notifyObservers(null, "clear-origin-attributes-data",
JSON.stringify({ userContextId: identity.userContextId }));
}
},
_forEachContainerTab(callback, userContextId = 0) { _forEachContainerTab(callback, userContextId = 0) {
let windowList = Services.wm.getEnumerator("navigator:browser"); let windowList = Services.wm.getEnumerator("navigator:browser");
while (windowList.hasMoreElements()) { while (windowList.hasMoreElements()) {