Bug 1612992 - Don't replace the nsIRequest passed to OnStart/StopRequest with nsViewSourceChannel if we don't need it. r=mayhemer

Differential Revision: https://phabricator.services.mozilla.com/D63285

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Matt Woodrow 2020-02-26 22:59:34 +00:00
Родитель b9b6d27e26
Коммит af33d93580
7 изменённых файлов: 51 добавлений и 52 удалений

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

@ -127,7 +127,6 @@ XPIDL_SOURCES += [
'nsIURIWithSpecialOrigin.idl',
'nsIURL.idl',
'nsIURLParser.idl',
'nsIWrapperChannel.idl',
'nsPISocketTransportService.idl',
]

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

@ -1,18 +0,0 @@
/* 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;
};

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

@ -32,7 +32,7 @@
#include "nsExternalHelperAppService.h"
#include "nsCExternalHandlerService.h"
#include "nsMimeTypes.h"
#include "nsIWrapperChannel.h"
#include "nsIViewSourceChannel.h"
mozilla::LazyLogModule gDocumentChannelLog("DocumentChannel");
#define LOG(fmt) MOZ_LOG(gDocumentChannelLog, mozilla::LogLevel::Verbose, fmt)
@ -307,6 +307,15 @@ bool DocumentLoadListener::Open(
timedChannel->SetAsyncOpen(aAsyncOpenTime);
}
// nsViewSourceChannel normally replaces the nsIRequest passed to
// OnStart/StopRequest with itself. We don't need this, and instead
// we want the original request so that we get different ones for
// each part of a multipart channel.
if (nsCOMPtr<nsIViewSourceChannel> viewSourceChannel =
do_QueryInterface(mChannel)) {
viewSourceChannel->SetReplaceRequest(false);
}
// Setup a ClientChannelHelper to watch for redirects, and copy
// across any serviceworker related data between channels as needed.
AddClientChannelHelperInParent(mChannel, GetMainThreadSerialEventTarget());
@ -650,11 +659,7 @@ void DocumentLoadListener::SerializeRedirectData(
nsCOMPtr<nsIRedirectChannelRegistrar> registrar =
RedirectChannelRegistrar::GetOrCreate();
MOZ_ASSERT(registrar);
nsCOMPtr<nsIChannel> chan = mChannel;
if (nsCOMPtr<nsIWrapperChannel> wrapper = do_QueryInterface(chan)) {
wrapper->GetInnerChannel(getter_AddRefs(chan));
}
nsresult rv = registrar->RegisterChannel(chan, &mRedirectChannelId);
nsresult rv = registrar->RegisterChannel(mChannel, &mRedirectChannelId);
NS_ENSURE_SUCCESS_VOID(rv);
aArgs.registrarId() = mRedirectChannelId;

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

@ -53,7 +53,6 @@
#include "nsThreadUtils.h"
#include "nsQueryObject.h"
#include "nsIMultiPartChannel.h"
#include "nsIWrapperChannel.h"
using mozilla::BasePrincipal;
using namespace mozilla::dom;
@ -1383,11 +1382,6 @@ 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?");

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

@ -33,6 +33,14 @@ interface nsIViewSourceChannel : nsIChannel
* srcdoc channel.
*/
[must_use] attribute nsIURI baseURI;
/**
* If true (default), then replaces the nsIRequest* passed to
* nsIStreamListener callback functions with itself, so that
* nsIViewSourceChannel is available.
* Otherwise passes through the the nsIRequest* from the inner channel.
*/
attribute boolean replaceRequest;
};

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

@ -28,7 +28,6 @@ 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(nsIInterfaceRequestor)
NS_INTERFACE_MAP_ENTRY(nsIChannelEventSink)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIHttpChannel, mHttpChannel)
@ -647,6 +646,18 @@ nsViewSourceChannel::GetProtocolVersion(nsACString& aProtocolVersion) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsViewSourceChannel::GetReplaceRequest(bool* aReplaceRequest) {
*aReplaceRequest = mReplaceRequest;
return NS_OK;
}
NS_IMETHODIMP
nsViewSourceChannel::SetReplaceRequest(bool aReplaceRequest) {
mReplaceRequest = aReplaceRequest;
return NS_OK;
}
// nsIRequestObserver methods
NS_IMETHODIMP
nsViewSourceChannel::OnStartRequest(nsIRequest* aRequest) {
@ -663,7 +674,10 @@ nsViewSourceChannel::OnStartRequest(nsIRequest* aRequest) {
Cancel(rv);
}
return mListener->OnStartRequest(static_cast<nsIViewSourceChannel*>(this));
if (mReplaceRequest) {
return mListener->OnStartRequest(static_cast<nsIViewSourceChannel*>(this));
}
return mListener->OnStartRequest(aRequest);
}
NS_IMETHODIMP
@ -677,8 +691,11 @@ nsViewSourceChannel::OnStopRequest(nsIRequest* aRequest, nsresult aStatus) {
nullptr, aStatus);
}
}
return mListener->OnStopRequest(static_cast<nsIViewSourceChannel*>(this),
aStatus);
if (mReplaceRequest) {
return mListener->OnStopRequest(static_cast<nsIViewSourceChannel*>(this),
aStatus);
}
return mListener->OnStopRequest(aRequest, aStatus);
}
// nsIStreamListener methods
@ -687,8 +704,12 @@ nsViewSourceChannel::OnDataAvailable(nsIRequest* aRequest,
nsIInputStream* aInputStream,
uint64_t aSourceOffset, uint32_t aLength) {
NS_ENSURE_TRUE(mListener, NS_ERROR_FAILURE);
return mListener->OnDataAvailable(static_cast<nsIViewSourceChannel*>(this),
aInputStream, aSourceOffset, aLength);
if (mReplaceRequest) {
return mListener->OnDataAvailable(static_cast<nsIViewSourceChannel*>(this),
aInputStream, aSourceOffset, aLength);
}
return mListener->OnDataAvailable(aRequest, aInputStream, aSourceOffset,
aLength);
}
// nsIHttpChannel methods
@ -1088,17 +1109,6 @@ nsViewSourceChannel::CompleteRedirectSetup(nsIStreamListener* aListener,
return rv;
}
// nsIWrapperChannel
NS_IMETHODIMP
nsViewSourceChannel::GetInnerChannel(nsIChannel** aChannel) {
NS_ENSURE_TRUE(mChannel, NS_ERROR_NOT_INITIALIZED);
nsCOMPtr<nsIChannel> chan = mChannel;
chan.forget(aChannel);
return NS_OK;
}
// nsIChannelEventSink
NS_IMETHODIMP

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

@ -17,7 +17,6 @@
#include "nsIStreamListener.h"
#include "nsIURI.h"
#include "nsIViewSourceChannel.h"
#include "nsIWrapperChannel.h"
#include "nsIChildChannel.h"
#include "nsString.h"
@ -29,7 +28,6 @@ class nsViewSourceChannel final : public nsIViewSourceChannel,
public nsIApplicationCacheChannel,
public nsIFormPOSTActionChannel,
public nsIChildChannel,
public nsIWrapperChannel,
public nsIInterfaceRequestor,
public nsIChannelEventSink {
public:
@ -42,7 +40,6 @@ class nsViewSourceChannel final : public nsIViewSourceChannel,
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSIHTTPCHANNEL
NS_DECL_NSICHILDCHANNEL
NS_DECL_NSIWRAPPERCHANNEL
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSICHANNELEVENTSINK
NS_FORWARD_SAFE_NSICACHEINFOCHANNEL(mCacheInfoChannel)
@ -55,7 +52,10 @@ class nsViewSourceChannel final : public nsIViewSourceChannel,
// nsViewSourceChannel methods:
nsViewSourceChannel()
: mIsDocument(false), mOpened(false), mIsSrcdocChannel(false) {}
: mIsDocument(false),
mOpened(false),
mIsSrcdocChannel(false),
mReplaceRequest(true) {}
MOZ_MUST_USE nsresult Init(nsIURI* uri, nsILoadInfo* aLoadInfo);
@ -94,6 +94,7 @@ class nsViewSourceChannel final : public nsIViewSourceChannel,
bool mIsDocument; // keeps track of the LOAD_DOCUMENT_URI flag
bool mOpened;
bool mIsSrcdocChannel;
bool mReplaceRequest;
};
#endif /* nsViewSourceChannel_h___ */