Bug 1486092 - Part 2: Make the reject tracker cookie behavior also depend on the browser.contentblocking.enabled pref; r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 24 Aug 2018 18:54:10 -0400
changeset 433460 b6c0d8e69ddc829c0c021af6cb815983b0d29521
parent 433459 537688d789650bfd285a6e6fc88903b089f40be2
child 433461 389b7c456a910ba9f035c451a0cfca1b6378c49d
push id107078
push usereakhgari@mozilla.com
push dateMon, 27 Aug 2018 13:22:10 +0000
treeherdermozilla-inbound@389b7c456a91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1486092
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1486092 - Part 2: Make the reject tracker cookie behavior also depend on the browser.contentblocking.enabled pref; r=baku The semantics implemented are as follows: the feature requires this new pref to also be set to true, otherwise cookies from trackers will be accepted.
dom/base/nsDocument.cpp
dom/workers/RuntimeService.cpp
toolkit/components/antitracking/AntiTrackingCommon.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -12648,17 +12648,18 @@ nsIDocument::SetDocTreeHadPlayRevoked()
     topLevelDoc->mDocTreeHadPlayRevoked = true;
   }
 }
 
 void
 nsIDocument::MaybeAllowStorageForOpener()
 {
   if (StaticPrefs::network_cookie_cookieBehavior() !=
-        nsICookieService::BEHAVIOR_REJECT_TRACKER) {
+        nsICookieService::BEHAVIOR_REJECT_TRACKER ||
+      !StaticPrefs::browser_contentblocking_enabled()) {
     return;
   }
 
   // This will probably change for project fission, but currently this document
   // and the opener are on the same process. In the future, we should make this
   // part async.
 
   nsPIDOMWindowInner* inner = GetInnerWindow();
--- a/dom/workers/RuntimeService.cpp
+++ b/dom/workers/RuntimeService.cpp
@@ -2266,17 +2266,18 @@ RuntimeService::ResumeWorkersForWindow(n
 }
 
 void
 RuntimeService::PropagateFirstPartyStorageAccessGranted(nsPIDOMWindowInner* aWindow)
 {
   AssertIsOnMainThread();
   MOZ_ASSERT(aWindow);
   MOZ_ASSERT(StaticPrefs::network_cookie_cookieBehavior() ==
-               nsICookieService::BEHAVIOR_REJECT_TRACKER);
+               nsICookieService::BEHAVIOR_REJECT_TRACKER &&
+             StaticPrefs::browser_contentblocking_enabled());
 
   nsTArray<WorkerPrivate*> workers;
   GetWorkersForWindow(aWindow, workers);
 
   for (uint32_t index = 0; index < workers.Length(); index++) {
     workers[index]->PropagateFirstPartyStorageAccessGranted();
   }
 }
@@ -2880,17 +2881,18 @@ ResumeWorkersForWindow(nsPIDOMWindowInne
   }
 }
 
 void
 PropagateFirstPartyStorageAccessGrantedToWorkers(nsPIDOMWindowInner* aWindow)
 {
   AssertIsOnMainThread();
   MOZ_ASSERT(StaticPrefs::network_cookie_cookieBehavior() ==
-               nsICookieService::BEHAVIOR_REJECT_TRACKER);
+               nsICookieService::BEHAVIOR_REJECT_TRACKER &&
+             StaticPrefs::browser_contentblocking_enabled());
 
   RuntimeService* runtime = RuntimeService::GetService();
   if (runtime) {
     runtime->PropagateFirstPartyStorageAccessGranted(aWindow);
   }
 }
 
 WorkerPrivate*
--- a/toolkit/components/antitracking/AntiTrackingCommon.cpp
+++ b/toolkit/components/antitracking/AntiTrackingCommon.cpp
@@ -145,16 +145,21 @@ AntiTrackingCommon::AddFirstPartyStorage
 
   if (StaticPrefs::network_cookie_cookieBehavior() !=
         nsICookieService::BEHAVIOR_REJECT_TRACKER) {
     LOG(("Disabled by network.cookie.cookieBehavior pref (%d), bailing out early",
          StaticPrefs::network_cookie_cookieBehavior()));
     return StorageAccessGrantPromise::CreateAndResolve(true, __func__);
   }
 
+  if (!StaticPrefs::browser_contentblocking_enabled()) {
+    LOG(("The content blocking pref has been disabled, bail out early"));
+    return StorageAccessGrantPromise::CreateAndResolve(true, __func__);
+  }
+
   nsCOMPtr<nsIPrincipal> topLevelStoragePrincipal;
   nsAutoCString trackingOrigin;
 
   nsGlobalWindowInner* parentWindow = nsGlobalWindowInner::Cast(aParentWindow);
   nsGlobalWindowOuter* outerParentWindow =
     nsGlobalWindowOuter::Cast(parentWindow->GetOuterWindow());
   if (NS_WARN_IF(!outerParentWindow)) {
     LOG(("No outer window found for our parent window, bailing out early"));
@@ -319,16 +324,24 @@ AntiTrackingCommon::IsFirstPartyStorageA
     // simply rejecting the request to use the storage. In the future, if we
     // change the meaning of BEHAVIOR_LIMIT_FOREIGN to be one which makes sense
     // for non-cookie storage types, this may change.
     LOG(("Nothing more to do due to the behavior code %d", int(behavior)));
     return false;
   }
 
   MOZ_ASSERT(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER);
+
+  // Now, we have to also honour the Content Blocking pref.
+  if (!StaticPrefs::browser_contentblocking_enabled()) {
+    LOG(("The content blocking pref has been disabled, bail out early by "
+         "by pretending our window isn't a tracking window"));
+    return true;
+  }
+
   if (!nsContentUtils::IsTrackingResourceWindow(aWindow)) {
     LOG(("Our window isn't a tracking window"));
     return true;
   }
 
   nsCOMPtr<nsIPrincipal> parentPrincipal;
   nsAutoCString trackingOrigin;
   if (!GetParentPrincipalAndTrackingOrigin(nsGlobalWindowInner::Cast(aWindow),
@@ -479,16 +492,23 @@ AntiTrackingCommon::IsFirstPartyStorageA
     // change the meaning of BEHAVIOR_LIMIT_FOREIGN to be one which makes sense
     // for non-cookie storage types, this may change.
     LOG(("Nothing more to do due to the behavior code %d", int(behavior)));
     return false;
   }
 
   MOZ_ASSERT(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER);
 
+  // Now, we have to also honour the Content Blocking pref.
+  if (!StaticPrefs::browser_contentblocking_enabled()) {
+    LOG(("The content blocking pref has been disabled, bail out early by "
+         "pretending our channel isn't a tracking channel"));
+    return true;
+  }
+
   nsIPrincipal* parentPrincipal = loadInfo->TopLevelStorageAreaPrincipal();
   if (!parentPrincipal) {
     LOG(("No top-level storage area principal at hand"));
 
     // parentPrincipal can be null if the parent window is not the top-level
     // window.
     if (loadInfo->TopLevelPrincipal()) {
       LOG(("Parent window is the top-level window, bail out early"));
@@ -586,16 +606,22 @@ AntiTrackingCommon::MaybeIsFirstPartySto
 
   if (StaticPrefs::network_cookie_cookieBehavior() !=
         nsICookieService::BEHAVIOR_REJECT_TRACKER) {
     LOG(("Disabled by the pref (%d), bail out early",
          StaticPrefs::network_cookie_cookieBehavior()));
     return true;
   }
 
+  // Now, we have to also honour the Content Blocking pref.
+  if (!StaticPrefs::browser_contentblocking_enabled()) {
+    LOG(("The content blocking pref has been disabled, bail out early"));
+    return true;
+  }
+
   if (!nsContentUtils::IsThirdPartyWindowOrChannel(aFirstPartyWindow,
                                                    nullptr, aURI)) {
     LOG(("Our window isn't a third-party window"));
     return true;
   }
 
   nsCOMPtr<nsIPrincipal> parentPrincipal =
     nsGlobalWindowInner::Cast(aFirstPartyWindow)->GetPrincipal();