Bug 1637634 - Update IsOnContentBlockingAllowList in nsHttpChannel::AsyncOpen r=timhuang,necko-reviewers
authorDimi Lee <dlee@mozilla.com>
Tue, 26 May 2020 06:52:39 +0000
changeset 532124 b4f883d57ca6ec1893c65a5ecbd9e59b70357d81
parent 532123 9298de7e11dd1a8b7cf408d1f3fba6f0edb6c55e
child 532125 a302225c17c8f70c8efd8e01d2da8d1fd9bf8268
push id37450
push usercbrindusan@mozilla.com
push dateTue, 26 May 2020 15:44:42 +0000
treeherdermozilla-central@4da52a3b8dfd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstimhuang, necko-reviewers
bugs1637634
milestone78.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 1637634 - Update IsOnContentBlockingAllowList in nsHttpChannel::AsyncOpen r=timhuang,necko-reviewers This patch removes the assertion that ensures the channel is top-level via BrowsingContext. This is because more than one testcases creates a TYPE_DOCUMENT channel to test. Differential Revision: https://phabricator.services.mozilla.com/D76152
netwerk/cookie/CookieJarSettings.cpp
netwerk/ipc/DocumentLoadListener.cpp
netwerk/protocol/http/nsHttpChannel.cpp
--- a/netwerk/cookie/CookieJarSettings.cpp
+++ b/netwerk/cookie/CookieJarSettings.cpp
@@ -420,35 +420,32 @@ void CookieJarSettings::SetFirstPartyDom
 }
 
 void CookieJarSettings::UpdateIsOnContentBlockingAllowList(
     nsIChannel* aChannel) {
   MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess());
   MOZ_ASSERT(aChannel);
   nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
 
-#ifdef DEBUG
-  RefPtr<dom::BrowsingContext> bc;
-  MOZ_ALWAYS_SUCCEEDS(loadInfo->GetTargetBrowsingContext(getter_AddRefs(bc)));
-  MOZ_ASSERT(bc->IsTop());
-#endif
-
-  nsCOMPtr<nsIURI> uriBeingLoaded =
-      AntiTrackingUtils::MaybeGetDocumentURIBeingLoaded(aChannel);
-  nsCOMPtr<nsIPrincipal> contentBlockingAllowListPrincipal;
+  nsCOMPtr<nsIURI> uri;
+  nsresult rv = aChannel->GetURI(getter_AddRefs(uri));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return;
+  }
 
   // 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.
+  nsCOMPtr<nsIPrincipal> contentBlockingAllowListPrincipal;
   OriginAttributes attrs;
   loadInfo->GetOriginAttributes(&attrs);
   ContentBlockingAllowList::RecomputePrincipal(
-      uriBeingLoaded, attrs, getter_AddRefs(contentBlockingAllowListPrincipal));
+      uri, attrs, getter_AddRefs(contentBlockingAllowListPrincipal));
 
   if (!contentBlockingAllowListPrincipal ||
       !contentBlockingAllowListPrincipal->GetIsContentPrincipal()) {
     return;
   }
 
   Unused << ContentBlockingAllowList::Check(contentBlockingAllowListPrincipal,
                                             NS_UsePrivateBrowsing(aChannel),
--- a/netwerk/ipc/DocumentLoadListener.cpp
+++ b/netwerk/ipc/DocumentLoadListener.cpp
@@ -3,17 +3,16 @@
 
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "DocumentLoadListener.h"
 
 #include "mozilla/AntiTrackingUtils.h"
-#include "mozilla/ContentBlockingAllowList.h"
 #include "mozilla/LoadInfo.h"
 #include "mozilla/MozPromiseInlines.h"  // For MozPromise::FromDomPromise
 #include "mozilla/StaticPrefs_fission.h"
 #include "mozilla/StaticPrefs_security.h"
 #include "mozilla/dom/CanonicalBrowsingContext.h"
 #include "mozilla/dom/ClientChannelHelper.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/ContentProcessManager.h"
@@ -408,25 +407,16 @@ bool DocumentLoadListener::Open(
 
   RefPtr<HttpBaseChannel> httpBaseChannel = do_QueryObject(mChannel, aRv);
   if (httpBaseChannel) {
     nsCOMPtr<nsIURI> topWindowURI;
     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;
-
-      // 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 = AntiTrackingUtils::
                    GetTopWindowExcludingExtensionAccessibleContentFrames(
                        browsingContext, uriBeingLoaded)) {
       nsCOMPtr<nsIPrincipal> topWindowPrincipal =
           topWindow->DocumentPrincipal();
       if (topWindowPrincipal && !topWindowPrincipal->GetIsNullPrincipal()) {
         auto* basePrin = BasePrincipal::Cast(topWindowPrincipal);
         basePrin->GetURI(getter_AddRefs(topWindowURI));
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -1858,24 +1858,30 @@ void nsHttpChannel::SetCachedContentType
 }
 
 void nsHttpChannel::UpdateAntiTrackingInfo() {
   Unused << mLoadInfo->SetHasStoragePermission(
       AntiTrackingUtils::HasStoragePermissionInParent(this));
 
   AntiTrackingUtils::ComputeIsThirdPartyToTopWindow(this);
 
-  // We only need to set FPD for top-level loads. FPD will automatically be
-  // propagated to non-top level loads via CookieJarSetting.
   if (mLoadInfo->GetExternalContentPolicyType() ==
       nsIContentPolicy::TYPE_DOCUMENT) {
     nsCOMPtr<nsICookieJarSettings> cookieJarSettings;
     Unused << mLoadInfo->GetCookieJarSettings(
         getter_AddRefs(cookieJarSettings));
 
+    // 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.
+    mozilla::net::CookieJarSettings::Cast(cookieJarSettings)
+        ->UpdateIsOnContentBlockingAllowList(this);
+
+    // We only need to set FPD for top-level loads. FPD will automatically be
+    // propagated to non-top level loads via CookieJarSetting.
     mozilla::net::CookieJarSettings::Cast(cookieJarSettings)
         ->SetFirstPartyDomain(mURI);
   }
 }
 
 nsresult nsHttpChannel::CallOnStartRequest() {
   LOG(("nsHttpChannel::CallOnStartRequest [this=%p]", this));