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
This commit is contained in:
Matt Woodrow 2020-01-08 01:00:35 +00:00
Родитель ff5ffc1ea3
Коммит 5913bdc39b
6 изменённых файлов: 45 добавлений и 2 удалений

Просмотреть файл

@ -127,6 +127,7 @@ XPIDL_SOURCES += [
'nsIURIWithSpecialOrigin.idl', 'nsIURIWithSpecialOrigin.idl',
'nsIURL.idl', 'nsIURL.idl',
'nsIURLParser.idl', 'nsIURLParser.idl',
'nsIWrapperChannel.idl',
'nsPISocketTransportService.idl', 'nsPISocketTransportService.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;
};

Просмотреть файл

@ -33,6 +33,7 @@
#include "nsExternalHelperAppService.h" #include "nsExternalHelperAppService.h"
#include "nsCExternalHandlerService.h" #include "nsCExternalHandlerService.h"
#include "nsMimeTypes.h" #include "nsMimeTypes.h"
#include "nsIWrapperChannel.h"
mozilla::LazyLogModule gDocumentChannelLog("DocumentChannel"); mozilla::LazyLogModule gDocumentChannelLog("DocumentChannel");
#define LOG(fmt) MOZ_LOG(gDocumentChannelLog, mozilla::LogLevel::Verbose, fmt) #define LOG(fmt) MOZ_LOG(gDocumentChannelLog, mozilla::LogLevel::Verbose, fmt)
@ -672,7 +673,11 @@ void DocumentLoadListener::SerializeRedirectData(
nsCOMPtr<nsIRedirectChannelRegistrar> registrar = nsCOMPtr<nsIRedirectChannelRegistrar> registrar =
RedirectChannelRegistrar::GetOrCreate(); RedirectChannelRegistrar::GetOrCreate();
MOZ_ASSERT(registrar); MOZ_ASSERT(registrar);
nsresult rv = registrar->RegisterChannel(mChannel, &mRedirectChannelId); nsCOMPtr<nsIChannel> chan = mChannel;
if (nsCOMPtr<nsIWrapperChannel> wrapper = do_QueryInterface(chan)) {
wrapper->GetInnerChannel(getter_AddRefs(chan));
}
nsresult rv = registrar->RegisterChannel(chan, &mRedirectChannelId);
NS_ENSURE_SUCCESS_VOID(rv); NS_ENSURE_SUCCESS_VOID(rv);
aArgs.registrarId() = mRedirectChannelId; aArgs.registrarId() = mRedirectChannelId;

Просмотреть файл

@ -53,6 +53,7 @@
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "nsQueryObject.h" #include "nsQueryObject.h"
#include "nsIMultiPartChannel.h" #include "nsIMultiPartChannel.h"
#include "nsIWrapperChannel.h"
using mozilla::BasePrincipal; using mozilla::BasePrincipal;
using namespace mozilla::dom; using namespace mozilla::dom;
@ -1366,6 +1367,11 @@ HttpChannelParent::OnStartRequest(nsIRequest* aRequest) {
multiPartChannel->GetPartID(&partID); multiPartChannel->GetPartID(&partID);
multiPartID = Some(partID); multiPartID = Some(partID);
multiPartChannel->GetIsLastPart(&isLastPartOfMultiPart); multiPartChannel->GetIsLastPart(&isLastPartOfMultiPart);
} else if (nsCOMPtr<nsIWrapperChannel> wrapperChannel =
do_QueryInterface(aRequest)) {
nsCOMPtr<nsIChannel> inner;
wrapperChannel->GetInnerChannel(getter_AddRefs(inner));
chan = do_QueryObject(inner);
} }
} }
MOZ_ASSERT(multiPartID || !mIsMultiPart, "Changed multi-part state?"); MOZ_ASSERT(multiPartID || !mIsMultiPart, "Changed multi-part state?");

Просмотреть файл

@ -28,6 +28,7 @@ NS_INTERFACE_MAP_BEGIN(nsViewSourceChannel)
NS_INTERFACE_MAP_ENTRY(nsIViewSourceChannel) NS_INTERFACE_MAP_ENTRY(nsIViewSourceChannel)
NS_INTERFACE_MAP_ENTRY(nsIStreamListener) NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver) NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
NS_INTERFACE_MAP_ENTRY(nsIWrapperChannel)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIHttpChannel, mHttpChannel) NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIHttpChannel, mHttpChannel)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIIdentChannel, mHttpChannel) NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIIdentChannel, mHttpChannel)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIHttpChannelInternal, NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIHttpChannelInternal,
@ -1067,3 +1068,12 @@ nsViewSourceChannel::CompleteRedirectSetup(nsIStreamListener* aListener,
return rv; return rv;
} }
NS_IMETHODIMP
nsViewSourceChannel::GetInnerChannel(nsIChannel** aChannel) {
NS_ENSURE_TRUE(mChannel, NS_ERROR_NOT_INITIALIZED);
nsCOMPtr<nsIChannel> chan = mChannel;
chan.forget(aChannel);
return NS_OK;
}

Просмотреть файл

@ -17,6 +17,7 @@
#include "nsIStreamListener.h" #include "nsIStreamListener.h"
#include "nsIURI.h" #include "nsIURI.h"
#include "nsIViewSourceChannel.h" #include "nsIViewSourceChannel.h"
#include "nsIWrapperChannel.h"
#include "nsIChildChannel.h" #include "nsIChildChannel.h"
#include "nsString.h" #include "nsString.h"
@ -27,7 +28,8 @@ class nsViewSourceChannel final : public nsIViewSourceChannel,
public nsICachingChannel, public nsICachingChannel,
public nsIApplicationCacheChannel, public nsIApplicationCacheChannel,
public nsIFormPOSTActionChannel, public nsIFormPOSTActionChannel,
public nsIChildChannel { public nsIChildChannel,
public nsIWrapperChannel {
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_NSIREQUEST NS_DECL_NSIREQUEST
@ -38,6 +40,7 @@ class nsViewSourceChannel final : public nsIViewSourceChannel,
NS_DECL_NSIREQUESTOBSERVER NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSIHTTPCHANNEL NS_DECL_NSIHTTPCHANNEL
NS_DECL_NSICHILDCHANNEL NS_DECL_NSICHILDCHANNEL
NS_DECL_NSIWRAPPERCHANNEL
NS_FORWARD_SAFE_NSICACHEINFOCHANNEL(mCacheInfoChannel) NS_FORWARD_SAFE_NSICACHEINFOCHANNEL(mCacheInfoChannel)
NS_FORWARD_SAFE_NSICACHINGCHANNEL(mCachingChannel) NS_FORWARD_SAFE_NSICACHINGCHANNEL(mCachingChannel)
NS_FORWARD_SAFE_NSIAPPLICATIONCACHECHANNEL(mApplicationCacheChannel) NS_FORWARD_SAFE_NSIAPPLICATIONCACHECHANNEL(mApplicationCacheChannel)