From 4793e51a6e23062c5f58fcee25596387aba92c43 Mon Sep 17 00:00:00 2001 From: Tim Huang Date: Fri, 15 Oct 2021 20:00:06 +0000 Subject: [PATCH] Bug 1731982 - Part 10: Use AntiTrackingUtils::IsThirdPartyContext() to check third party in AntiTrackingUtils::IsThirdPartyWindow() if the channel is not available. r=pbz We used to use the ThirdPartyUtil::IsThirdPartyWindow() to check third party if the document or the channel is not available. However, this could be incorrect in the case where the channel is not available because the WindowContext is not ready yet. To address this issue, we use the browingContext of the document to check third party. Differential Revision: https://phabricator.services.mozilla.com/D128601 --- .../components/antitracking/AntiTrackingUtils.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/toolkit/components/antitracking/AntiTrackingUtils.cpp b/toolkit/components/antitracking/AntiTrackingUtils.cpp index 3fbed37e10cf..a0741c048e44 100644 --- a/toolkit/components/antitracking/AntiTrackingUtils.cpp +++ b/toolkit/components/antitracking/AntiTrackingUtils.cpp @@ -651,9 +651,9 @@ bool AntiTrackingUtils::IsThirdPartyWindow(nsPIDOMWindowInner* aWindow, } RefPtr doc = aWindow->GetDoc(); - if (!doc || !doc->GetChannel()) { - // If we can't get channel from the window, ex, about:blank, fallback to use - // IsThirdPartyWindow check that examine the whole hierarchy. + if (!doc) { + // If we can't get the document from the window, ex, about:blank, fallback + // to use IsThirdPartyWindow check that examine the whole hierarchy. nsCOMPtr thirdPartyUtil = components::ThirdPartyUtil::Service(); Unused << thirdPartyUtil->IsThirdPartyWindow(aWindow->GetOuterWindow(), @@ -661,6 +661,13 @@ bool AntiTrackingUtils::IsThirdPartyWindow(nsPIDOMWindowInner* aWindow, return thirdParty; } + if (!doc->GetChannel()) { + // If we can't get the channel from the document, i.e. initial about:blank + // page, we use the browsingContext of the document to check if it's in the + // third-party context. + return IsThirdPartyContext(doc->GetBrowsingContext()); + } + // We only care whether the channel is 3rd-party with respect to // the top-level. nsCOMPtr loadInfo = doc->GetChannel()->LoadInfo();