Bug 1596330 - Remove dead process switching code r=mattwoodrow
authorPaul Bone <pbone@mozilla.com>
Thu, 14 Nov 2019 08:43:05 +0000
changeset 502081 f1b88c7e983e1aacb8897ac1a2858b6af1514e82
parent 502080 9062e6ab980e537e00bcafd9ce16eb43d9a20366
child 502082 f406de07f131f6478b7d012f3534021698331f74
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1596330
milestone72.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 1596330 - Remove dead process switching code r=mattwoodrow Differential Revision: https://phabricator.services.mozilla.com/D52949
netwerk/protocol/http/HttpChannelParent.cpp
netwerk/protocol/http/HttpChannelParent.h
netwerk/protocol/http/nsHttpChannel.cpp
netwerk/protocol/http/nsHttpChannel.h
--- a/netwerk/protocol/http/HttpChannelParent.cpp
+++ b/netwerk/protocol/http/HttpChannelParent.cpp
@@ -2597,143 +2597,15 @@ HttpChannelParent::OnRedirectResult(bool
   } else if (redirectChannel) {
     // Delete the redirect target channel: continue using old channel
     redirectChannel->Delete();
   }
 
   return NS_OK;
 }
 
-nsresult HttpChannelParent::TriggerCrossProcessSwitch(nsIHttpChannel* aChannel,
-                                                      uint64_t aIdentifier) {
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // Mark ourselves as performing a cross-process redirect. This will prevent
-  // messages being communicated to the underlying channel, allowing us to keep
-  // it open.
-  MOZ_ASSERT(!mDoingCrossProcessRedirect, "Already redirected");
-  mDoingCrossProcessRedirect = true;
-
-  nsCOMPtr<nsIChannel> channel = aChannel;
-  RefPtr<nsHttpChannel> httpChannel = do_QueryObject(channel);
-  MOZ_DIAGNOSTIC_ASSERT(httpChannel,
-                        "Must be called with nsHttpChannel object");
-
-  RefPtr<nsHttpChannel::ContentProcessIdPromise> p =
-      httpChannel->TakeRedirectContentProcessIdPromise();
-
-  nsCOMPtr<nsIURI> uri;
-  aChannel->GetURI(getter_AddRefs(uri));
-
-  // We must set rpURI here to the target (the redirect-to) URL because
-  // otherwise NS_GetFinalChannelURI, used to build the channel principal,
-  // will use the OriginalURI of the channel, which is the first URL of the
-  // redirect chain. We can set rpURI here because http handler doesn't set
-  // rpURI on the load info during the channel creation (we set the rpURI after
-  // channel creation here). This is then specific to and possible only for the
-  // http protocol and MUST NOT be done this way when we make this code
-  // universal for any protocol (schema).
-  nsCOMPtr<nsILoadInfo> loadInfo = httpChannel->CloneLoadInfoForRedirect(
-      uri, nsIChannelEventSink::REDIRECT_INTERNAL);
-  loadInfo->SetResultPrincipalURI(uri);
-
-  RefPtr<HttpChannelParent> self = this;
-  p->Then(
-      GetMainThreadSerialEventTarget(), __func__,
-      [=](uint64_t cpId) {
-        nsresult rv;
-
-        // Cancel the channel in the original process, as the switch is
-        // happening in earnest.
-        if (!self->mIPCClosed) {
-          Unused << self->SendCancelRedirected();
-        }
-
-        // Register the new channel and obtain id for it
-        nsCOMPtr<nsIRedirectChannelRegistrar> registrar =
-            RedirectChannelRegistrar::GetOrCreate();
-        MOZ_ASSERT(registrar);
-        rv = registrar->RegisterChannel(channel, &self->mRedirectChannelId);
-        NS_ENSURE_SUCCESS_VOID(rv);
-
-        LOG(("Registered %p channel under id=%d", channel.get(),
-             self->mRedirectChannelId));
-
-        Maybe<LoadInfoArgs> loadInfoArgs;
-        MOZ_ALWAYS_SUCCEEDS(LoadInfoToLoadInfoArgs(loadInfo, &loadInfoArgs));
-
-        nsCOMPtr<nsIURI> uri;
-        channel->GetURI(getter_AddRefs(uri));
-
-        nsCOMPtr<nsIURI> originalURI;
-        channel->GetOriginalURI(getter_AddRefs(originalURI));
-
-        uint64_t channelId;
-        MOZ_ALWAYS_SUCCEEDS(httpChannel->GetChannelId(&channelId));
-
-        uint32_t redirectMode = nsIHttpChannelInternal::REDIRECT_MODE_FOLLOW;
-        nsCOMPtr<nsIHttpChannelInternal> internalChannel =
-            do_QueryInterface(channel);
-        if (internalChannel) {
-          MOZ_ALWAYS_SUCCEEDS(internalChannel->GetRedirectMode(&redirectMode));
-        }
-
-        ReplacementChannelConfigInit config =
-            httpChannel->CloneReplacementChannelConfig(true, 0).Serialize();
-
-        dom::ContentParent* cp =
-            dom::ContentProcessManager::GetSingleton()->GetContentProcessById(
-                ContentParentId{cpId});
-        if (!cp) {
-          return;
-        }
-        cp->SendCrossProcessRedirect(self->mRedirectChannelId, uri,
-                                     Some(config), loadInfoArgs, channelId,
-                                     originalURI, aIdentifier, redirectMode)
-            ->Then(
-                GetCurrentThreadSerialEventTarget(), __func__,
-                [self](Tuple<nsresult, Maybe<LoadInfoArgs>>&& aResponse) {
-                  // We need to continue on the new HttpChannelParent.
-                  MOZ_ASSERT(self->mRedirectChannelId);
-                  nsCOMPtr<nsIRedirectChannelRegistrar> redirectReg =
-                      RedirectChannelRegistrar::GetOrCreate();
-                  MOZ_ASSERT(redirectReg);
-
-                  nsCOMPtr<nsIParentChannel> redirectParentChannel;
-                  if (NS_FAILED(redirectReg->GetParentChannel(
-                          self->mRedirectChannelId,
-                          getter_AddRefs(redirectParentChannel))) ||
-                      !redirectParentChannel) {
-                    // Redirect might got canceled.
-                    self->CrossProcessRedirectDone(NS_ERROR_FAILURE, Nothing());
-                    return;
-                  }
-                  RefPtr<HttpChannelParent> newParent =
-                      do_QueryObject(redirectParentChannel);
-                  MOZ_ASSERT(newParent);
-                  newParent->CrossProcessRedirectDone(Get<0>(aResponse),
-                                                      Get<1>(aResponse));
-                },
-                [self](const mozilla::ipc::ResponseRejectReason) {
-                  self->CrossProcessRedirectDone(NS_ERROR_FAILURE, Nothing());
-                });
-      },
-      [=](nsresult aStatus) {
-        MOZ_ASSERT(NS_FAILED(aStatus), "Status should be error");
-
-        // We failed to do a process switch. Make sure the content process has
-        // canceled the channel, and then resume the load process with an error.
-        if (!self->mIPCClosed) {
-          Unused << self->SendCancelRedirected();
-        }
-        httpChannel->OnRedirectVerifyCallback(aStatus);
-      });
-
-  return NS_OK;
-}
-
 void HttpChannelParent::OverrideReferrerInfoDuringBeginConnect(
     nsIReferrerInfo* aReferrerInfo) {
   Unused << SendOverrideReferrerInfoDuringBeginConnect(aReferrerInfo);
 }
 
 }  // namespace net
 }  // namespace mozilla
--- a/netwerk/protocol/http/HttpChannelParent.h
+++ b/netwerk/protocol/http/HttpChannelParent.h
@@ -124,23 +124,16 @@ class HttpChannelParent final : public n
 
   // Callback while background channel is ready.
   void OnBackgroundParentReady(HttpBackgroundChannelParent* aBgParent);
   // Callback while background channel is destroyed.
   void OnBackgroundParentDestroyed();
 
   base::ProcessId OtherPid() const;
 
-  // Called by nsHttpChannel when a process switch is about to start.
-  // aChannel: nsIHttpChannel caller.
-  // aIdentifier: identifier from SessionStore to be passed to the childChannel
-  //              in order to identify it.
-  nsresult TriggerCrossProcessSwitch(nsIHttpChannel* aChannel,
-                                     uint64_t aIdentifier);
-
   // Inform the child actor that our referrer info was modified late during
   // BeginConnect.
   void OverrideReferrerInfoDuringBeginConnect(nsIReferrerInfo* aReferrerInfo);
 
  protected:
   // used to connect redirected-to channel in parent with just created
   // ChildChannel.  Used during redirects.
   MOZ_MUST_USE bool ConnectChannel(const uint32_t& channelId,
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -7340,38 +7340,16 @@ nsHttpChannel::GetCrossOriginOpenerPolic
   // policy we'll throw an error.
   if (!mComputedCrossOriginOpenerPolicy.isSome()) {
     return NS_ERROR_NOT_AVAILABLE;
   }
   *aPolicy = mComputedCrossOriginOpenerPolicy.value();
   return NS_OK;
 }
 
-nsresult nsHttpChannel::StartCrossProcessRedirect() {
-  nsresult rv;
-
-  LOG(("nsHttpChannel::StartCrossProcessRedirect [this=%p]", this));
-
-  rv = CheckRedirectLimit(nsIChannelEventSink::REDIRECT_INTERNAL);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCOMPtr<nsIParentChannel> parentChannel;
-  NS_QueryNotificationCallbacks(this, parentChannel);
-  RefPtr<HttpChannelParent> httpParent = do_QueryObject(parentChannel);
-  MOZ_ASSERT(httpParent);
-  NS_ENSURE_TRUE(httpParent, NS_ERROR_UNEXPECTED);
-
-  httpParent->TriggerCrossProcessSwitch(this, mCrossProcessRedirectIdentifier);
-
-  // This will suspend the channel
-  rv = WaitForRedirectCallback();
-
-  return rv;
-}
-
 // See https://gist.github.com/annevk/6f2dd8c79c77123f39797f6bdac43f3e
 // This method runs steps 1-4 of the algorithm to compare
 // cross-origin-opener policies
 static bool CompareCrossOriginOpenerPolicies(
     nsILoadInfo::CrossOriginOpenerPolicy documentPolicy,
     nsIPrincipal* documentOrigin,
     nsILoadInfo::CrossOriginOpenerPolicy resultPolicy,
     nsIPrincipal* resultOrigin) {
--- a/netwerk/protocol/http/nsHttpChannel.h
+++ b/netwerk/protocol/http/nsHttpChannel.h
@@ -373,17 +373,16 @@ class nsHttpChannel final : public HttpB
   MOZ_MUST_USE nsresult ContinueHandleAsyncRedirect(nsresult);
   void HandleAsyncNotModified();
   void HandleAsyncFallback();
   MOZ_MUST_USE nsresult ContinueHandleAsyncFallback(nsresult);
   MOZ_MUST_USE nsresult PromptTempRedirect();
   virtual MOZ_MUST_USE nsresult
   SetupReplacementChannel(nsIURI*, nsIChannel*, bool preserveMethod,
                           uint32_t redirectFlags) override;
-  nsresult StartCrossProcessRedirect();
 
   // proxy specific methods
   MOZ_MUST_USE nsresult ProxyFailover();
   MOZ_MUST_USE nsresult AsyncDoReplaceWithProxy(nsIProxyInfo*);
   MOZ_MUST_USE nsresult ContinueDoReplaceWithProxy(nsresult);
   MOZ_MUST_USE nsresult ResolveProxy();
 
   // cache specific methods