From 6ff998ce0c912c2e640af904770e111880506883 Mon Sep 17 00:00:00 2001 From: Junior Hsu Date: Thu, 21 May 2020 22:41:44 +0000 Subject: [PATCH] Bug 1638313 - Let devtool show CORS rejected requests correctly, r=necko-reviewers,mayhemer Differential Revision: https://phabricator.services.mozilla.com/D76255 --- netwerk/protocol/http/HttpChannelChild.cpp | 2 +- netwerk/protocol/http/HttpChannelParent.cpp | 17 ++++++++++++----- netwerk/protocol/http/HttpChannelParent.h | 3 ++- netwerk/protocol/http/PHttpChannel.ipdl | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/netwerk/protocol/http/HttpChannelChild.cpp b/netwerk/protocol/http/HttpChannelChild.cpp index 7af938c4dd7f..2949f7f35cd4 100644 --- a/netwerk/protocol/http/HttpChannelChild.cpp +++ b/netwerk/protocol/http/HttpChannelChild.cpp @@ -2280,7 +2280,7 @@ HttpChannelChild::Cancel(nsresult aStatus) { mCanceled = true; mStatus = aStatus; if (RemoteChannelExists()) { - SendCancel(aStatus); + SendCancel(aStatus, mLoadInfo->GetRequestBlockingReason()); } // If the channel is intercepted and already pumping, then just diff --git a/netwerk/protocol/http/HttpChannelParent.cpp b/netwerk/protocol/http/HttpChannelParent.cpp index eef92e56db85..0f4c5f7306b6 100644 --- a/netwerk/protocol/http/HttpChannelParent.cpp +++ b/netwerk/protocol/http/HttpChannelParent.cpp @@ -807,13 +807,20 @@ mozilla::ipc::IPCResult HttpChannelParent::RecvResume() { return IPC_OK(); } -mozilla::ipc::IPCResult HttpChannelParent::RecvCancel(const nsresult& status) { +mozilla::ipc::IPCResult HttpChannelParent::RecvCancel( + const nsresult& status, const uint32_t& requestBlockingReason) { LOG(("HttpChannelParent::RecvCancel [this=%p]\n", this)); // May receive cancel before channel has been constructed! if (mChannel) { mChannel->Cancel(status); + if (MOZ_UNLIKELY(requestBlockingReason != + nsILoadInfo::BLOCKING_REASON_NONE)) { + nsCOMPtr loadInfo = mChannel->LoadInfo(); + loadInfo->SetRequestBlockingReason(requestBlockingReason); + } + // Once we receive |Cancel|, child will stop sending RecvBytesRead. Force // the channel resumed if needed. if (mSuspendedForFlowControl) { @@ -939,11 +946,11 @@ mozilla::ipc::IPCResult HttpChannelParent::RecvRedirect2Verify( // load info, so we must carry iver the change. // The channel may have already been cleaned up, so there is nothing we can // do. - if (MOZ_UNLIKELY(aSourceRequestBlockingReason) && mChannel) { + if (MOZ_UNLIKELY(aSourceRequestBlockingReason != + nsILoadInfo::BLOCKING_REASON_NONE) && + mChannel) { nsCOMPtr sourceLoadInfo = mChannel->LoadInfo(); - if (sourceLoadInfo) { - sourceLoadInfo->SetRequestBlockingReason(aSourceRequestBlockingReason); - } + sourceLoadInfo->SetRequestBlockingReason(aSourceRequestBlockingReason); } // Continue the verification procedure if child has veto the redirection. diff --git a/netwerk/protocol/http/HttpChannelParent.h b/netwerk/protocol/http/HttpChannelParent.h index 841d20e8845c..d115e0261f4f 100644 --- a/netwerk/protocol/http/HttpChannelParent.h +++ b/netwerk/protocol/http/HttpChannelParent.h @@ -187,7 +187,8 @@ class HttpChannelParent final : public nsIInterfaceRequestor, 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 RecvCancel( + const nsresult& status, const uint32_t& requestBlockingReason) override; virtual mozilla::ipc::IPCResult RecvRedirect2Verify( const nsresult& result, const RequestHeaderTuples& changedHeaders, const uint32_t& aSourceRequestBlockingReason, diff --git a/netwerk/protocol/http/PHttpChannel.ipdl b/netwerk/protocol/http/PHttpChannel.ipdl index 931ab82f5f58..d0d8a6e90aee 100644 --- a/netwerk/protocol/http/PHttpChannel.ipdl +++ b/netwerk/protocol/http/PHttpChannel.ipdl @@ -40,7 +40,7 @@ parent: async Suspend(); async Resume(); - async Cancel(nsresult status); + async Cancel(nsresult status, uint32_t requestBlockingReason); // Reports approval/veto of redirect by child process redirect observers async Redirect2Verify(nsresult result, RequestHeaderTuples changedHeaders,