Bug 1652244 - P2. Use TYPE_DOCUMENT to ensure IsThirdPartyContextToTopWindow is false when loading a top-level r=timhuang
authorDimi Lee <dlee@mozilla.com>
Wed, 12 Aug 2020 09:10:51 +0000
changeset 544391 fadf02e459b620639086f946fad5d0ac46568e4d
parent 544390 47b142630cf9f822aca7290d5a7e01618f382252
child 544392 0fa31c531db234a08df41ffe3c1236ff2007f2f7
push id124004
push userdlee@mozilla.com
push dateWed, 12 Aug 2020 09:17:09 +0000
treeherderautoland@1e2a698cb187 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstimhuang
bugs1652244
milestone81.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 1652244 - P2. Use TYPE_DOCUMENT to ensure IsThirdPartyContextToTopWindow is false when loading a top-level r=timhuang Differential Revision: https://phabricator.services.mozilla.com/D86715
toolkit/components/antitracking/AntiTrackingUtils.cpp
--- a/toolkit/components/antitracking/AntiTrackingUtils.cpp
+++ b/toolkit/components/antitracking/AntiTrackingUtils.cpp
@@ -545,16 +545,27 @@ AntiTrackingUtils::GetTopWindowExcluding
 }
 
 /* static */
 void AntiTrackingUtils::ComputeIsThirdPartyToTopWindow(nsIChannel* aChannel) {
   MOZ_ASSERT(aChannel);
   MOZ_ASSERT(XRE_IsParentProcess());
 
   nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
+
+  // When a top-level load is opened by window.open, BrowsingContext from
+  // LoadInfo is its opener, which may make the third-party caculation code
+  // below returns an incorrect result. So we use TYPE_DOCUMENT to
+  // ensure a top-level load is not considered 3rd-party.
+  auto policyType = loadInfo->GetExternalContentPolicyType();
+  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.
   if (!bc) {
     return;
   }