Bug 1584207 - Forward nsILoadInfo.requestBlockingReason to the parent process for both old and new redirect channels, r=dragana,asuth
authorHonza Bambas <honzab.moz@firemni.cz>
Tue, 01 Oct 2019 16:50:23 +0000
changeset 496108 effee4ab270cba85ad53b7be844212bc458ec1a6
parent 496107 a49132352f5bfd3994ab179813b6c1be499e7a23
child 496109 18cdbda1b5e1249e1741c7a023ca4d037b33ccf3
push id97015
push userhonzab.moz@firemni.cz
push dateWed, 02 Oct 2019 19:21:06 +0000
treeherderautoland@effee4ab270c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana, asuth
bugs1584207
milestone71.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 1584207 - Forward nsILoadInfo.requestBlockingReason to the parent process for both old and new redirect channels, r=dragana,asuth Differential Revision: https://phabricator.services.mozilla.com/D47264
ipc/glue/BackgroundUtils.cpp
netwerk/ipc/NeckoChannelParams.ipdlh
netwerk/protocol/http/HttpChannelChild.cpp
netwerk/protocol/http/HttpChannelParent.cpp
netwerk/protocol/http/HttpChannelParent.h
netwerk/protocol/http/PHttpChannel.ipdl
--- a/ipc/glue/BackgroundUtils.cpp
+++ b/ipc/glue/BackgroundUtils.cpp
@@ -880,17 +880,17 @@ nsresult MergeParentLoadInfoForwarder(
 
   return NS_OK;
 }
 
 void LoadInfoToChildLoadInfoForwarder(
     nsILoadInfo* aLoadInfo, ChildLoadInfoForwarderArgs* aForwarderArgsOut) {
   if (!aLoadInfo) {
     *aForwarderArgsOut =
-        ChildLoadInfoForwarderArgs(Nothing(), Nothing(), Nothing());
+        ChildLoadInfoForwarderArgs(Nothing(), Nothing(), Nothing(), 0);
     return;
   }
 
   Maybe<IPCClientInfo> ipcReserved;
   Maybe<ClientInfo> reserved(aLoadInfo->GetReservedClientInfo());
   if (reserved.isSome()) {
     ipcReserved.emplace(reserved.ref().ToIPC());
   }
@@ -903,17 +903,18 @@ void LoadInfoToChildLoadInfoForwarder(
 
   Maybe<IPCServiceWorkerDescriptor> ipcController;
   Maybe<ServiceWorkerDescriptor> controller(aLoadInfo->GetController());
   if (controller.isSome()) {
     ipcController.emplace(controller.ref().ToIPC());
   }
 
   *aForwarderArgsOut =
-      ChildLoadInfoForwarderArgs(ipcReserved, ipcInitial, ipcController);
+      ChildLoadInfoForwarderArgs(ipcReserved, ipcInitial, ipcController,
+                                 aLoadInfo->GetRequestBlockingReason());
 }
 
 nsresult MergeChildLoadInfoForwarder(
     const ChildLoadInfoForwarderArgs& aForwarderArgs, nsILoadInfo* aLoadInfo) {
   if (!aLoadInfo) {
     return NS_OK;
   }
 
@@ -955,13 +956,20 @@ nsresult MergeChildLoadInfoForwarder(
   }
 
   aLoadInfo->ClearController();
   auto& controller = aForwarderArgs.controller();
   if (controller.isSome()) {
     aLoadInfo->SetController(ServiceWorkerDescriptor(controller.ref()));
   }
 
+  uint32_t blockingReason = aForwarderArgs.requestBlockingReason();
+  if (blockingReason) {
+    // We only want to override when non-null, so that any earlier set non-null
+    // value is not reverted to 0.
+    aLoadInfo->SetRequestBlockingReason(blockingReason);
+  }
+
   return NS_OK;
 }
 
 }  // namespace ipc
 }  // namespace mozilla
--- a/netwerk/ipc/NeckoChannelParams.ipdlh
+++ b/netwerk/ipc/NeckoChannelParams.ipdlh
@@ -208,16 +208,18 @@ struct ChildLoadInfoForwarderArgs
   // The reserved and initial ClientInfo values may change during a
   // redirect if the new channel is cross-origin to the old channel.
   IPCClientInfo? reservedClientInfo;
   IPCClientInfo? initialClientInfo;
 
   // The ServiceWorker controller may be cleared in the child during
   // a redirect.
   IPCServiceWorkerDescriptor? controller;
+
+  uint32_t requestBlockingReason;
 };
 
 //-----------------------------------------------------------------------------
 // HTTP IPDL structs
 //-----------------------------------------------------------------------------
 
 struct CorsPreflightArgs
 {
--- a/netwerk/protocol/http/HttpChannelChild.cpp
+++ b/netwerk/protocol/http/HttpChannelChild.cpp
@@ -2379,29 +2379,35 @@ HttpChannelChild::OnRedirectVerifyCallba
 
   bool chooseAppcache = false;
   nsCOMPtr<nsIApplicationCacheChannel> appCacheChannel =
       do_QueryInterface(newHttpChannel);
   if (appCacheChannel) {
     appCacheChannel->GetChooseApplicationCache(&chooseAppcache);
   }
 
+  uint32_t sourceRequestBlockingReason = 0;
+  if (mLoadInfo) {
+    mLoadInfo->GetRequestBlockingReason(&sourceRequestBlockingReason);
+  }
+
   nsCOMPtr<nsILoadInfo> newChannelLoadInfo = nullptr;
   nsCOMPtr<nsIChannel> newChannel = do_QueryInterface(mRedirectChannelChild);
   if (newChannel) {
     newChannelLoadInfo = newChannel->LoadInfo();
   }
 
-  ChildLoadInfoForwarderArgs loadInfoForwarder;
-  LoadInfoToChildLoadInfoForwarder(newChannelLoadInfo, &loadInfoForwarder);
+  ChildLoadInfoForwarderArgs targetLoadInfoForwarder;
+  LoadInfoToChildLoadInfoForwarder(newChannelLoadInfo,
+                                   &targetLoadInfoForwarder);
 
   if (CanSend())
-    SendRedirect2Verify(result, *headerTuples, loadInfoForwarder, loadFlags,
-                        referrerInfo, redirectURI, corsPreflightArgs,
-                        chooseAppcache);
+    SendRedirect2Verify(result, *headerTuples, sourceRequestBlockingReason,
+                        targetLoadInfoForwarder, loadFlags, referrerInfo,
+                        redirectURI, corsPreflightArgs, chooseAppcache);
 
   return NS_OK;
 }
 
 //-----------------------------------------------------------------------------
 // HttpChannelChild::nsIRequest
 //-----------------------------------------------------------------------------
 
--- a/netwerk/protocol/http/HttpChannelParent.cpp
+++ b/netwerk/protocol/http/HttpChannelParent.cpp
@@ -854,17 +854,18 @@ mozilla::ipc::IPCResult HttpChannelParen
 mozilla::ipc::IPCResult HttpChannelParent::RecvSetCacheTokenCachedCharset(
     const nsCString& charset) {
   if (mCacheEntry) mCacheEntry->SetMetaDataElement("charset", charset.get());
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult HttpChannelParent::RecvRedirect2Verify(
     const nsresult& aResult, const RequestHeaderTuples& changedHeaders,
-    const ChildLoadInfoForwarderArgs& aLoadInfoForwarder,
+    const uint32_t& aSourceRequestBlockingReason,
+    const ChildLoadInfoForwarderArgs& aTargetLoadInfoForwarder,
     const uint32_t& loadFlags, nsIReferrerInfo* aReferrerInfo,
     const Maybe<URIParams>& aAPIRedirectURI,
     const Maybe<CorsPreflightArgs>& aCorsPreflightArgs,
     const bool& aChooseAppcache) {
   LOG(("HttpChannelParent::RecvRedirect2Verify [this=%p result=%" PRIx32 "]\n",
        this, static_cast<uint32_t>(aResult)));
 
   // Result from the child.  If something fails here, we might overwrite a
@@ -923,23 +924,32 @@ mozilla::ipc::IPCResult HttpChannelParen
 
       nsCOMPtr<nsIApplicationCacheChannel> appCacheChannel =
           do_QueryInterface(newHttpChannel);
       if (appCacheChannel) {
         appCacheChannel->SetChooseApplicationCache(aChooseAppcache);
       }
 
       nsCOMPtr<nsILoadInfo> newLoadInfo = newHttpChannel->LoadInfo();
-      rv = MergeChildLoadInfoForwarder(aLoadInfoForwarder, newLoadInfo);
+      rv = MergeChildLoadInfoForwarder(aTargetLoadInfoForwarder, newLoadInfo);
       if (NS_FAILED(rv) && NS_SUCCEEDED(result)) {
         result = rv;
       }
     }
   }
 
+  // If the redirect is vetoed, reason is set on the source (current) channel's
+  // load info, so we must carry iver the change.
+  if (aSourceRequestBlockingReason) {
+    nsCOMPtr<nsILoadInfo> sourceLoadInfo = mChannel->LoadInfo();
+    if (sourceLoadInfo) {
+      sourceLoadInfo->SetRequestBlockingReason(aSourceRequestBlockingReason);
+    }
+  }
+
   // Continue the verification procedure if child has veto the redirection.
   if (NS_FAILED(result)) {
     ContinueRedirect2Verify(result);
     return IPC_OK();
   }
 
   // Wait for background channel ready on target channel
   nsCOMPtr<nsIRedirectChannelRegistrar> redirectReg =
--- a/netwerk/protocol/http/HttpChannelParent.h
+++ b/netwerk/protocol/http/HttpChannelParent.h
@@ -194,17 +194,18 @@ class HttpChannelParent final : public n
       const uint32_t& cos) override;
   virtual mozilla::ipc::IPCResult RecvSetCacheTokenCachedCharset(
       const nsCString& charset) override;
   virtual mozilla::ipc::IPCResult RecvSuspend() override;
   virtual mozilla::ipc::IPCResult RecvResume() override;
   virtual mozilla::ipc::IPCResult RecvCancel(const nsresult& status) override;
   virtual mozilla::ipc::IPCResult RecvRedirect2Verify(
       const nsresult& result, const RequestHeaderTuples& changedHeaders,
-      const ChildLoadInfoForwarderArgs& aLoadInfoForwarder,
+      const uint32_t& aSourceRequestBlockingReason,
+      const ChildLoadInfoForwarderArgs& aTargetLoadInfoForwarder,
       const uint32_t& loadFlags, nsIReferrerInfo* aReferrerInfo,
       const Maybe<URIParams>& apiRedirectUri,
       const Maybe<CorsPreflightArgs>& aCorsPreflightArgs,
       const bool& aChooseAppcache) override;
   virtual mozilla::ipc::IPCResult RecvDocumentChannelCleanup(
       const bool& clearCacheEntry) override;
   virtual mozilla::ipc::IPCResult RecvMarkOfflineCacheEntryAsForeign() override;
   virtual mozilla::ipc::IPCResult RecvDivertOnDataAvailable(
--- a/netwerk/protocol/http/PHttpChannel.ipdl
+++ b/netwerk/protocol/http/PHttpChannel.ipdl
@@ -39,17 +39,18 @@ parent:
 
   async Suspend();
   async Resume();
 
   async Cancel(nsresult status);
 
   // Reports approval/veto of redirect by child process redirect observers
   async Redirect2Verify(nsresult result, RequestHeaderTuples changedHeaders,
-                        ChildLoadInfoForwarderArgs loadInfoForwarder,
+                        uint32_t sourceRequestBlockingReason,
+                        ChildLoadInfoForwarderArgs targetLoadInfoForwarder,
                         uint32_t loadFlags, nsIReferrerInfo referrerInfo,
                         URIParams? apiRedirectTo,
                         CorsPreflightArgs? corsPreflightArgs,
                         bool chooseAppcache);
 
   // For document loads we keep this protocol open after child's
   // OnStopRequest, and send this msg (instead of __delete__) to allow
   // partial cleanup on parent.