Bug 1576714 - Part 4: Delay canceling original http channel during process switch, r=mattwoodrow

This patch changes when the original HttpChannelChild gets canceled during a
process switch to be after when the process switch is completed. This is needed
to prevent the load event firing too early in the original content process.

Differential Revision: https://phabricator.services.mozilla.com/D47311

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nika Layzell 2019-10-03 21:40:31 +00:00
parent 89b22d83ef
commit 03df92a7e0
2 changed files with 20 additions and 18 deletions

View File

@ -2114,16 +2114,6 @@ HttpChannelParent::StartRedirect(nsIChannel* newChannel, uint32_t redirectFlags,
return NS_OK;
}
void HttpChannelParent::CancelChildCrossProcessRedirect() {
MOZ_ASSERT(!mDoingCrossProcessRedirect, "Already redirected");
MOZ_ASSERT(NS_IsMainThread());
mDoingCrossProcessRedirect = true;
if (!mIPCClosed) {
Unused << SendCancelRedirected();
}
}
NS_IMETHODIMP
HttpChannelParent::CompleteRedirect(bool succeeded) {
LOG(("HttpChannelParent::CompleteRedirect [this=%p succeeded=%d]\n", this,
@ -2642,7 +2632,13 @@ HttpChannelParent::OnRedirectResult(bool succeeded) {
nsresult HttpChannelParent::TriggerCrossProcessSwitch(nsIHttpChannel* aChannel,
uint64_t aIdentifier) {
CancelChildCrossProcessRedirect();
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);
@ -2673,6 +2669,12 @@ nsresult HttpChannelParent::TriggerCrossProcessSwitch(nsIHttpChannel* aChannel,
[=](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();
@ -2742,8 +2744,14 @@ nsresult HttpChannelParent::TriggerCrossProcessSwitch(nsIHttpChannel* aChannel,
self->CrossProcessRedirectDone(NS_ERROR_FAILURE, Nothing());
});
},
[httpChannel](nsresult aStatus) {
[=](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);
});

View File

@ -136,12 +136,6 @@ class HttpChannelParent final : public nsIInterfaceRequestor,
nsresult TriggerCrossProcessSwitch(nsIHttpChannel* aChannel,
uint64_t aIdentifier);
// Calling this method will cancel the HttpChannelChild because the consumer
// needs to be relocated to another process.
// Any OnStart/Stop/DataAvailable calls that follow will not be sent to the
// child channel.
void CancelChildCrossProcessRedirect();
protected:
// used to connect redirected-to channel in parent with just created
// ChildChannel. Used during redirects.