Bug 1501006 - Reject cookieStoreId when contextual identities are disabled. r=mixedpuppy, a=RyanVM
authorRob Wu <rob@robwu.nl>
Mon, 29 Oct 2018 13:23:12 +0000
changeset 500946 5d62582ba7ae1aed3ddfddf355abd84274ac9de1
parent 500945 a78fa2f251c0f213f7b06f45e7488e4f22a9a429
child 500947 d709ec7593d0670a1de6df5ec39e6e34b9ef5ca9
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy, RyanVM
bugs1501006
milestone64.0
Bug 1501006 - Reject cookieStoreId when contextual identities are disabled. r=mixedpuppy, a=RyanVM Depends on D9517 Differential Revision: https://phabricator.services.mozilla.com/D9518
browser/components/extensions/test/browser/browser_ext_tabs_cookieStoreId.js
browser/components/extensions/test/browser/browser_ext_windows_create_cookieStoreId.js
toolkit/components/extensions/parent/ext-tabs-base.js
--- a/browser/components/extensions/test/browser/browser_ext_tabs_cookieStoreId.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_cookieStoreId.js
@@ -180,8 +180,28 @@ add_task(async function perma_private_br
       browser.test.sendMessage("done");
     },
   });
   await extension.startup();
   await extension.awaitMessage("done");
   await extension.unload();
   await SpecialPowers.popPrefEnv();
 });
+
+add_task(async function userContext_disabled() {
+  await SpecialPowers.pushPrefEnv({"set": [["privacy.userContext.enabled", false]]});
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      "permissions": ["tabs", "cookies"],
+    },
+    async background() {
+      await browser.test.assertRejects(
+        browser.tabs.create({cookieStoreId: "firefox-container-1"}),
+        /Contextual identities are currently disabled/,
+        "should refuse to open container tab when contextual identities are disabled");
+      browser.test.sendMessage("done");
+    },
+  });
+  await extension.startup();
+  await extension.awaitMessage("done");
+  await extension.unload();
+  await SpecialPowers.popPrefEnv();
+});
--- a/browser/components/extensions/test/browser/browser_ext_windows_create_cookieStoreId.js
+++ b/browser/components/extensions/test/browser/browser_ext_windows_create_cookieStoreId.js
@@ -77,16 +77,36 @@ add_task(async function perma_private_br
     },
   });
   await extension.startup();
   await extension.awaitMessage("done");
   await extension.unload();
   await SpecialPowers.popPrefEnv();
 });
 
+add_task(async function userContext_disabled() {
+  await SpecialPowers.pushPrefEnv({"set": [["privacy.userContext.enabled", false]]});
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      "permissions": ["tabs", "cookies"],
+    },
+    async background() {
+      await browser.test.assertRejects(
+        browser.windows.create({cookieStoreId: "firefox-container-1"}),
+        /Contextual identities are currently disabled/,
+        "cookieStoreId cannot be a container tab ID when contextual identities are disabled");
+      browser.test.sendMessage("done");
+    },
+  });
+  await extension.startup();
+  await extension.awaitMessage("done");
+  await extension.unload();
+  await SpecialPowers.popPrefEnv();
+});
+
 add_task(async function valid_cookieStoreId() {
   await SpecialPowers.pushPrefEnv({"set": [
     ["privacy.userContext.enabled", true],
   ]});
 
   const testCases = [{
     description: "no explicit URL",
     createParams: {
--- a/toolkit/components/extensions/parent/ext-tabs-base.js
+++ b/toolkit/components/extensions/parent/ext-tabs-base.js
@@ -6,16 +6,18 @@
 "use strict";
 
 /* globals EventEmitter */
 
 ChromeUtils.defineModuleGetter(this, "PrivateBrowsingUtils",
                                "resource://gre/modules/PrivateBrowsingUtils.jsm");
 ChromeUtils.defineModuleGetter(this, "Services",
                                "resource://gre/modules/Services.jsm");
+XPCOMUtils.defineLazyPreferenceGetter(this, "containersEnabled",
+                                      "privacy.userContext.enabled");
 
 var {
   DefaultMap,
   DefaultWeakMap,
   ExtensionError,
   getWinUtils,
 } = ExtensionUtils;
 
@@ -2071,16 +2073,19 @@ function getUserContextIdForCookieStoreI
     throw new ExtensionError(`Illegal to set private cookieStoreId in a non-private window`);
   }
 
   if (isContainerCookieStoreId(cookieStoreId)) {
     if (PrivateBrowsingUtils.permanentPrivateBrowsing) {
       // Container tabs are not supported in perma-private browsing mode - bug 1320757
       throw new ExtensionError(`Contextual identities are unavailable in permanent private browsing mode`);
     }
+    if (!containersEnabled) {
+      throw new ExtensionError(`Contextual identities are currently disabled`);
+    }
     let userContextId = getContainerForCookieStoreId(cookieStoreId);
     if (!userContextId) {
       throw new ExtensionError(`No cookie store exists with ID ${cookieStoreId}`);
     }
     return userContextId;
   }
 
   return Services.scriptSecurityManager.DEFAULT_USER_CONTEXT_ID;