Bug 1554781 - Part 2: Provide support for the storage access API and the associated heuristics for dynamic FPI; r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 28 May 2019 12:06:37 +0000
changeset 475946 452b8c9f9a1349f44e523711f2f0f32dc927ba3c
parent 475945 2191d21821d5792731da4c99c96fb476e31ca5f6
child 475947 ece4def4fd82ec30ac258028858e93a5b1d88630
push id36080
push usernerli@mozilla.com
push dateWed, 29 May 2019 09:48:47 +0000
treeherdermozilla-central@d78adc84bde8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1554781
milestone69.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 1554781 - Part 2: Provide support for the storage access API and the associated heuristics for dynamic FPI; r=baku Differential Revision: https://phabricator.services.mozilla.com/D32766
toolkit/components/antitracking/AntiTrackingCommon.cpp
--- a/toolkit/components/antitracking/AntiTrackingCommon.cpp
+++ b/toolkit/components/antitracking/AntiTrackingCommon.cpp
@@ -1237,32 +1237,34 @@ bool AntiTrackingCommon::IsFirstPartySto
     return false;
   }
 
   MOZ_ASSERT(
       behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER ||
       behavior ==
           nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN);
 
+  uint32_t blockedReason =
+      nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER;
+
   if (behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER) {
     if (!nsContentUtils::IsThirdPartyTrackingResourceWindow(aWindow)) {
       LOG(("Our window isn't a third-party tracking window"));
       return true;
     }
   } else {
     MOZ_ASSERT(behavior ==
                nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN);
     if (nsContentUtils::IsThirdPartyTrackingResourceWindow(aWindow)) {
       // fall through
     } else if (nsContentUtils::IsThirdPartyWindowOrChannel(aWindow, nullptr,
                                                            aURI)) {
       LOG(("We're in the third-party context, storage should be partitioned"));
-      *aRejectedReason =
-          nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN;
-      return false;
+      // fall through, but remember that we're partitioning.
+      blockedReason = nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN;
     } else {
       LOG(("Our window isn't a third-party window, storage is allowed"));
       return true;
     }
   }
 
 #ifdef DEBUG
   nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil = services::GetThirdPartyUtil();
@@ -1281,17 +1283,17 @@ bool AntiTrackingCommon::IsFirstPartySto
   nsCOMPtr<nsIPrincipal> parentPrincipal;
   nsCOMPtr<nsIURI> parentPrincipalURI;
   nsCOMPtr<nsIURI> trackingURI;
   nsAutoCString trackingOrigin;
   if (!GetParentPrincipalAndTrackingOrigin(
           nsGlobalWindowInner::Cast(aWindow), getter_AddRefs(parentPrincipal),
           trackingOrigin, getter_AddRefs(trackingURI), nullptr)) {
     LOG(("Failed to obtain the parent principal and the tracking origin"));
-    *aRejectedReason = nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER;
+    *aRejectedReason = blockedReason;
     return false;
   }
   Unused << parentPrincipal->GetURI(getter_AddRefs(parentPrincipalURI));
 
   nsAutoCString grantedOrigin;
   nsresult rv = nsContentUtils::GetASCIIOrigin(aURI, grantedOrigin);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     LOG_SPEC(("Failed to compute the origin from %s", _spec), aURI);
@@ -1321,17 +1323,17 @@ bool AntiTrackingCommon::IsFirstPartySto
 
   LOG_SPEC(
       ("Testing permission type %s for %s resulted in %d (%s)", type.get(),
        _spec, int(result),
        result == nsIPermissionManager::ALLOW_ACTION ? "success" : "failure"),
       parentPrincipalURI);
 
   if (result != nsIPermissionManager::ALLOW_ACTION) {
-    *aRejectedReason = nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER;
+    *aRejectedReason = blockedReason;
     return false;
   }
 
   return true;
 }
 
 bool AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(
     nsIHttpChannel* aChannel, nsIURI* aURI, uint32_t* aRejectedReason) {
@@ -1494,48 +1496,50 @@ bool AntiTrackingCommon::IsFirstPartySto
     return false;
   }
 
   MOZ_ASSERT(
       behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER ||
       behavior ==
           nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN);
 
+  uint32_t blockedReason =
+      nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER;
+
   // Not a tracker.
   if (behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER) {
     if (!aChannel->IsThirdPartyTrackingResource()) {
       LOG(("Our channel isn't a third-party tracking channel"));
       return true;
     }
   } else {
     MOZ_ASSERT(behavior ==
                nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN);
     if (aChannel->IsThirdPartyTrackingResource()) {
       // fall through
     } else if (nsContentUtils::IsThirdPartyWindowOrChannel(nullptr, aChannel,
                                                            aURI)) {
       LOG(("We're in the third-party context, storage should be partitioned"));
-      *aRejectedReason =
-          nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN;
-      return false;
+      // fall through but remember that we're partitioning.
+      blockedReason = nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN;
     } else {
       LOG(("Our channel isn't a third-party channel, storage is allowed"));
       return true;
     }
   }
 
   nsIPrincipal* parentPrincipal = loadInfo->GetTopLevelStorageAreaPrincipal();
   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->GetTopLevelPrincipal()) {
       LOG(("Parent window is the top-level window, bail out early"));
-      *aRejectedReason = nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER;
+      *aRejectedReason = blockedReason;
       return false;
     }
 
     parentPrincipal = toplevelPrincipal;
     if (NS_WARN_IF(!parentPrincipal)) {
       LOG(
           ("No triggering principal, this shouldn't be happening! Bail out "
            "early"));
@@ -1589,17 +1593,17 @@ bool AntiTrackingCommon::IsFirstPartySto
 
   LOG_SPEC(
       ("Testing permission type %s for %s resulted in %d (%s)", type.get(),
        _spec, int(result),
        result == nsIPermissionManager::ALLOW_ACTION ? "success" : "failure"),
       parentPrincipalURI);
 
   if (result != nsIPermissionManager::ALLOW_ACTION) {
-    *aRejectedReason = nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER;
+    *aRejectedReason = blockedReason;
     return false;
   }
 
   return true;
 }
 
 bool AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(
     nsIPrincipal* aPrincipal, nsICookieSettings* aCookieSettings) {