diff --git a/dom/ipc/WindowGlobalChild.cpp b/dom/ipc/WindowGlobalChild.cpp index 3a23514a5cb9..0d6089d4ca81 100644 --- a/dom/ipc/WindowGlobalChild.cpp +++ b/dom/ipc/WindowGlobalChild.cpp @@ -81,8 +81,7 @@ already_AddRefed WindowGlobalChild::Create( if (httpChan && loadInfo->GetExternalContentPolicyType() == nsIContentPolicy::TYPE_DOCUMENT && - NS_SUCCEEDED(httpChan->ComputeCrossOriginOpenerPolicy( - nsILoadInfo::OPENER_POLICY_NULL, &policy))) { + NS_SUCCEEDED(httpChan->GetCrossOriginOpenerPolicy(&policy))) { bc->SetOpenerPolicy(policy); } diff --git a/netwerk/base/nsIProcessSwitchRequestor.idl b/netwerk/base/nsIProcessSwitchRequestor.idl index cde6226c7b47..3656485ee597 100644 --- a/netwerk/base/nsIProcessSwitchRequestor.idl +++ b/netwerk/base/nsIProcessSwitchRequestor.idl @@ -46,7 +46,7 @@ interface nsIProcessSwitchRequestor : nsISupports /** * Returns a cached CrossOriginOpenerPolicy that is computed just before we * determine if there is a policy mismatch. - * @throws NS_ERROR_NOT_AVAILABLE if it has not been computed yet + * @throws NS_ERROR_NOT_AVAILABLE if called before onStartRequest */ - [must_use] readonly attribute nsILoadInfo_CrossOriginOpenerPolicy crossOriginOpenerPolicy; + [must_use, binaryname(CachedCrossOriginOpenerPolicy)] readonly attribute nsILoadInfo_CrossOriginOpenerPolicy crossOriginOpenerPolicy; }; diff --git a/netwerk/ipc/DocumentLoadListener.cpp b/netwerk/ipc/DocumentLoadListener.cpp index 8e7efea02d1d..499eab1d8833 100644 --- a/netwerk/ipc/DocumentLoadListener.cpp +++ b/netwerk/ipc/DocumentLoadListener.cpp @@ -1238,7 +1238,7 @@ DocumentLoadListener::HasCrossOriginOpenerPolicyMismatch(bool* aMismatch) { } NS_IMETHODIMP -DocumentLoadListener::GetCrossOriginOpenerPolicy( +DocumentLoadListener::GetCachedCrossOriginOpenerPolicy( nsILoadInfo::CrossOriginOpenerPolicy* aPolicy) { MOZ_ASSERT(aPolicy); if (!aPolicy) { diff --git a/netwerk/protocol/http/ClassifierDummyChannel.cpp b/netwerk/protocol/http/ClassifierDummyChannel.cpp index 58778644fe51..9ff5e7ff54d4 100644 --- a/netwerk/protocol/http/ClassifierDummyChannel.cpp +++ b/netwerk/protocol/http/ClassifierDummyChannel.cpp @@ -661,5 +661,11 @@ NS_IMETHODIMP ClassifierDummyChannel::ComputeCrossOriginOpenerPolicy( return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP +ClassifierDummyChannel::GetCrossOriginOpenerPolicy( + nsILoadInfo::CrossOriginOpenerPolicy* aPolicy) { + return NS_ERROR_NOT_IMPLEMENTED; +} + } // namespace net } // namespace mozilla diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp index aeadfe1bbecd..160df7aedce9 100644 --- a/netwerk/protocol/http/HttpBaseChannel.cpp +++ b/netwerk/protocol/http/HttpBaseChannel.cpp @@ -158,6 +158,7 @@ HttpBaseChannel::HttpBaseChannel() : mReportCollector(new ConsoleReportCollector()), mHttpHandler(gHttpHandler), mChannelCreationTime(0), + mComputedCrossOriginOpenerPolicy(nsILoadInfo::OPENER_POLICY_NULL), mStartPos(UINT64_MAX), mTransferSize(0), mRequestSize(0), @@ -4585,5 +4586,22 @@ NS_IMETHODIMP HttpBaseChannel::ComputeCrossOriginOpenerPolicy( return NS_OK; } +NS_IMETHODIMP +HttpBaseChannel::GetCrossOriginOpenerPolicy( + nsILoadInfo::CrossOriginOpenerPolicy* aPolicy) { + MOZ_ASSERT(aPolicy); + if (!aPolicy) { + return NS_ERROR_INVALID_ARG; + } + // If this method is called before OnStartRequest (ie. before we call + // ComputeCrossOriginOpenerPolicy) or if we were unable to compute the + // policy we'll throw an error. + if (!mOnStartRequestCalled) { + return NS_ERROR_NOT_AVAILABLE; + } + *aPolicy = mComputedCrossOriginOpenerPolicy; + return NS_OK; +} + } // namespace net } // namespace mozilla diff --git a/netwerk/protocol/http/HttpBaseChannel.h b/netwerk/protocol/http/HttpBaseChannel.h index fb6790c666ab..56841bdd27e5 100644 --- a/netwerk/protocol/http/HttpBaseChannel.h +++ b/netwerk/protocol/http/HttpBaseChannel.h @@ -314,6 +314,8 @@ class HttpBaseChannel : public nsHashPropertyBag, NS_IMETHOD CancelByURLClassifier(nsresult aErrorCode) override; virtual void SetIPv4Disabled(void) override; virtual void SetIPv6Disabled(void) override; + NS_IMETHOD GetCrossOriginOpenerPolicy( + nsILoadInfo::CrossOriginOpenerPolicy* aCrossOriginOpenerPolicy) override; NS_IMETHOD ComputeCrossOriginOpenerPolicy( nsILoadInfo::CrossOriginOpenerPolicy aInitiatorPolicy, nsILoadInfo::CrossOriginOpenerPolicy* aOutPolicy) override; @@ -702,6 +704,10 @@ class HttpBaseChannel : public nsHashPropertyBag, // so that the timing can still be queried from OnStopRequest TimingStruct mTransactionTimings; + // Gets computed during ComputeCrossOriginOpenerPolicyMismatch so we have + // the channel's policy even if we don't know policy initiator. + nsILoadInfo::CrossOriginOpenerPolicy mComputedCrossOriginOpenerPolicy; + uint64_t mStartPos; uint64_t mTransferSize; uint64_t mRequestSize; diff --git a/netwerk/protocol/http/HttpChannelChild.cpp b/netwerk/protocol/http/HttpChannelChild.cpp index d84d5381ed73..cfc5b8bef43d 100644 --- a/netwerk/protocol/http/HttpChannelChild.cpp +++ b/netwerk/protocol/http/HttpChannelChild.cpp @@ -383,7 +383,8 @@ mozilla::ipc::IPCResult HttpChannelChild::RecvOnStartRequest( const bool& aApplyConversion, const bool& aIsResolvedByTRR, const ResourceTimingStructArgs& aTiming, const bool& aAllRedirectsSameOrigin, const Maybe& aMultiPartID, - const bool& aIsLastPartOfMultiPart) { + const bool& aIsLastPartOfMultiPart, + const nsILoadInfo::CrossOriginOpenerPolicy& aOpenerPolicy) { AUTO_PROFILER_LABEL("HttpChannelChild::RecvOnStartRequest", NETWORK); LOG(("HttpChannelChild::RecvOnStartRequest [this=%p]\n", this)); // mFlushedForDiversion and mDivertingToParent should NEVER be set at this @@ -405,7 +406,8 @@ mozilla::ipc::IPCResult HttpChannelChild::RecvOnStartRequest( aCacheExpirationTime, aCachedCharset, aSecurityInfoSerialization, aSelfAddr, aPeerAddr, aCacheKey, aAltDataType, aAltDataLen, aDeliveringAltData, aApplyConversion, aIsResolvedByTRR, aTiming, - aAllRedirectsSameOrigin, aMultiPartID, aIsLastPartOfMultiPart]() { + aAllRedirectsSameOrigin, aMultiPartID, aIsLastPartOfMultiPart, + aOpenerPolicy]() { self->OnStartRequest( aChannelStatus, aResponseHead, aUseResponseHead, aRequestHeaders, aLoadInfoForwarder, aIsFromCache, aIsRacing, aCacheEntryAvailable, @@ -413,7 +415,8 @@ mozilla::ipc::IPCResult HttpChannelChild::RecvOnStartRequest( aCachedCharset, aSecurityInfoSerialization, aSelfAddr, aPeerAddr, aCacheKey, aAltDataType, aAltDataLen, aDeliveringAltData, aApplyConversion, aIsResolvedByTRR, aTiming, - aAllRedirectsSameOrigin, aMultiPartID, aIsLastPartOfMultiPart); + aAllRedirectsSameOrigin, aMultiPartID, aIsLastPartOfMultiPart, + aOpenerPolicy); })); { @@ -467,7 +470,8 @@ void HttpChannelChild::OnStartRequest( const bool& aDeliveringAltData, const bool& aApplyConversion, const bool& aIsResolvedByTRR, const ResourceTimingStructArgs& aTiming, const bool& aAllRedirectsSameOrigin, const Maybe& aMultiPartID, - const bool& aIsLastPartOfMultiPart) { + const bool& aIsLastPartOfMultiPart, + const nsILoadInfo::CrossOriginOpenerPolicy& aOpenerPolicy) { LOG(("HttpChannelChild::OnStartRequest [this=%p]\n", this)); // mFlushedForDiversion and mDivertingToParent should NEVER be set at this @@ -487,6 +491,8 @@ void HttpChannelChild::OnStartRequest( return; } + mComputedCrossOriginOpenerPolicy = aOpenerPolicy; + if (!mCanceled && NS_SUCCEEDED(mStatus)) { mStatus = aChannelStatus; } diff --git a/netwerk/protocol/http/HttpChannelChild.h b/netwerk/protocol/http/HttpChannelChild.h index b5024118462f..83f309165f61 100644 --- a/netwerk/protocol/http/HttpChannelChild.h +++ b/netwerk/protocol/http/HttpChannelChild.h @@ -145,7 +145,8 @@ class HttpChannelChild final : public PHttpChannelChild, const bool& aApplyConversion, const bool& aIsResolvedByTRR, const ResourceTimingStructArgs& aTiming, const bool& aAllRedirectsSameOrigin, const Maybe& aMultiPartID, - const bool& aIsLastPartOfMultiPart) override; + const bool& aIsLastPartOfMultiPart, + const nsILoadInfo::CrossOriginOpenerPolicy& aOpenerPolicy) override; mozilla::ipc::IPCResult RecvOnTransportAndData( const nsresult& aChannelStatus, const nsresult& aTransportStatus, const uint64_t& aOffset, const uint32_t& aCount, @@ -510,7 +511,8 @@ class HttpChannelChild final : public PHttpChannelChild, const bool& deliveringAltData, const bool& aApplyConversion, const bool& aIsResolvedByTRR, const ResourceTimingStructArgs& aTiming, const bool& aAllRedirectsSameOrigin, const Maybe& aMultiPartID, - const bool& aIsLastPartOfMultiPart); + const bool& aIsLastPartOfMultiPart, + const nsILoadInfo::CrossOriginOpenerPolicy& aOpenerPolicy); void MaybeDivertOnData(const nsCString& data, const uint64_t& offset, const uint32_t& count); void OnTransportAndData(const nsresult& channelStatus, const nsresult& status, diff --git a/netwerk/protocol/http/HttpChannelParent.cpp b/netwerk/protocol/http/HttpChannelParent.cpp index 4189f68701d5..fbbb63206383 100644 --- a/netwerk/protocol/http/HttpChannelParent.cpp +++ b/netwerk/protocol/http/HttpChannelParent.cpp @@ -1522,6 +1522,10 @@ HttpChannelParent::OnStartRequest(nsIRequest* aRequest) { bool allRedirectsSameOrigin = false; chan->GetAllRedirectsSameOrigin(&allRedirectsSameOrigin); + nsILoadInfo::CrossOriginOpenerPolicy openerPolicy = + nsILoadInfo::OPENER_POLICY_NULL; + chan->GetCrossOriginOpenerPolicy(&openerPolicy); + rv = NS_OK; if (mIPCClosed || !SendOnStartRequest( @@ -1533,7 +1537,7 @@ HttpChannelParent::OnStartRequest(nsIRequest* aRequest) { chan->GetPeerAddr(), redirectCount, cacheKey, altDataType, altDataLen, deliveringAltData, applyConversion, isResolvedByTRR, GetTimingAttributes(mChannel), allRedirectsSameOrigin, multiPartID, - isLastPartOfMultiPart)) { + isLastPartOfMultiPart, openerPolicy)) { rv = NS_ERROR_UNEXPECTED; } requestHead->Exit(); diff --git a/netwerk/protocol/http/PHttpChannel.ipdl b/netwerk/protocol/http/PHttpChannel.ipdl index e645407b3b34..cf6de1800235 100644 --- a/netwerk/protocol/http/PHttpChannel.ipdl +++ b/netwerk/protocol/http/PHttpChannel.ipdl @@ -21,6 +21,7 @@ using class nsHttpHeaderArray from "nsHttpHeaderArray.h"; using mozilla::net::NetAddr from "mozilla/net/DNS.h"; using refcounted class nsIReferrerInfo from "mozilla/dom/ReferrerInfoUtils.h"; using nsIHttpChannel::FlashPluginState from "mozilla/net/NeckoMessageUtils.h"; +using nsILoadInfo::CrossOriginOpenerPolicy from "nsILoadInfo.h"; namespace mozilla { namespace net { @@ -130,7 +131,8 @@ child: ResourceTimingStructArgs timing, bool allRedirectsSameOrigin, uint32_t? multiPartId, - bool isLastPartOfMultiPart); + bool isLastPartOfMultiPart, + CrossOriginOpenerPolicy policy); // Combines a single OnDataAvailable and its associated OnProgress & // OnStatus calls into one IPDL message diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index ecae253ad360..b43a60886d85 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -304,7 +304,6 @@ nsHttpChannel::nsHttpChannel() mOfflineCacheLastModifiedTime(0), mSuspendTotalTime(0), mRedirectType(0), - mComputedCrossOriginOpenerPolicy(nsILoadInfo::OPENER_POLICY_NULL), mCacheOpenWithPriority(false), mCacheQueueSizeWhenOpen(0), mCachedContentIsValid(false), @@ -7398,20 +7397,9 @@ nsHttpChannel::HasCrossOriginOpenerPolicyMismatch(bool* aMismatch) { } NS_IMETHODIMP -nsHttpChannel::GetCrossOriginOpenerPolicy( +nsHttpChannel::GetCachedCrossOriginOpenerPolicy( nsILoadInfo::CrossOriginOpenerPolicy* aPolicy) { - MOZ_ASSERT(aPolicy); - if (!aPolicy) { - return NS_ERROR_INVALID_ARG; - } - // If this method is called before OnStartRequest (ie. before we call - // ComputeCrossOriginOpenerPolicy) or if we were unable to compute the - // policy we'll throw an error. - if (!mOnStartRequestCalled) { - return NS_ERROR_NOT_AVAILABLE; - } - *aPolicy = mComputedCrossOriginOpenerPolicy; - return NS_OK; + return HttpBaseChannel::GetCrossOriginOpenerPolicy(aPolicy); } // See https://gist.github.com/annevk/6f2dd8c79c77123f39797f6bdac43f3e diff --git a/netwerk/protocol/http/nsHttpChannel.h b/netwerk/protocol/http/nsHttpChannel.h index 8c3b11e03112..0f2be1bda2e2 100644 --- a/netwerk/protocol/http/nsHttpChannel.h +++ b/netwerk/protocol/http/nsHttpChannel.h @@ -664,10 +664,6 @@ class nsHttpChannel final : public HttpBaseChannel, static const uint32_t WAIT_FOR_CACHE_ENTRY = 1; static const uint32_t WAIT_FOR_OFFLINE_CACHE_ENTRY = 2; - // Gets computed during ComputeCrossOriginOpenerPolicyMismatch so we have - // the channel's policy even if we don't know policy initiator. - nsILoadInfo::CrossOriginOpenerPolicy mComputedCrossOriginOpenerPolicy; - bool mCacheOpenWithPriority; uint32_t mCacheQueueSizeWhenOpen; diff --git a/netwerk/protocol/http/nsIHttpChannelInternal.idl b/netwerk/protocol/http/nsIHttpChannelInternal.idl index 329bb9932f4c..bfa09430f087 100644 --- a/netwerk/protocol/http/nsIHttpChannelInternal.idl +++ b/netwerk/protocol/http/nsIHttpChannelInternal.idl @@ -386,7 +386,15 @@ interface nsIHttpChannelInternal : nsISupports void setIPv6Disabled(); /** - * Get the Cross-Origin-Opener-Policy of the top-level document channel. + * Returns a cached CrossOriginOpenerPolicy that is computed just before we + * determine if there is a policy mismatch. + * @throws NS_ERROR_NOT_AVAILABLE if it has not been computed yet + */ + readonly attribute nsILoadInfo_CrossOriginOpenerPolicy crossOriginOpenerPolicy; + + /** + * Called during onStartRequest to compute the cross-origin-opener-policy + * for a given channel. */ [noscript] nsILoadInfo_CrossOriginOpenerPolicy computeCrossOriginOpenerPolicy(