Bug 1663992 - Check loading principal if there is no browsing context in AntiTrackingUtils::ComputeIsThirdPartyToTopWindow(). r=dimi, a=pascalc FIREFOX_81_0_2_BUILD1 FIREFOX_81_0_2_RELEASE
authorTim Huang <tihuang@mozilla.com>
Mon, 21 Sep 2020 12:41:24 +0000
changeset 614841 bdb93bd9b26d6480c04eeda33896e826a8e9255e
parent 614840 c1986de311b05e9085622d9bff7f28e0522e3c13
child 614842 1e79586438cfd92e407751f76f183a1450414cdf
push id2427
push userarchaeopteryx@coole-files.de
push dateMon, 12 Oct 2020 08:58:04 +0000
treeherdermozilla-release@bdb93bd9b26d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdimi, pascalc
bugs1663992
milestone81.0.2
Bug 1663992 - Check loading principal if there is no browsing context in AntiTrackingUtils::ComputeIsThirdPartyToTopWindow(). r=dimi, a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D90816
toolkit/components/antitracking/AntiTrackingUtils.cpp
--- a/toolkit/components/antitracking/AntiTrackingUtils.cpp
+++ b/toolkit/components/antitracking/AntiTrackingUtils.cpp
@@ -559,24 +559,37 @@ void AntiTrackingUtils::ComputeIsThirdPa
   if (policyType == nsIContentPolicy::TYPE_DOCUMENT) {
     loadInfo->SetIsThirdPartyContextToTopWindow(false);
     return;
   }
 
   RefPtr<BrowsingContext> bc;
   loadInfo->GetBrowsingContext(getter_AddRefs(bc));
 
-  // In xpcshell-tests we don't always have a browsingContext.
+  nsCOMPtr<nsIURI> uri;
+  Unused << aChannel->GetURI(getter_AddRefs(uri));
+
+  // In some cases we don't have a browsingContext. For example, in xpcshell
+  // tests or channels that are used to download images.
   if (!bc) {
+    // We turn to check the loading principal if there is no browsing context.
+    auto* loadingPrincipal =
+        BasePrincipal::Cast(loadInfo->GetLoadingPrincipal());
+
+    if (uri && loadingPrincipal) {
+      bool isThirdParty = true;
+      nsresult rv = loadingPrincipal->IsThirdPartyURI(uri, &isThirdParty);
+
+      if (NS_SUCCEEDED(rv)) {
+        loadInfo->SetIsThirdPartyContextToTopWindow(isThirdParty);
+      }
+    }
     return;
   }
 
-  nsCOMPtr<nsIURI> uri;
-  Unused << aChannel->GetURI(getter_AddRefs(uri));
-
   RefPtr<WindowGlobalParent> topWindow =
       GetTopWindowExcludingExtensionAccessibleContentFrames(bc->Canonical(),
                                                             uri);
 
   if (NS_WARN_IF(!topWindow)) {
     return;
   }