Commit 2746af48 authored by Jean-Yves Avenard's avatar Jean-Yves Avenard
Browse files

Bug 1637869 - P6. Propagate proper error code when cancelling a channel. r=mattwoodrow

parent 710b7ac9
Loading
Loading
Loading
Loading
+14 −19
Original line number Diff line number Diff line
@@ -754,13 +754,8 @@ void DocumentLoadListener::RedirectToRealChannelFinished(nsresult aRv) {
      ("DocumentLoadListener RedirectToRealChannelFinished [this=%p, "
       "aRv=%" PRIx32 " ]",
       this, static_cast<uint32_t>(aRv)));
  if (NS_FAILED(aRv)) {
    FinishReplacementChannelSetup(false);
    return;
  }

  if (!mRedirectChannelId) {
    FinishReplacementChannelSetup(true);
  if (NS_FAILED(aRv) || !mRedirectChannelId) {
    FinishReplacementChannelSetup(aRv);
    return;
  }

@@ -773,7 +768,7 @@ void DocumentLoadListener::RedirectToRealChannelFinished(nsresult aRv) {
  redirectReg->GetParentChannel(mRedirectChannelId,
                                getter_AddRefs(redirectParentChannel));
  if (!redirectParentChannel) {
    FinishReplacementChannelSetup(false);
    FinishReplacementChannelSetup(NS_ERROR_FAILURE);
    return;
  }

@@ -781,7 +776,7 @@ void DocumentLoadListener::RedirectToRealChannelFinished(nsresult aRv) {
      do_QueryInterface(redirectParentChannel);
  if (!redirectingParent) {
    // Continue verification procedure if redirecting to non-Http protocol
    FinishReplacementChannelSetup(true);
    FinishReplacementChannelSetup(NS_OK);
    return;
  }

@@ -792,23 +787,23 @@ void DocumentLoadListener::RedirectToRealChannelFinished(nsresult aRv) {

NS_IMETHODIMP
DocumentLoadListener::ReadyToVerify(nsresult aResultCode) {
  FinishReplacementChannelSetup(NS_SUCCEEDED(aResultCode));
  FinishReplacementChannelSetup(aResultCode);
  return NS_OK;
}

void DocumentLoadListener::FinishReplacementChannelSetup(bool aSucceeded) {
void DocumentLoadListener::FinishReplacementChannelSetup(nsresult aResult) {
  LOG(
      ("DocumentLoadListener FinishReplacementChannelSetup [this=%p, "
       "aSucceeded=%d]",
       this, aSucceeded));
       "aResult=%x]",
       this, int(aResult)));

  if (mDoingProcessSwitch) {
    DisconnectChildListeners(NS_BINDING_ABORTED, NS_BINDING_ABORTED);
  }

  if (!mRedirectChannelId) {
    if (!aSucceeded) {
      mChannel->Cancel(NS_BINDING_ABORTED);
    if (NS_FAILED(aResult)) {
      mChannel->Cancel(aResult);
      mChannel->Resume();
      return;
    }
@@ -833,10 +828,10 @@ void DocumentLoadListener::FinishReplacementChannelSetup(bool aSucceeded) {
    MOZ_ASSERT(newChannel, "Already registered channel not found");

    if (NS_SUCCEEDED(rv)) {
      newChannel->Cancel(NS_BINDING_ABORTED);
      newChannel->Cancel(NS_ERROR_FAILURE);
    }
    if (!redirectChannel) {
      aSucceeded = false;
      aResult = NS_ERROR_FAILURE;
    }
  }

@@ -844,11 +839,11 @@ void DocumentLoadListener::FinishReplacementChannelSetup(bool aSucceeded) {
  // be kept in the registrar from this moment.
  registrar->DeregisterChannels(mRedirectChannelId);
  mRedirectChannelId = 0;
  if (!aSucceeded) {
  if (NS_FAILED(aResult)) {
    if (redirectChannel) {
      redirectChannel->Delete();
    }
    mChannel->Cancel(NS_BINDING_ABORTED);
    mChannel->Cancel(aResult);
    mChannel->Resume();
    if (auto* ctx = GetBrowsingContext()) {
      ctx->EndDocumentLoad(this);
+1 −1
Original line number Diff line number Diff line
@@ -240,7 +240,7 @@ class DocumentLoadListener : public nsIInterfaceRequestor,
  // This redirects the ParentChannelListener to forward any future
  // messages to the new channel, manually forwards any being held
  // by us, and resumes the underlying source channel.
  void FinishReplacementChannelSetup(bool aSucceeded);
  void FinishReplacementChannelSetup(nsresult aResult);

  // Called from `OnStartRequest` to make the decision about whether or not to
  // change process. This method will return `nullptr` if the current target
+2 −2
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ ParentProcessDocumentChannel::RedirectToRealChannel(
          "Attempt to load a non-authorised load in the parent process: ", 0);
      NS_ASSERTION(false, msg.get());
      return PDocumentChannelParent::RedirectToRealChannelPromise::
          CreateAndResolve(NS_BINDING_ABORTED, __func__);
          CreateAndResolve(NS_ERROR_CONTENT_BLOCKED, __func__);
    }
  }
  mStreamFilterEndpoints = std::move(aStreamFilterEndpoints);
@@ -86,7 +86,7 @@ ParentProcessDocumentChannel::OnRedirectVerifyCallback(nsresult aResult) {
  if (NS_FAILED(aResult)) {
    Cancel(aResult);
  } else if (mCanceled && NS_SUCCEEDED(aResult)) {
    aResult = NS_BINDING_ABORTED;
    aResult = NS_ERROR_ABORT;
  } else {
    const nsCOMPtr<nsIChannel> channel = mDocumentLoadListener->GetChannel();
    mLoadGroup->AddRequest(channel, nullptr);