From ea53fed3b6ef20a6c2aabe5c513d9b0290fc7d9c Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Wed, 26 Feb 2020 20:58:19 +0000 Subject: [PATCH] Bug 1616716 - Implement nsIRemoteWindowContext on ParentChannelListener. r=mayhemer Differential Revision: https://phabricator.services.mozilla.com/D63427 --HG-- extra : moz-landing-system : lando --- .../protocol/http/ParentChannelListener.cpp | 41 +++++++++++++++---- netwerk/protocol/http/ParentChannelListener.h | 8 +++- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/netwerk/protocol/http/ParentChannelListener.cpp b/netwerk/protocol/http/ParentChannelListener.cpp index c1d26fcac81f..abf9d6a88c53 100644 --- a/netwerk/protocol/http/ParentChannelListener.cpp +++ b/netwerk/protocol/http/ParentChannelListener.cpp @@ -25,6 +25,8 @@ #include "Element.h" #include "nsILoginManagerAuthPrompter.h" #include "mozilla/dom/CanonicalBrowsingContext.h" +#include "mozilla/dom/LoadURIOptionsBinding.h" +#include "nsIWebNavigation.h" using mozilla::Unused; using mozilla::dom::ServiceWorkerInterceptController; @@ -49,6 +51,8 @@ ParentChannelListener::ParentChannelListener(nsIStreamListener* aListener, } if (mBrowserParent) { mBrowsingContext = mBrowserParent->GetBrowsingContext(); + nsCOMPtr loadContext = mBrowserParent->GetLoadContext(); + mUsePrivateBrowsing = loadContext && loadContext->UsePrivateBrowsing(); } } @@ -69,6 +73,7 @@ NS_INTERFACE_MAP_BEGIN(ParentChannelListener) NS_INTERFACE_MAP_ENTRY(nsIMultiPartChannelListener) NS_INTERFACE_MAP_ENTRY(nsINetworkInterceptController) NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIAuthPromptProvider, mBrowsingContext) + NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIRemoteWindowContext, mBrowsingContext) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIInterfaceRequestor) NS_INTERFACE_MAP_ENTRY_CONCRETE(ParentChannelListener) NS_INTERFACE_MAP_END @@ -154,7 +159,8 @@ ParentChannelListener::OnAfterLastPart(nsresult aStatus) { NS_IMETHODIMP ParentChannelListener::GetInterface(const nsIID& aIID, void** result) { - if (aIID.Equals(NS_GET_IID(nsINetworkInterceptController))) { + if (aIID.Equals(NS_GET_IID(nsINetworkInterceptController)) || + aIID.Equals(NS_GET_IID(nsIRemoteWindowContext))) { return QueryInterface(aIID, result); } @@ -189,13 +195,6 @@ ParentChannelListener::GetInterface(const nsIID& aIID, void** result) { return GetAuthPrompt(nsIAuthPromptProvider::PROMPT_NORMAL, aIID, result); } - if (aIID.Equals(NS_GET_IID(nsIRemoteWindowContext)) && mBrowserParent) { - nsCOMPtr ctx( - new dom::RemoteWindowContext(mBrowserParent)); - ctx.forget(result); - return NS_OK; - } - nsCOMPtr ir; if (mNextListener && NS_SUCCEEDED(CallQueryInterface(mNextListener.get(), getter_AddRefs(ir)))) { @@ -417,5 +416,31 @@ ParentChannelListener::GetAuthPrompt(uint32_t aPromptReason, const nsIID& iid, return NS_OK; } +//----------------------------------------------------------------------------- +// ParentChannelListener::nsIRemoteWindowContext +// + +NS_IMETHODIMP +ParentChannelListener::OpenURI(nsIURI* aURI) { + nsCString spec; + aURI->GetSpec(spec); + + dom::LoadURIOptions loadURIOptions; + loadURIOptions.mTriggeringPrincipal = nsContentUtils::GetSystemPrincipal(); + loadURIOptions.mLoadFlags = + nsIWebNavigation::LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP | + nsIWebNavigation::LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL; + + ErrorResult rv; + mBrowsingContext->LoadURI(NS_ConvertUTF8toUTF16(spec), loadURIOptions, rv); + return rv.StealNSResult(); +} + +NS_IMETHODIMP +ParentChannelListener::GetUsePrivateBrowsing(bool* aUsePrivateBrowsing) { + *aUsePrivateBrowsing = mUsePrivateBrowsing; + return NS_OK; +} + } // namespace net } // namespace mozilla diff --git a/netwerk/protocol/http/ParentChannelListener.h b/netwerk/protocol/http/ParentChannelListener.h index b70545fa1a71..b078a6f9c548 100644 --- a/netwerk/protocol/http/ParentChannelListener.h +++ b/netwerk/protocol/http/ParentChannelListener.h @@ -13,6 +13,7 @@ #include "nsINetworkInterceptController.h" #include "nsIStreamListener.h" #include "nsIMultiPartChannel.h" +#include "nsIRemoteWindowContext.h" #include "mozilla/dom/BrowserParent.h" #include "mozilla/dom/CanonicalBrowsingContext.h" @@ -34,7 +35,8 @@ class ParentChannelListener final : public nsIInterfaceRequestor, public nsIStreamListener, public nsIMultiPartChannelListener, public nsINetworkInterceptController, - private nsIAuthPromptProvider { + private nsIAuthPromptProvider, + private nsIRemoteWindowContext { public: NS_DECL_ISUPPORTS NS_DECL_NSIINTERFACEREQUESTOR @@ -43,6 +45,7 @@ class ParentChannelListener final : public nsIInterfaceRequestor, NS_DECL_NSIMULTIPARTCHANNELLISTENER NS_DECL_NSINETWORKINTERCEPTCONTROLLER NS_DECL_NSIAUTHPROMPTPROVIDER + NS_DECL_NSIREMOTEWINDOWCONTEXT NS_DECLARE_STATIC_IID_ACCESSOR(PARENT_CHANNEL_LISTENER) @@ -99,6 +102,9 @@ class ParentChannelListener final : public nsIInterfaceRequestor, // True if we received OnStartRequest for a nsIMultiPartChannel, and are // expected AllPartsStopped to be called when complete. bool mIsMultiPart = false; + + // True if the nsILoadContext for this channel has private browsing enabled. + bool mUsePrivateBrowsing = false; }; NS_DEFINE_STATIC_IID_ACCESSOR(ParentChannelListener, PARENT_CHANNEL_LISTENER)