Bug 1612378 - Part 2: Update the IsOnContentBlockingAllowList boolean in the CookieJarSettings when doing a top-level load. r=dimi,baku
authorTim Huang <tihuang@mozilla.com>
Wed, 25 Mar 2020 13:20:29 +0000
changeset 520367 a1f77b99a1b846a6b1b57749968b1fee64c010fe
parent 520366 f1be7541d81cd555327bc3b159c8a9e2c1119c56
child 520368 1b39850be0bee76c13ec627c7a3ae2a46c5320b7
push id37249
push userdvarga@mozilla.com
push dateWed, 25 Mar 2020 21:39:06 +0000
treeherdermozilla-central@b3c3f7d0f044 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdimi, baku
bugs1612378
milestone76.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 1612378 - Part 2: Update the IsOnContentBlockingAllowList boolean in the CookieJarSettings when doing a top-level load. r=dimi,baku In this patch, we update the IsOnContentBlockingAllowList boolean in the CookieJarSettings when doing a top-level load. The boolean will be set in DocumentLoadListener::Open(). And this boolean would be propagated with the CookieJarSettings. So, we can check this boolean to see if the top-level site is in the ContentBlockingAllowList. In addition, we remove setting the ContentBlockingAllowListPrincipal to the httpBaseChannel in DocumentLoadListener::Open(). Because we can use the IsOnContentBlockingAllowList directly without the principal. Differential Revision: https://phabricator.services.mozilla.com/D66209
netwerk/ipc/DocumentLoadListener.cpp
--- a/netwerk/ipc/DocumentLoadListener.cpp
+++ b/netwerk/ipc/DocumentLoadListener.cpp
@@ -12,16 +12,17 @@
 #include "mozilla/LoadInfo.h"
 #include "mozilla/MozPromiseInlines.h"  // For MozPromise::FromDomPromise
 #include "mozilla/dom/CanonicalBrowsingContext.h"
 #include "mozilla/dom/ClientChannelHelper.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/ContentProcessManager.h"
 #include "mozilla/dom/ipc/IdType.h"
 #include "mozilla/dom/ServiceWorkerManager.h"
+#include "mozilla/net/CookieJarSettings.h"
 #include "mozilla/net/HttpChannelParent.h"
 #include "mozilla/net/RedirectChannelRegistrar.h"
 #include "nsDocShell.h"
 #include "nsDocShellLoadState.h"
 #include "nsHttpChannel.h"
 #include "nsISecureBrowserUI.h"
 #include "nsRedirectHistoryEntry.h"
 #include "nsSerializationHelper.h"
@@ -365,57 +366,43 @@ bool DocumentLoadListener::Open(
           nullptr, attrs, aLoadFlags, aCacheKey, *aRv,
           getter_AddRefs(mChannel))) {
     mParentChannelListener = nullptr;
     return false;
   }
 
   nsCOMPtr<nsIURI> uriBeingLoaded =
       AntiTrackingUtils::MaybeGetDocumentURIBeingLoaded(mChannel);
-  RefPtr<WindowGlobalParent> topWindow =
-      GetTopWindowExcludingExtensionAccessibleContentFrames(browsingContext,
-                                                            uriBeingLoaded);
 
   RefPtr<HttpBaseChannel> httpBaseChannel = do_QueryObject(mChannel, aRv);
   if (httpBaseChannel) {
     nsCOMPtr<nsIURI> topWindowURI;
-    nsCOMPtr<nsIPrincipal> contentBlockingAllowListPrincipal;
     if (browsingContext->IsTop()) {
       // If this is for the top level loading, the top window URI should be the
       // URI which we are loading.
       topWindowURI = uriBeingLoaded;
 
-      // We need to recompute the ContentBlockingAllowListPrincipal here for the
-      // top level channel because we might navigate from the the initial
-      // about:blank page or the existing page which may have a different origin
-      // than the URI we are going to load here. Thus, we need to recompute the
-      // prinicpal in order to get the correct
-      // ContentBlockingAllowListPrincipal.
-      OriginAttributes attrs;
-      aLoadInfo->GetOriginAttributes(&attrs);
-      ContentBlockingAllowList::RecomputePrincipal(
-          uriBeingLoaded, attrs,
-          getter_AddRefs(contentBlockingAllowListPrincipal));
-    } else if (topWindow) {
+      // Update the IsOnContentBlockingAllowList flag in the CookieJarSettings
+      // if this is a top level loading. For sub-document loading, this flag
+      // would inherit from the parent.
+      nsCOMPtr<nsICookieJarSettings> cookieJarSettings;
+      Unused << loadInfo->GetCookieJarSettings(
+          getter_AddRefs(cookieJarSettings));
+      net::CookieJarSettings::Cast(cookieJarSettings)
+          ->UpdateIsOnContentBlockingAllowList(mChannel);
+    } else if (RefPtr<WindowGlobalParent> topWindow =
+                   GetTopWindowExcludingExtensionAccessibleContentFrames(
+                       browsingContext, uriBeingLoaded)) {
       nsCOMPtr<nsIPrincipal> topWindowPrincipal =
           topWindow->DocumentPrincipal();
       if (topWindowPrincipal && !topWindowPrincipal->GetIsNullPrincipal()) {
         topWindowPrincipal->GetURI(getter_AddRefs(topWindowURI));
       }
-
-      contentBlockingAllowListPrincipal =
-          topWindow->GetContentBlockingAllowListPrincipal();
     }
     httpBaseChannel->SetTopWindowURI(topWindowURI);
-
-    if (contentBlockingAllowListPrincipal &&
-        contentBlockingAllowListPrincipal->GetIsContentPrincipal()) {
-      httpBaseChannel->SetContentBlockingAllowListPrincipal(
-          contentBlockingAllowListPrincipal);
-    }
   }
 
   nsCOMPtr<nsIIdentChannel> identChannel = do_QueryInterface(mChannel);
   if (identChannel) {
     Unused << identChannel->SetChannelId(aChannelId);
   }
 
   RefPtr<nsHttpChannel> httpChannelImpl = do_QueryObject(mChannel);