From 27d2b8a269b91e51b9aba60af67b51295dc867ad Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Tue, 7 Jan 2020 20:57:52 +0000 Subject: [PATCH] Bug 1598523 - Create nsIWrapperChannel so that we can find the inner channel within view-source. r=mayhemer Differential Revision: https://phabricator.services.mozilla.com/D57893 --HG-- extra : moz-landing-system : lando --- netwerk/base/moz.build | 1 + netwerk/base/nsIWrapperChannel.idl | 18 ++++++++++++++++++ netwerk/ipc/DocumentLoadListener.cpp | 7 ++++++- netwerk/protocol/http/HttpChannelParent.cpp | 6 ++++++ .../viewsource/nsViewSourceChannel.cpp | 10 ++++++++++ .../protocol/viewsource/nsViewSourceChannel.h | 5 ++++- 6 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 netwerk/base/nsIWrapperChannel.idl diff --git a/netwerk/base/moz.build b/netwerk/base/moz.build index 5b9386c0464a..4d553ffdbbbe 100644 --- a/netwerk/base/moz.build +++ b/netwerk/base/moz.build @@ -127,6 +127,7 @@ XPIDL_SOURCES += [ 'nsIURIWithSpecialOrigin.idl', 'nsIURL.idl', 'nsIURLParser.idl', + 'nsIWrapperChannel.idl', 'nsPISocketTransportService.idl', ] diff --git a/netwerk/base/nsIWrapperChannel.idl b/netwerk/base/nsIWrapperChannel.idl new file mode 100644 index 000000000000..0c66d86ef456 --- /dev/null +++ b/netwerk/base/nsIWrapperChannel.idl @@ -0,0 +1,18 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsIChannel.idl" + +/** + * A channel that exists as a wrapper around another channel, + * like view-source. + * + * Exposes the inner channel for callers that need it. + */ + +[uuid(2dfce356-b3e0-4f5e-bb55-e91cf9b49acc)] +interface nsIWrapperChannel : nsISupports +{ + readonly attribute nsIChannel innerChannel; +}; diff --git a/netwerk/ipc/DocumentLoadListener.cpp b/netwerk/ipc/DocumentLoadListener.cpp index 9349d4fc9847..3b7a5043b3d4 100644 --- a/netwerk/ipc/DocumentLoadListener.cpp +++ b/netwerk/ipc/DocumentLoadListener.cpp @@ -33,6 +33,7 @@ #include "nsExternalHelperAppService.h" #include "nsCExternalHandlerService.h" #include "nsMimeTypes.h" +#include "nsIWrapperChannel.h" mozilla::LazyLogModule gDocumentChannelLog("DocumentChannel"); #define LOG(fmt) MOZ_LOG(gDocumentChannelLog, mozilla::LogLevel::Verbose, fmt) @@ -672,7 +673,11 @@ void DocumentLoadListener::SerializeRedirectData( nsCOMPtr registrar = RedirectChannelRegistrar::GetOrCreate(); MOZ_ASSERT(registrar); - nsresult rv = registrar->RegisterChannel(mChannel, &mRedirectChannelId); + nsCOMPtr chan = mChannel; + if (nsCOMPtr wrapper = do_QueryInterface(chan)) { + wrapper->GetInnerChannel(getter_AddRefs(chan)); + } + nsresult rv = registrar->RegisterChannel(chan, &mRedirectChannelId); NS_ENSURE_SUCCESS_VOID(rv); aArgs.registrarId() = mRedirectChannelId; diff --git a/netwerk/protocol/http/HttpChannelParent.cpp b/netwerk/protocol/http/HttpChannelParent.cpp index 936e1fca56cf..4189f68701d5 100644 --- a/netwerk/protocol/http/HttpChannelParent.cpp +++ b/netwerk/protocol/http/HttpChannelParent.cpp @@ -53,6 +53,7 @@ #include "nsThreadUtils.h" #include "nsQueryObject.h" #include "nsIMultiPartChannel.h" +#include "nsIWrapperChannel.h" using mozilla::BasePrincipal; using namespace mozilla::dom; @@ -1366,6 +1367,11 @@ HttpChannelParent::OnStartRequest(nsIRequest* aRequest) { multiPartChannel->GetPartID(&partID); multiPartID = Some(partID); multiPartChannel->GetIsLastPart(&isLastPartOfMultiPart); + } else if (nsCOMPtr wrapperChannel = + do_QueryInterface(aRequest)) { + nsCOMPtr inner; + wrapperChannel->GetInnerChannel(getter_AddRefs(inner)); + chan = do_QueryObject(inner); } } MOZ_ASSERT(multiPartID || !mIsMultiPart, "Changed multi-part state?"); diff --git a/netwerk/protocol/viewsource/nsViewSourceChannel.cpp b/netwerk/protocol/viewsource/nsViewSourceChannel.cpp index 7084dbc3927b..647e452e6844 100644 --- a/netwerk/protocol/viewsource/nsViewSourceChannel.cpp +++ b/netwerk/protocol/viewsource/nsViewSourceChannel.cpp @@ -28,6 +28,7 @@ NS_INTERFACE_MAP_BEGIN(nsViewSourceChannel) NS_INTERFACE_MAP_ENTRY(nsIViewSourceChannel) NS_INTERFACE_MAP_ENTRY(nsIStreamListener) NS_INTERFACE_MAP_ENTRY(nsIRequestObserver) + NS_INTERFACE_MAP_ENTRY(nsIWrapperChannel) NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIHttpChannel, mHttpChannel) NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIIdentChannel, mHttpChannel) NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIHttpChannelInternal, @@ -1067,3 +1068,12 @@ nsViewSourceChannel::CompleteRedirectSetup(nsIStreamListener* aListener, return rv; } + +NS_IMETHODIMP +nsViewSourceChannel::GetInnerChannel(nsIChannel** aChannel) { + NS_ENSURE_TRUE(mChannel, NS_ERROR_NOT_INITIALIZED); + + nsCOMPtr chan = mChannel; + chan.forget(aChannel); + return NS_OK; +} diff --git a/netwerk/protocol/viewsource/nsViewSourceChannel.h b/netwerk/protocol/viewsource/nsViewSourceChannel.h index d507fe1c1dc4..eed965efd62c 100644 --- a/netwerk/protocol/viewsource/nsViewSourceChannel.h +++ b/netwerk/protocol/viewsource/nsViewSourceChannel.h @@ -17,6 +17,7 @@ #include "nsIStreamListener.h" #include "nsIURI.h" #include "nsIViewSourceChannel.h" +#include "nsIWrapperChannel.h" #include "nsIChildChannel.h" #include "nsString.h" @@ -27,7 +28,8 @@ class nsViewSourceChannel final : public nsIViewSourceChannel, public nsICachingChannel, public nsIApplicationCacheChannel, public nsIFormPOSTActionChannel, - public nsIChildChannel { + public nsIChildChannel, + public nsIWrapperChannel { public: NS_DECL_ISUPPORTS NS_DECL_NSIREQUEST @@ -38,6 +40,7 @@ class nsViewSourceChannel final : public nsIViewSourceChannel, NS_DECL_NSIREQUESTOBSERVER NS_DECL_NSIHTTPCHANNEL NS_DECL_NSICHILDCHANNEL + NS_DECL_NSIWRAPPERCHANNEL NS_FORWARD_SAFE_NSICACHEINFOCHANNEL(mCacheInfoChannel) NS_FORWARD_SAFE_NSICACHINGCHANNEL(mCachingChannel) NS_FORWARD_SAFE_NSIAPPLICATIONCACHECHANNEL(mApplicationCacheChannel)