Bug 1623268 - P3. ContentBlockingAllowList::Check API supports passing BrowsingContext r=timhuang,baku
authorDimi Lee <dlee@mozilla.com>
Thu, 26 Mar 2020 15:12:57 +0000
changeset 520589 f89b7ec7b51b8c02cb8a18a002641af5883da42c
parent 520588 5072342655d845d309ad4b3f0238e2f6a92cfe26
child 520590 a217ec8bc94ed25180c73fd7799a3f543f5e6c98
push id37253
push usernerli@mozilla.com
push dateThu, 26 Mar 2020 21:36:52 +0000
treeherdermozilla-central@c644dd16e2cc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstimhuang, baku
bugs1623268
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 1623268 - P3. ContentBlockingAllowList::Check API supports passing BrowsingContext r=timhuang,baku Differential Revision: https://phabricator.services.mozilla.com/D67283
toolkit/components/antitracking/ContentBlocking.cpp
toolkit/components/antitracking/ContentBlockingAllowList.cpp
toolkit/components/antitracking/ContentBlockingAllowList.h
--- a/toolkit/components/antitracking/ContentBlocking.cpp
+++ b/toolkit/components/antitracking/ContentBlocking.cpp
@@ -335,17 +335,23 @@ ContentBlocking::AllowAccessFor(
   if (!parentInner) {
     LOG(
         ("No inner window found for our parent outer window, bailing out "
          "early"));
     return StorageAccessGrantPromise::CreateAndReject(false, __func__);
   }
 
   // No need to continue when we are already in the allow list.
-  if (ContentBlockingAllowList::Check(parentInner)) {
+  bool isInAllowList = false;
+  if (NS_FAILED(
+          ContentBlockingAllowList::Check(aParentContext, isInAllowList))) {
+    return StorageAccessGrantPromise::CreateAndReject(false, __func__);
+  }
+
+  if (isInAllowList) {
     return StorageAccessGrantPromise::CreateAndResolve(true, __func__);
   }
 
   bool isParentTopLevel = aParentContext->IsTopContent();
 
   // Make sure storage access isn't disabled
   if (!isParentTopLevel &&
       Document::StorageAccessSandboxed(aParentContext->GetSandboxFlags())) {
--- a/toolkit/components/antitracking/ContentBlockingAllowList.cpp
+++ b/toolkit/components/antitracking/ContentBlockingAllowList.cpp
@@ -40,16 +40,38 @@ using namespace mozilla;
         ("Could not check the content blocking allow list because the cookie "
          "jar settings wasn't available"));
     return false;
   }
 
   return aCookieJarSettings->GetIsOnContentBlockingAllowList();
 }
 
+// TODO: We'll update the implementation here to use CookiejarSetting in
+//       WindowContext (See 1612378).
+/* static */ nsresult ContentBlockingAllowList::Check(
+    BrowsingContext* aParentContext, bool& aIsAllowListed) {
+  MOZ_ASSERT(aParentContext);
+
+  nsCOMPtr<nsPIDOMWindowOuter> outer = aParentContext->GetDOMWindow();
+  if (!outer) {
+    LOG(("No outer window found for our parent window context"));
+    return NS_ERROR_FAILURE;
+  }
+
+  nsCOMPtr<nsPIDOMWindowInner> inner = outer->GetCurrentInnerWindow();
+  if (!inner) {
+    LOG(("No inner window found for our parent outer window"));
+    return NS_ERROR_FAILURE;
+  }
+
+  aIsAllowListed = ContentBlockingAllowList::Check(inner);
+  return NS_OK;
+}
+
 /* static */ bool ContentBlockingAllowList::Check(nsPIDOMWindowInner* aWindow) {
   // We can check the IsOnContentBlockingAllowList flag in the document's
   // CookieJarSettings. Because this flag represents the fact that whether the
   // top-level document is on the content blocking allow list. And this flag was
   // propagated from the top-level as the CookieJarSettings inherits from the
   // parent.
   RefPtr<dom::Document> doc = nsGlobalWindowInner::Cast(aWindow)->GetDocument();
 
--- a/toolkit/components/antitracking/ContentBlockingAllowList.h
+++ b/toolkit/components/antitracking/ContentBlockingAllowList.h
@@ -2,16 +2,18 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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/. */
 
 #ifndef mozilla_contentblockingallowlist_h
 #define mozilla_contentblockingallowlist_h
 
+#include "mozilla/dom/BrowsingContext.h"
+
 class nsICookieJarSettings;
 class nsIHttpChannel;
 class nsIPrincipal;
 class nsIURI;
 class nsPIDOMWindowInner;
 
 namespace mozilla {
 
@@ -39,15 +41,16 @@ class ContentBlockingAllowList final {
                                  const OriginAttributes& aAttrs,
                                  nsIPrincipal** aPrincipal);
 
  private:
   // Utility APIs for ContentBlocking.
   static bool Check(nsIPrincipal* aTopWinPrincipal, bool aIsPrivateBrowsing);
   static bool Check(nsPIDOMWindowInner* aWindow);
   static bool Check(nsICookieJarSettings* aCookieJarSettings);
+  static nsresult Check(mozilla::dom::BrowsingContext* aBrowsingContext, bool& aIsAllowListed);
 
   friend class ContentBlocking;
 };
 
 }  // namespace mozilla
 
 #endif  // mozilla_contentblockingallowlist_h