From feecd3ed43c4837525ee4b7fef70f81b01874a17 Mon Sep 17 00:00:00 2001 From: Nika Layzell Date: Fri, 15 Feb 2019 19:49:04 +0000 Subject: [PATCH] Bug 1522637 - Part 2: Include BrowsingContextID in LoadInfo for subdocument loads, r=valentin Depends on D18602 Differential Revision: https://phabricator.services.mozilla.com/D18603 --HG-- extra : moz-landing-system : lando --- .../components/sessionstore/SessionStore.jsm | 14 ++++++++----- ipc/glue/BackgroundUtils.cpp | 4 +++- netwerk/base/LoadInfo.cpp | 20 ++++++++++++++++++- netwerk/base/LoadInfo.h | 3 ++- netwerk/base/nsILoadInfo.idl | 7 +++++++ netwerk/ipc/NeckoChannelParams.ipdlh | 1 + 6 files changed, 41 insertions(+), 8 deletions(-) diff --git a/browser/components/sessionstore/SessionStore.jsm b/browser/components/sessionstore/SessionStore.jsm index a3d092977e0a..5b3580ad8bf0 100644 --- a/browser/components/sessionstore/SessionStore.jsm +++ b/browser/components/sessionstore/SessionStore.jsm @@ -2323,13 +2323,17 @@ var SessionStoreInternal = { return; // Not a document load. } - let browsingContext = aChannel.loadInfo.browsingContext; - if (!browsingContext) { - return; // Not loading in a browsing context. + let cpType = aChannel.loadInfo.externalContentPolicyType; + let toplevel = cpType == Ci.nsIContentPolicy.TYPE_DOCUMENT; + if (!toplevel) { + return; // Not loading a toplevel document. } - if (browsingContext.parent) { - return; // Not a toplevel load, can't flip procs. + let browsingContext = toplevel + ? aChannel.loadInfo.browsingContext + : aChannel.loadInfo.frameBrowsingContext; + if (!browsingContext) { + return; // Not loading in a browsing context. } // Get principal for a document already loaded in the BrowsingContext. diff --git a/ipc/glue/BackgroundUtils.cpp b/ipc/glue/BackgroundUtils.cpp index 9c7ed8a07ae9..85250564d2c2 100644 --- a/ipc/glue/BackgroundUtils.cpp +++ b/ipc/glue/BackgroundUtils.cpp @@ -477,6 +477,7 @@ nsresult LoadInfoToLoadInfoArgs(nsILoadInfo* aLoadInfo, aLoadInfo->GetInnerWindowID(), aLoadInfo->GetOuterWindowID(), aLoadInfo->GetParentOuterWindowID(), aLoadInfo->GetTopOuterWindowID(), aLoadInfo->GetFrameOuterWindowID(), aLoadInfo->GetBrowsingContextID(), + aLoadInfo->GetFrameBrowsingContextID(), aLoadInfo->GetInitialSecurityCheckDone(), aLoadInfo->GetIsInThirdPartyContext(), aLoadInfo->GetIsDocshellReload(), aLoadInfo->GetSendCSPViolationEvents(), aLoadInfo->GetOriginAttributes(), @@ -634,7 +635,8 @@ nsresult LoadInfoArgsToLoadInfo( loadInfoArgs.forceInheritPrincipalDropped(), loadInfoArgs.innerWindowID(), loadInfoArgs.outerWindowID(), loadInfoArgs.parentOuterWindowID(), loadInfoArgs.topOuterWindowID(), loadInfoArgs.frameOuterWindowID(), - loadInfoArgs.browsingContextID(), loadInfoArgs.initialSecurityCheckDone(), + loadInfoArgs.browsingContextID(), loadInfoArgs.frameBrowsingContextID(), + loadInfoArgs.initialSecurityCheckDone(), loadInfoArgs.isInThirdPartyContext(), loadInfoArgs.isDocshellReload(), loadInfoArgs.sendCSPViolationEvents(), loadInfoArgs.originAttributes(), redirectChainIncludingInternalRedirects, redirectChain, diff --git a/netwerk/base/LoadInfo.cpp b/netwerk/base/LoadInfo.cpp index a35b8ce525b7..0e381e396378 100644 --- a/netwerk/base/LoadInfo.cpp +++ b/netwerk/base/LoadInfo.cpp @@ -80,6 +80,7 @@ LoadInfo::LoadInfo( mTopOuterWindowID(0), mFrameOuterWindowID(0), mBrowsingContextID(0), + mFrameBrowsingContextID(0), mInitialSecurityCheckDone(false), mIsThirdPartyContext(false), mIsDocshellReload(false), @@ -230,6 +231,9 @@ LoadInfo::LoadInfo( nsCOMPtr outerWindow = do_GetInterface(docShell); if (outerWindow) { mFrameOuterWindowID = outerWindow->WindowID(); + + RefPtr bc = outerWindow->GetBrowsingContext(); + mFrameBrowsingContextID = bc ? bc->Id() : 0; } } } @@ -362,6 +366,7 @@ LoadInfo::LoadInfo(nsPIDOMWindowOuter* aOuterWindow, mTopOuterWindowID(0), mFrameOuterWindowID(0), mBrowsingContextID(0), + mFrameBrowsingContextID(0), mInitialSecurityCheckDone(false), mIsThirdPartyContext(false), // NB: TYPE_DOCUMENT implies !third-party. mIsDocshellReload(false), @@ -500,7 +505,7 @@ LoadInfo::LoadInfo( bool aForceInheritPrincipalDropped, uint64_t aInnerWindowID, uint64_t aOuterWindowID, uint64_t aParentOuterWindowID, uint64_t aTopOuterWindowID, uint64_t aFrameOuterWindowID, - uint64_t aBrowsingContextID, + uint64_t aBrowsingContextID, uint64_t aFrameBrowsingContextID, bool aInitialSecurityCheckDone, bool aIsThirdPartyContext, bool aIsDocshellReload, bool aSendCSPViolationEvents, const OriginAttributes& aOriginAttributes, @@ -543,6 +548,7 @@ LoadInfo::LoadInfo( mTopOuterWindowID(aTopOuterWindowID), mFrameOuterWindowID(aFrameOuterWindowID), mBrowsingContextID(aBrowsingContextID), + mFrameBrowsingContextID(aFrameBrowsingContextID), mInitialSecurityCheckDone(aInitialSecurityCheckDone), mIsThirdPartyContext(aIsThirdPartyContext), mIsDocshellReload(aIsDocshellReload), @@ -993,12 +999,24 @@ LoadInfo::GetBrowsingContextID(uint64_t* aResult) { return NS_OK; } +NS_IMETHODIMP +LoadInfo::GetFrameBrowsingContextID(uint64_t* aResult) { + *aResult = mFrameBrowsingContextID; + return NS_OK; +} + NS_IMETHODIMP LoadInfo::GetBrowsingContext(dom::BrowsingContext** aResult) { *aResult = BrowsingContext::Get(mBrowsingContextID).take(); return NS_OK; } +NS_IMETHODIMP +LoadInfo::GetFrameBrowsingContext(dom::BrowsingContext** aResult) { + *aResult = BrowsingContext::Get(mFrameBrowsingContextID).take(); + return NS_OK; +} + NS_IMETHODIMP LoadInfo::GetScriptableOriginAttributes( JSContext* aCx, JS::MutableHandle aOriginAttributes) { diff --git a/netwerk/base/LoadInfo.h b/netwerk/base/LoadInfo.h index 851602553ebe..15c016d5f850 100644 --- a/netwerk/base/LoadInfo.h +++ b/netwerk/base/LoadInfo.h @@ -111,7 +111,7 @@ class LoadInfo final : public nsILoadInfo { bool aForceInheritPrincipalDropped, uint64_t aInnerWindowID, uint64_t aOuterWindowID, uint64_t aParentOuterWindowID, uint64_t aTopOuterWindowID, uint64_t aFrameOuterWindowID, - uint64_t aBrowsingContextID, + uint64_t aBrowsingContextID, uint64_t aFrameBrowsingContextID, bool aInitialSecurityCheckDone, bool aIsThirdPartyRequest, bool aIsDocshellReload, bool aSendCSPViolationEvents, const OriginAttributes& aOriginAttributes, @@ -184,6 +184,7 @@ class LoadInfo final : public nsILoadInfo { uint64_t mTopOuterWindowID; uint64_t mFrameOuterWindowID; uint64_t mBrowsingContextID; + uint64_t mFrameBrowsingContextID; bool mInitialSecurityCheckDone; bool mIsThirdPartyContext; bool mIsDocshellReload; diff --git a/netwerk/base/nsILoadInfo.idl b/netwerk/base/nsILoadInfo.idl index 6a8ba66c1a47..9c98c654fd60 100644 --- a/netwerk/base/nsILoadInfo.idl +++ b/netwerk/base/nsILoadInfo.idl @@ -634,6 +634,13 @@ interface nsILoadInfo : nsISupports [infallible] readonly attribute unsigned long long browsingContextID; readonly attribute BrowsingContext browsingContext; + /** + * Like `frameOuterWindowID`, however returning the BrowsingContextID + * instead. + */ + [infallible] readonly attribute unsigned long long frameBrowsingContextID; + readonly attribute BrowsingContext frameBrowsingContext; + /** * Resets the PrincipalToInherit to a freshly created NullPrincipal * which inherits the origin attributes from the loadInfo. diff --git a/netwerk/ipc/NeckoChannelParams.ipdlh b/netwerk/ipc/NeckoChannelParams.ipdlh index 267f9ea22aaa..08a92c60b5e7 100644 --- a/netwerk/ipc/NeckoChannelParams.ipdlh +++ b/netwerk/ipc/NeckoChannelParams.ipdlh @@ -64,6 +64,7 @@ struct LoadInfoArgs uint64_t topOuterWindowID; uint64_t frameOuterWindowID; uint64_t browsingContextID; + uint64_t frameBrowsingContextID; bool initialSecurityCheckDone; bool isInThirdPartyContext; bool isDocshellReload;