Bug 1536110 - StorageAccess should be propagated to workers, r=Ehsan a=pascalc
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 20 Mar 2019 01:06:33 +0000
changeset 525908 7c44e976056eca85a5b9945bc9c42ace1e9310ac
parent 525907 db23516c1a2aa62b77ff9ac18f27dee6adaac2ac
child 525909 df26e30d2c9e37174c887f2ee15109bd90597ca3
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan, pascalc
bugs1536110
milestone67.0
Bug 1536110 - StorageAccess should be propagated to workers, r=Ehsan a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D23861
dom/base/nsGlobalWindowInner.cpp
toolkit/components/antitracking/test/browser/browser.ini
toolkit/components/antitracking/test/browser/browser_workerPropagation.js
toolkit/components/antitracking/test/browser/workerIframe.html
--- a/dom/base/nsGlobalWindowInner.cpp
+++ b/dom/base/nsGlobalWindowInner.cpp
@@ -6806,16 +6806,18 @@ void nsGlobalWindowInner::StoreSharedWor
 void nsGlobalWindowInner::ForgetSharedWorker(SharedWorker* aSharedWorker) {
   MOZ_ASSERT(aSharedWorker);
   MOZ_ASSERT(mSharedWorkers.Contains(aSharedWorker));
 
   mSharedWorkers.RemoveElement(aSharedWorker);
 }
 
 void nsGlobalWindowInner::StorageAccessGranted() {
+  PropagateFirstPartyStorageAccessGrantedToWorkers(this);
+
   // If we have a partitioned localStorage, it's time to replace it with a real
   // one in order to receive notifications.
 
   if (mLocalStorage &&
       mLocalStorage->Type() == Storage::ePartitionedLocalStorage) {
     IgnoredErrorResult error;
     GetLocalStorage(error);
     if (NS_WARN_IF(error.Failed())) {
--- a/toolkit/components/antitracking/test/browser/browser.ini
+++ b/toolkit/components/antitracking/test/browser/browser.ini
@@ -80,8 +80,10 @@ skip-if = serviceworker_e10s
 [browser_storageAccessWithHeuristics.js]
 [browser_allowPermissionForTracker.js]
 [browser_denyPermissionForTracker.js]
 [browser_localStorageEvents.js]
 support-files = localStorage.html
 [browser_partitionedLocalStorage.js]
 [browser_partitionedLocalStorage_events.js]
 support-files = localStorageEvents.html
+[browser_workerPropagation.js]
+support-files = workerIframe.html
new file mode 100644
--- /dev/null
+++ b/toolkit/components/antitracking/test/browser/browser_workerPropagation.js
@@ -0,0 +1,74 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/* eslint-disable mozilla/no-arbitrary-setTimeout */
+
+add_task(async function() {
+  info("Starting subResources test");
+
+  await SpecialPowers.flushPrefEnv();
+  await SpecialPowers.pushPrefEnv({"set": [
+    ["browser.contentblocking.allowlist.annotations.enabled", true],
+    ["browser.contentblocking.allowlist.storage.enabled", true],
+    [ContentBlocking.prefIntroCount, ContentBlocking.MAX_INTROS],
+    ["dom.storage_access.auto_grants", true],
+    ["dom.storage_access.auto_grants.delayed", false],
+    ["dom.storage_access.enabled", true],
+    ["dom.storage_access.prompt.testing", false],
+    ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
+    ["privacy.trackingprotection.enabled", false],
+    ["privacy.trackingprotection.pbmode.enabled", false],
+    ["privacy.trackingprotection.annotate_channels", true],
+    ["privacy.restrict3rdpartystorage.userInteractionRequiredForHosts", "tracking.example.com,tracking.example.org"],
+  ]});
+
+  await UrlClassifierTestUtils.addTestTrackers();
+
+  info("Creating a new tab");
+  let tab = BrowserTestUtils.addTab(gBrowser, TEST_TOP_PAGE);
+  gBrowser.selectedTab = tab;
+
+  let browser = gBrowser.getBrowserForTab(tab);
+  await BrowserTestUtils.browserLoaded(browser);
+
+  // Let's create an iframe and run the test there.
+  let page = TEST_3RD_PARTY_DOMAIN + TEST_PATH + "workerIframe.html";
+  await ContentTask.spawn(browser, page, async function(page) {
+    await new content.Promise(resolve => {
+      let ifr = content.document.createElement("iframe");
+      ifr.id = "test";
+
+      content.addEventListener("message", e => {
+        if (e.data.type == "finish") {
+          resolve();
+          return;
+        }
+
+        if (e.data.type == "info") {
+          info(e.data.msg);
+          return;
+        }
+
+        if (e.data.type == "ok") {
+          ok(e.data.what, e.data.msg);
+          return;
+        }
+
+        ok(false, "Unknown message");
+      });
+
+      content.document.body.appendChild(ifr);
+      ifr.src = page;
+    });
+  });
+
+  info("Removing the tab");
+  BrowserTestUtils.removeTab(tab);
+});
+
+add_task(async function() {
+  info("Cleaning up.");
+  await new Promise(resolve => {
+    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
+  });
+});
new file mode 100644
--- /dev/null
+++ b/toolkit/components/antitracking/test/browser/workerIframe.html
@@ -0,0 +1,71 @@
+<html>
+<head>
+  <title>3rd party content!</title>
+  <script type="text/javascript" src="https://example.com/browser/toolkit/components/antitracking/test/browser/storageAccessAPIHelpers.js"></script>
+</head>
+<body>
+<h1>Here the 3rd party content!</h1>
+<script>
+
+function info(msg) {
+  parent.postMessage({ type: "info", msg }, "*");
+}
+
+function ok(what, msg) {
+  parent.postMessage({ type: "ok", what: !!what, msg }, "*");
+}
+
+function is(a, b, msg) {
+  ok(a === b, msg);
+}
+
+async function runTest() {
+  function workerCode() {
+    onmessage = e => {
+      try {
+        indexedDB.open("test", "1");
+        postMessage(true);
+      } catch (e) {
+        postMessage(false);
+      }
+    };
+  }
+
+  /* import-globals-from storageAccessAPIHelpers.js */
+  await noStorageAccessInitially();
+  info("Initialized");
+
+  let blob = new Blob([workerCode.toString() + "; workerCode();"]);
+  let blobURL = URL.createObjectURL(blob);
+  info("Blob created");
+
+  let w = new Worker(blobURL);
+  info("Worker created");
+
+  await new Promise(resolve => {
+    w.addEventListener("message", e => {
+      ok(!e.data, "IDB is disabled");
+      resolve();
+    }, { once: true });
+    w.postMessage("go");
+  });
+
+  /* import-globals-from storageAccessAPIHelpers.js */
+  await callRequestStorageAccess();
+
+  await new Promise(resolve => {
+    w.addEventListener("message", e => {
+      ok(e.data, "IDB is enabled");
+      resolve();
+    }, { once: true });
+    w.postMessage("go");
+  });
+
+  parent.postMessage({ type: "finish" }, "*");
+}
+
+runTest();
+
+</script>
+</body>
+</html>