Bug 1522637 - Part 2: Include BrowsingContextID in LoadInfo for subdocument loads, r=valentin
authorNika Layzell <nika@thelayzells.com>
Fri, 15 Feb 2019 19:49:04 +0000
changeset 459589 7eca000f53a6c6dc3143636cd49e57f8c293b509
parent 459588 663ed0c62558d2d71d79c46203ffc3c4146c3da1
child 459590 f3f386e5ae0726571360f6e63fdae057ff155164
push id35563
push userccoroiu@mozilla.com
push dateSat, 16 Feb 2019 09:36:04 +0000
treeherdermozilla-central@1cfd69d05aa1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1522637
milestone67.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 1522637 - Part 2: Include BrowsingContextID in LoadInfo for subdocument loads, r=valentin Depends on D18602 Differential Revision: https://phabricator.services.mozilla.com/D18603
browser/components/sessionstore/SessionStore.jsm
ipc/glue/BackgroundUtils.cpp
netwerk/base/LoadInfo.cpp
netwerk/base/LoadInfo.h
netwerk/base/nsILoadInfo.idl
netwerk/ipc/NeckoChannelParams.ipdlh
--- a/browser/components/sessionstore/SessionStore.jsm
+++ b/browser/components/sessionstore/SessionStore.jsm
@@ -2318,25 +2318,29 @@ var SessionStoreInternal = {
     if (!E10SUtils.useHttpResponseProcessSelection()) {
       return;
     }
 
     if (!aChannel.isDocument || !aChannel.loadInfo) {
       return; // Not a document load.
     }
 
-    let browsingContext = aChannel.loadInfo.browsingContext;
+    let cpType = aChannel.loadInfo.externalContentPolicyType;
+    let toplevel = cpType == Ci.nsIContentPolicy.TYPE_DOCUMENT;
+    if (!toplevel) {
+      return; // Not loading a toplevel document.
+    }
+
+    let browsingContext = toplevel
+        ? aChannel.loadInfo.browsingContext
+        : aChannel.loadInfo.frameBrowsingContext;
     if (!browsingContext) {
       return; // Not loading in a browsing context.
     }
 
-    if (browsingContext.parent) {
-      return; // Not a toplevel load, can't flip procs.
-    }
-
     // Get principal for a document already loaded in the BrowsingContext.
     let currentPrincipal = null;
     if (browsingContext.currentWindowGlobal) {
       currentPrincipal = browsingContext.currentWindowGlobal.documentPrincipal;
     }
 
     let parentChannel = aChannel.notificationCallbacks
                                 .getInterface(Ci.nsIParentChannel);
--- a/ipc/glue/BackgroundUtils.cpp
+++ b/ipc/glue/BackgroundUtils.cpp
@@ -472,16 +472,17 @@ nsresult LoadInfoToLoadInfoArgs(nsILoadI
       aLoadInfo->GetVerifySignedContent(), aLoadInfo->GetEnforceSRI(),
       aLoadInfo->GetForceAllowDataURI(),
       aLoadInfo->GetAllowInsecureRedirectToDataURI(),
       aLoadInfo->GetSkipContentPolicyCheckForWebRequest(),
       aLoadInfo->GetForceInheritPrincipalDropped(),
       aLoadInfo->GetInnerWindowID(), aLoadInfo->GetOuterWindowID(),
       aLoadInfo->GetParentOuterWindowID(), aLoadInfo->GetTopOuterWindowID(),
       aLoadInfo->GetFrameOuterWindowID(), aLoadInfo->GetBrowsingContextID(),
+      aLoadInfo->GetFrameBrowsingContextID(),
       aLoadInfo->GetInitialSecurityCheckDone(),
       aLoadInfo->GetIsInThirdPartyContext(), aLoadInfo->GetIsDocshellReload(),
       aLoadInfo->GetSendCSPViolationEvents(), aLoadInfo->GetOriginAttributes(),
       redirectChainIncludingInternalRedirects, redirectChain,
       ancestorPrincipals, aLoadInfo->AncestorOuterWindowIDs(), ipcClientInfo,
       ipcReservedClientInfo, ipcInitialClientInfo, ipcController,
       aLoadInfo->CorsUnsafeHeaders(), aLoadInfo->GetForcePreflight(),
       aLoadInfo->GetIsPreflight(), aLoadInfo->GetLoadTriggeredFromExternal(),
@@ -629,17 +630,18 @@ nsresult LoadInfoArgsToLoadInfo(
       loadInfoArgs.browserWouldUpgradeInsecureRequests(),
       loadInfoArgs.verifySignedContent(), loadInfoArgs.enforceSRI(),
       loadInfoArgs.forceAllowDataURI(),
       loadInfoArgs.allowInsecureRedirectToDataURI(),
       loadInfoArgs.skipContentPolicyCheckForWebRequest(),
       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,
       std::move(ancestorPrincipals), loadInfoArgs.ancestorOuterWindowIDs(),
       loadInfoArgs.corsUnsafeHeaders(), loadInfoArgs.forcePreflight(),
       loadInfoArgs.isPreflight(), loadInfoArgs.loadTriggeredFromExternal(),
       loadInfoArgs.serviceWorkerTaintingSynthesized(),
       loadInfoArgs.documentHasUserInteracted(),
--- a/netwerk/base/LoadInfo.cpp
+++ b/netwerk/base/LoadInfo.cpp
@@ -75,16 +75,17 @@ LoadInfo::LoadInfo(
       mOriginalFrameSrcLoad(false),
       mForceInheritPrincipalDropped(false),
       mInnerWindowID(0),
       mOuterWindowID(0),
       mParentOuterWindowID(0),
       mTopOuterWindowID(0),
       mFrameOuterWindowID(0),
       mBrowsingContextID(0),
+      mFrameBrowsingContextID(0),
       mInitialSecurityCheckDone(false),
       mIsThirdPartyContext(false),
       mIsDocshellReload(false),
       mSendCSPViolationEvents(true),
       mForcePreflight(false),
       mIsPreflight(false),
       mLoadTriggeredFromExternal(false),
       mServiceWorkerTaintingSynthesized(false),
@@ -225,16 +226,19 @@ LoadInfo::LoadInfo(
     RefPtr<nsFrameLoader> fl =
         frameLoaderOwner ? frameLoaderOwner->GetFrameLoader() : nullptr;
     if (fl) {
       nsCOMPtr<nsIDocShell> docShell = fl->GetDocShell(IgnoreErrors());
       if (docShell) {
         nsCOMPtr<nsPIDOMWindowOuter> outerWindow = do_GetInterface(docShell);
         if (outerWindow) {
           mFrameOuterWindowID = outerWindow->WindowID();
+
+          RefPtr<dom::BrowsingContext> bc = outerWindow->GetBrowsingContext();
+          mFrameBrowsingContextID = bc ? bc->Id() : 0;
         }
       }
     }
 
     // if the document forces all requests to be upgraded from http to https,
     // then we should do that for all requests. If it only forces preloads to be
     // upgraded then we should enforce upgrade insecure requests only for
     // preloads.
@@ -357,16 +361,17 @@ LoadInfo::LoadInfo(nsPIDOMWindowOuter* a
       mOriginalFrameSrcLoad(false),
       mForceInheritPrincipalDropped(false),
       mInnerWindowID(0),
       mOuterWindowID(0),
       mParentOuterWindowID(0),
       mTopOuterWindowID(0),
       mFrameOuterWindowID(0),
       mBrowsingContextID(0),
+      mFrameBrowsingContextID(0),
       mInitialSecurityCheckDone(false),
       mIsThirdPartyContext(false),  // NB: TYPE_DOCUMENT implies !third-party.
       mIsDocshellReload(false),
       mSendCSPViolationEvents(true),
       mForcePreflight(false),
       mIsPreflight(false),
       mLoadTriggeredFromExternal(false),
       mServiceWorkerTaintingSynthesized(false),
@@ -495,17 +500,17 @@ LoadInfo::LoadInfo(
     bool aBrowserUpgradeInsecureRequests,
     bool aBrowserWouldUpgradeInsecureRequests, bool aVerifySignedContent,
     bool aEnforceSRI, bool aForceAllowDataURI,
     bool aAllowInsecureRedirectToDataURI,
     bool aSkipContentPolicyCheckForWebRequest,
     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,
     RedirectHistoryArray& aRedirectChainIncludingInternalRedirects,
     RedirectHistoryArray& aRedirectChain,
     nsTArray<nsCOMPtr<nsIPrincipal>>&& aAncestorPrincipals,
     const nsTArray<uint64_t>& aAncestorOuterWindowIDs,
     const nsTArray<nsCString>& aCorsUnsafeHeaders, bool aForcePreflight,
@@ -538,16 +543,17 @@ LoadInfo::LoadInfo(
       mOriginalFrameSrcLoad(false),
       mForceInheritPrincipalDropped(aForceInheritPrincipalDropped),
       mInnerWindowID(aInnerWindowID),
       mOuterWindowID(aOuterWindowID),
       mParentOuterWindowID(aParentOuterWindowID),
       mTopOuterWindowID(aTopOuterWindowID),
       mFrameOuterWindowID(aFrameOuterWindowID),
       mBrowsingContextID(aBrowsingContextID),
+      mFrameBrowsingContextID(aFrameBrowsingContextID),
       mInitialSecurityCheckDone(aInitialSecurityCheckDone),
       mIsThirdPartyContext(aIsThirdPartyContext),
       mIsDocshellReload(aIsDocshellReload),
       mSendCSPViolationEvents(aSendCSPViolationEvents),
       mOriginAttributes(aOriginAttributes),
       mAncestorPrincipals(std::move(aAncestorPrincipals)),
       mAncestorOuterWindowIDs(aAncestorOuterWindowIDs),
       mCorsUnsafeHeaders(aCorsUnsafeHeaders),
@@ -989,22 +995,34 @@ LoadInfo::GetFrameOuterWindowID(uint64_t
 
 NS_IMETHODIMP
 LoadInfo::GetBrowsingContextID(uint64_t* aResult) {
   *aResult = mBrowsingContextID;
   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<JS::Value> aOriginAttributes) {
   if (NS_WARN_IF(!ToJSValue(aCx, mOriginAttributes, aOriginAttributes))) {
     return NS_ERROR_FAILURE;
   }
   return NS_OK;
 }
 
--- a/netwerk/base/LoadInfo.h
+++ b/netwerk/base/LoadInfo.h
@@ -106,17 +106,17 @@ class LoadInfo final : public nsILoadInf
            bool aUpgradeInsecureRequests, bool aBrowserUpgradeInsecureRequests,
            bool aBrowserWouldUpgradeInsecureRequests, bool aVerifySignedContent,
            bool aEnforceSRI, bool aForceAllowDataURI,
            bool aAllowInsecureRedirectToDataURI,
            bool aSkipContentPolicyCheckForWebRequest,
            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,
            RedirectHistoryArray& aRedirectChainIncludingInternalRedirects,
            RedirectHistoryArray& aRedirectChain,
            nsTArray<nsCOMPtr<nsIPrincipal>>&& aAncestorPrincipals,
            const nsTArray<uint64_t>& aAncestorOuterWindowIDs,
            const nsTArray<nsCString>& aUnsafeHeaders, bool aForcePreflight,
@@ -179,16 +179,17 @@ class LoadInfo final : public nsILoadInf
   bool mOriginalFrameSrcLoad;
   bool mForceInheritPrincipalDropped;
   uint64_t mInnerWindowID;
   uint64_t mOuterWindowID;
   uint64_t mParentOuterWindowID;
   uint64_t mTopOuterWindowID;
   uint64_t mFrameOuterWindowID;
   uint64_t mBrowsingContextID;
+  uint64_t mFrameBrowsingContextID;
   bool mInitialSecurityCheckDone;
   bool mIsThirdPartyContext;
   bool mIsDocshellReload;
   bool mSendCSPViolationEvents;
   OriginAttributes mOriginAttributes;
   RedirectHistoryArray mRedirectChainIncludingInternalRedirects;
   RedirectHistoryArray mRedirectChain;
   nsTArray<nsCOMPtr<nsIPrincipal>> mAncestorPrincipals;
--- a/netwerk/base/nsILoadInfo.idl
+++ b/netwerk/base/nsILoadInfo.idl
@@ -630,16 +630,23 @@ interface nsILoadInfo : nsISupports
 
   /**
    * The BrowsingContext performing the load for this nsILoadInfo object.
    */
   [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.
    *
    * WARNING: Please only use that function if you know exactly what
    * you are doing!!!
    */
   void resetPrincipalToInheritToNullPrincipal();
 
--- a/netwerk/ipc/NeckoChannelParams.ipdlh
+++ b/netwerk/ipc/NeckoChannelParams.ipdlh
@@ -59,16 +59,17 @@ struct LoadInfoArgs
   bool                        skipContentPolicyCheckForWebRequest;
   bool                        forceInheritPrincipalDropped;
   uint64_t                    innerWindowID;
   uint64_t                    outerWindowID;
   uint64_t                    parentOuterWindowID;
   uint64_t                    topOuterWindowID;
   uint64_t                    frameOuterWindowID;
   uint64_t                    browsingContextID;
+  uint64_t                    frameBrowsingContextID;
   bool                        initialSecurityCheckDone;
   bool                        isInThirdPartyContext;
   bool                        isDocshellReload;
   bool                        sendCSPViolationEvents;
   OriginAttributes            originAttributes;
   RedirectHistoryEntryInfo[]  redirectChainIncludingInternalRedirects;
   RedirectHistoryEntryInfo[]  redirectChain;