From d67ea3aa051b7aec279074f9b9d438a0616c01dc Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Wed, 28 Aug 2019 11:13:49 +0000 Subject: [PATCH] Bug 1576316 - Restore a bit of the Fission-incompatible code removed in bug 1575609 in order to satisfy the tests that are relying on it; r=baku The function called in these tests of course does the wrong thing, but these tests aren't testing anything related to anti-tracking, so it is probably harmless to leave this code in until the dependencies described in the comments in the patch are in place. Differential Revision: https://phabricator.services.mozilla.com/D43465 --HG-- extra : moz-landing-system : lando --- .../antitracking/AntiTrackingCommon.cpp | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/toolkit/components/antitracking/AntiTrackingCommon.cpp b/toolkit/components/antitracking/AntiTrackingCommon.cpp index 6768184d1ba3..1f97ceef6182 100644 --- a/toolkit/components/antitracking/AntiTrackingCommon.cpp +++ b/toolkit/components/antitracking/AntiTrackingCommon.cpp @@ -1313,8 +1313,34 @@ bool AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( return false; } - nsGlobalWindowOuter* topWindow = nsGlobalWindowOuter::Cast( - aWindow->GetBrowsingContext()->Top()->GetDOMWindow()); + BrowsingContext* topBC = aWindow->GetBrowsingContext()->Top(); + nsGlobalWindowOuter* topWindow = nullptr; + if (topBC->IsInProcess()) { + topWindow = nsGlobalWindowOuter::Cast(topBC->GetDOMWindow()); + } else { + // For out-of-process top frames, we need to be able to access three things + // from the top BrowsingContext in order to be able to port this code to + // Fission successfully: + // * The principal of the top BrowsingContext. + // * The CookieSettings of the top BrowsingContext. + // * The HasStorageAccessGranted() API on BrowsingContext. + // For now, if we face an out-of-process top frame, instead of failing here, + // we revert back to looking at the in-process top frame. This is of course + // the wrong thing to do, but we seem to have a number of tests in the tree + // which are depending on this incorrect behaviour. This path is intended + // to temporarily keep those tests working... + nsGlobalWindowOuter* outerWindow = + nsGlobalWindowOuter::Cast(aWindow->GetOuterWindow()); + if (!outerWindow) { + LOG(("Our window has no outer window")); + return false; + } + + nsCOMPtr topOuterWindow = + outerWindow->GetInProcessTop(); + topWindow = nsGlobalWindowOuter::Cast(topOuterWindow); + } + if (NS_WARN_IF(!topWindow)) { LOG(("No top outer window")); return false;