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-07 20:57:52 +00:00
Родитель a92b542805
Коммит 27d2b8a269
6 изменённых файлов: 45 добавлений и 2 удалений

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

@ -127,6 +127,7 @@ XPIDL_SOURCES += [
'nsIURIWithSpecialOrigin.idl',
'nsIURL.idl',
'nsIURLParser.idl',
'nsIWrapperChannel.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 "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<nsIRedirectChannelRegistrar> registrar =
RedirectChannelRegistrar::GetOrCreate();
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);
aArgs.registrarId() = mRedirectChannelId;

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

@ -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<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?");

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

@ -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<nsIChannel> chan = mChannel;
chan.forget(aChannel);
return NS_OK;
}

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

@ -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)