Bug 1598523 - Implement nsIChildChannel on nsViewSourceChannel forwarding to the inner channel. r=mayhemer

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Matt Woodrow 2020-01-08 01:00:37 +00:00
parent a59b688778
commit ff5ffc1ea3
2 changed files with 51 additions and 1 deletions

View File

@ -38,6 +38,7 @@ NS_INTERFACE_MAP_BEGIN(nsViewSourceChannel)
mApplicationCacheChannel)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIUploadChannel, mUploadChannel)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIFormPOSTActionChannel, mPostChannel)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIChildChannel, mChildChannel)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIRequest, nsIViewSourceChannel)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIChannel, nsIViewSourceChannel)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIViewSourceChannel)
@ -81,6 +82,7 @@ nsresult nsViewSourceChannel::Init(nsIURI* uri, nsILoadInfo* aLoadInfo) {
mApplicationCacheChannel = do_QueryInterface(mChannel);
mUploadChannel = do_QueryInterface(mChannel);
mPostChannel = do_QueryInterface(mChannel);
mChildChannel = do_QueryInterface(mChannel);
return NS_OK;
}
@ -113,6 +115,7 @@ nsresult nsViewSourceChannel::InitSrcdoc(nsIURI* aURI, nsIURI* aBaseURI,
mCacheInfoChannel = do_QueryInterface(mChannel);
mApplicationCacheChannel = do_QueryInterface(mChannel);
mUploadChannel = do_QueryInterface(mChannel);
mChildChannel = do_QueryInterface(mChannel);
rv = UpdateLoadInfoResultPrincipalURI();
NS_ENSURE_SUCCESS(rv, rv);
@ -1021,3 +1024,46 @@ void nsViewSourceChannel::SetHasNonEmptySandboxingFlag(
aHasNonEmptySandboxingFlag);
}
}
// nsIChildChannel methods
NS_IMETHODIMP
nsViewSourceChannel::ConnectParent(uint32_t aRegistarId) {
NS_ENSURE_TRUE(mChildChannel, NS_ERROR_NULL_POINTER);
return mChildChannel->ConnectParent(aRegistarId);
}
NS_IMETHODIMP
nsViewSourceChannel::CompleteRedirectSetup(nsIStreamListener* aListener,
nsISupports* aContext) {
NS_ENSURE_TRUE(mChildChannel, NS_ERROR_NULL_POINTER);
mListener = aListener;
/*
* We want to add ourselves to the loadgroup before opening
* mChannel, since we want to make sure we're in the loadgroup
* when mChannel finishes and fires OnStopRequest()
*/
nsCOMPtr<nsILoadGroup> loadGroup;
mChannel->GetLoadGroup(getter_AddRefs(loadGroup));
if (loadGroup) {
loadGroup->AddRequest(static_cast<nsIViewSourceChannel*>(this), nullptr);
}
nsresult rv = NS_OK;
rv = mChildChannel->CompleteRedirectSetup(this, aContext);
if (NS_FAILED(rv) && loadGroup) {
loadGroup->RemoveRequest(static_cast<nsIViewSourceChannel*>(this), nullptr,
rv);
}
if (NS_SUCCEEDED(rv)) {
mOpened = true;
}
return rv;
}

View File

@ -17,6 +17,7 @@
#include "nsIStreamListener.h"
#include "nsIURI.h"
#include "nsIViewSourceChannel.h"
#include "nsIChildChannel.h"
#include "nsString.h"
class nsViewSourceChannel final : public nsIViewSourceChannel,
@ -25,7 +26,8 @@ class nsViewSourceChannel final : public nsIViewSourceChannel,
public nsIHttpChannelInternal,
public nsICachingChannel,
public nsIApplicationCacheChannel,
public nsIFormPOSTActionChannel {
public nsIFormPOSTActionChannel,
public nsIChildChannel {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUEST
@ -35,6 +37,7 @@ class nsViewSourceChannel final : public nsIViewSourceChannel,
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSIHTTPCHANNEL
NS_DECL_NSICHILDCHANNEL
NS_FORWARD_SAFE_NSICACHEINFOCHANNEL(mCacheInfoChannel)
NS_FORWARD_SAFE_NSICACHINGCHANNEL(mCachingChannel)
NS_FORWARD_SAFE_NSIAPPLICATIONCACHECHANNEL(mApplicationCacheChannel)
@ -75,6 +78,7 @@ class nsViewSourceChannel final : public nsIViewSourceChannel,
nsCOMPtr<nsIApplicationCacheChannel> mApplicationCacheChannel;
nsCOMPtr<nsIUploadChannel> mUploadChannel;
nsCOMPtr<nsIFormPOSTActionChannel> mPostChannel;
nsCOMPtr<nsIChildChannel> mChildChannel;
nsCOMPtr<nsIStreamListener> mListener;
nsCOMPtr<nsIURI> mOriginalURI;
nsCOMPtr<nsIURI> mBaseURI;