diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 6f11051fc4ee..ad589276755a 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -11162,9 +11162,9 @@ nsresult nsDocShell::AddToSessionHistory( // For now keep storing just the principal in the SHEntry. if (!principalToInherit) { if (loadInfo->GetLoadingSandboxed()) { - if (loadInfo->GetLoadingPrincipal()) { + if (loadInfo->LoadingPrincipal()) { principalToInherit = NullPrincipal::CreateWithInheritedAttributes( - loadInfo->GetLoadingPrincipal()); + loadInfo->LoadingPrincipal()); } else { // get the OriginAttributes OriginAttributes attrs; diff --git a/dom/base/ThirdPartyUtil.cpp b/dom/base/ThirdPartyUtil.cpp index c6a88dd92630..be469cc959be 100644 --- a/dom/base/ThirdPartyUtil.cpp +++ b/dom/base/ThirdPartyUtil.cpp @@ -326,8 +326,8 @@ ThirdPartyUtil::IsThirdPartyChannel(nsIChannel* aChannel, nsIURI* aURI, // Check if the channel itself is third-party to its own requestor. // Unforunately, we have to go through the loading principal. - rv = loadInfo->GetLoadingPrincipal()->IsThirdPartyURI(channelURI, - &parentIsThird); + rv = loadInfo->LoadingPrincipal()->IsThirdPartyURI(channelURI, + &parentIsThird); if (NS_FAILED(rv)) { return rv; } diff --git a/dom/base/nsContentPolicyUtils.h b/dom/base/nsContentPolicyUtils.h index a3c34e8b2ec5..74a7e54800cf 100644 --- a/dom/base/nsContentPolicyUtils.h +++ b/dom/base/nsContentPolicyUtils.h @@ -172,37 +172,40 @@ inline const char* NS_CP_ContentTypeName(uint32_t contentType) { * purpose */ #define CHECK_PRINCIPAL_CSP_AND_DATA(action) \ PR_BEGIN_MACRO \ - if (loadingPrincipal && loadingPrincipal->IsSystemPrincipal()) { \ + if (loadingPrincipal) { \ /* We exempt most loads into any document with the system principal \ - * from content policy (except CSP) checks, mostly as an optimization. \ + * from content policy (escept CSP) checks, mostly as an optimization. \ * Which means that we need to apply this check to the loading principal, \ * not the principal that triggered the load. */ \ - /* Check CSP for System Privileged pages */ \ - CSPService::ConsultCSP(contentLocation, loadInfo, mimeType, decision); \ - if (NS_CP_REJECTED(*decision)) { \ - return NS_OK; \ - } \ - if (contentType != nsIContentPolicy::TYPE_DOCUMENT) { \ - *decision = nsIContentPolicy::ACCEPT; \ - nsCOMPtr n = do_QueryInterface(context); \ - if (!n) { \ - nsCOMPtr win = do_QueryInterface(context); \ - n = win ? win->GetExtantDoc() : nullptr; \ + bool isSystem = loadingPrincipal->IsSystemPrincipal(); \ + if (isSystem) { \ + /* Check CSP for System Privileged pages */ \ + CSPService::ConsultCSP(contentLocation, loadInfo, mimeType, decision); \ + if (NS_CP_REJECTED(*decision)) { \ + return NS_OK; \ } \ - if (n) { \ - mozilla::dom::Document* d = n->OwnerDoc(); \ - if (d->IsLoadedAsData() || d->IsBeingUsedAsImage() || \ - d->IsResourceDoc()) { \ - nsCOMPtr dataPolicy = \ - do_GetService("@mozilla.org/data-document-content-policy;1"); \ - if (dataPolicy) { \ - dataPolicy->action(contentLocation, loadInfo, mimeType, \ - decision); \ + if (contentType != nsIContentPolicy::TYPE_DOCUMENT) { \ + *decision = nsIContentPolicy::ACCEPT; \ + nsCOMPtr n = do_QueryInterface(context); \ + if (!n) { \ + nsCOMPtr win = do_QueryInterface(context); \ + n = win ? win->GetExtantDoc() : nullptr; \ + } \ + if (n) { \ + mozilla::dom::Document* d = n->OwnerDoc(); \ + if (d->IsLoadedAsData() || d->IsBeingUsedAsImage() || \ + d->IsResourceDoc()) { \ + nsCOMPtr dataPolicy = \ + do_GetService("@mozilla.org/data-document-content-policy;1"); \ + if (dataPolicy) { \ + dataPolicy->action(contentLocation, loadInfo, mimeType, \ + decision); \ + } \ } \ } \ } \ + return NS_OK; \ } \ - return NS_OK; \ } \ PR_END_MACRO @@ -219,7 +222,7 @@ inline const char* NS_CP_ContentTypeName(uint32_t contentType) { inline nsresult NS_CheckContentLoadPolicy( nsIURI* contentLocation, nsILoadInfo* loadInfo, const nsACString& mimeType, int16_t* decision, nsIContentPolicy* policyService = nullptr) { - nsIPrincipal* loadingPrincipal = loadInfo->GetLoadingPrincipal(); + nsIPrincipal* loadingPrincipal = loadInfo->LoadingPrincipal(); nsCOMPtr context = loadInfo->GetLoadingContext(); nsContentPolicyType contentType = loadInfo->InternalContentPolicyType(); CHECK_PRINCIPAL_CSP_AND_DATA(ShouldLoad); @@ -235,7 +238,7 @@ inline nsresult NS_CheckContentLoadPolicy( inline nsresult NS_CheckContentProcessPolicy( nsIURI* contentLocation, nsILoadInfo* loadInfo, const nsACString& mimeType, int16_t* decision, nsIContentPolicy* policyService = nullptr) { - nsIPrincipal* loadingPrincipal = loadInfo->GetLoadingPrincipal(); + nsIPrincipal* loadingPrincipal = loadInfo->LoadingPrincipal(); nsCOMPtr context = loadInfo->GetLoadingContext(); nsContentPolicyType contentType = loadInfo->InternalContentPolicyType(); CHECK_PRINCIPAL_CSP_AND_DATA(ShouldProcess); diff --git a/dom/base/nsNodeInfoManager.cpp b/dom/base/nsNodeInfoManager.cpp index b0534b661a23..f77b8d366537 100644 --- a/dom/base/nsNodeInfoManager.cpp +++ b/dom/base/nsNodeInfoManager.cpp @@ -384,7 +384,7 @@ bool nsNodeInfoManager::InternalSVGEnabled() { nsIContentPolicy::TYPE_IMAGE || loadInfo->GetExternalContentPolicyType() == nsIContentPolicy::TYPE_OTHER) && - (IsSystemOrAddonPrincipal(loadInfo->GetLoadingPrincipal()) || + (IsSystemOrAddonPrincipal(loadInfo->LoadingPrincipal()) || IsSystemOrAddonPrincipal(loadInfo->TriggeringPrincipal())))); mSVGEnabled = Some(conclusion); return conclusion; diff --git a/dom/file/uri/BlobURLProtocolHandler.cpp b/dom/file/uri/BlobURLProtocolHandler.cpp index 359e9188d246..e51d875c6f9e 100644 --- a/dom/file/uri/BlobURLProtocolHandler.cpp +++ b/dom/file/uri/BlobURLProtocolHandler.cpp @@ -811,8 +811,8 @@ BlobURLProtocolHandler::NewChannel(nsIURI* aURI, nsILoadInfo* aLoadInfo, // principal and which is never mutated to have a non-zero mPrivateBrowsingId // or container. if (aLoadInfo && - (!aLoadInfo->GetLoadingPrincipal() || - !aLoadInfo->GetLoadingPrincipal()->IsSystemPrincipal()) && + (!aLoadInfo->LoadingPrincipal() || + !aLoadInfo->LoadingPrincipal()->IsSystemPrincipal()) && !ChromeUtils::IsOriginAttributesEqualIgnoringFPD( aLoadInfo->GetOriginAttributes(), BasePrincipal::Cast(info->mPrincipal)->OriginAttributesRef())) { diff --git a/dom/performance/PerformanceTiming.cpp b/dom/performance/PerformanceTiming.cpp index 374be9c6761c..30694e769f87 100644 --- a/dom/performance/PerformanceTiming.cpp +++ b/dom/performance/PerformanceTiming.cpp @@ -276,7 +276,7 @@ bool PerformanceTimingData::CheckAllowedOrigin(nsIHttpChannel* aResourceChannel, return true; } - nsCOMPtr principal = loadInfo->GetLoadingPrincipal(); + nsCOMPtr principal = loadInfo->LoadingPrincipal(); // Check if the resource is either same origin as the page that started // the load, or if the response contains the proper Timing-Allow-Origin diff --git a/dom/security/DOMSecurityMonitor.cpp b/dom/security/DOMSecurityMonitor.cpp index d3d47d939919..632d8f83a0ce 100644 --- a/dom/security/DOMSecurityMonitor.cpp +++ b/dom/security/DOMSecurityMonitor.cpp @@ -110,7 +110,7 @@ void DOMSecurityMonitor::AuditParsingOfHTMLXMLFragments( /* static */ void DOMSecurityMonitor::AuditUseOfJavaScriptURI(nsIChannel* aChannel) { nsCOMPtr loadInfo = aChannel->LoadInfo(); - nsCOMPtr loadingPrincipal = loadInfo->GetLoadingPrincipal(); + nsCOMPtr loadingPrincipal = loadInfo->LoadingPrincipal(); // We only ever have no loadingPrincipal in case of a new top-level load. // The purpose of this assertion is to make sure we do not allow loading diff --git a/dom/security/nsContentSecurityManager.cpp b/dom/security/nsContentSecurityManager.cpp index 5a0754eed4c6..c6fb07d6b7b5 100644 --- a/dom/security/nsContentSecurityManager.cpp +++ b/dom/security/nsContentSecurityManager.cpp @@ -711,7 +711,7 @@ static void DebugDoContentSecurityCheck(nsIChannel* aChannel, // Log Principals nsCOMPtr requestPrincipal = aLoadInfo->TriggeringPrincipal(); - LogPrincipal(aLoadInfo->GetLoadingPrincipal(), + LogPrincipal(aLoadInfo->LoadingPrincipal(), NS_LITERAL_STRING("loadingPrincipal")); LogPrincipal(requestPrincipal, NS_LITERAL_STRING("triggeringPrincipal")); LogPrincipal(aLoadInfo->PrincipalToInherit(), @@ -769,8 +769,8 @@ nsresult nsContentSecurityManager::CheckAllowLoadInSystemPrivilegedContext( // nothing to do here if we are not loading a resource into a // system prvileged context. - if (!loadInfo->GetLoadingPrincipal() || - !loadInfo->GetLoadingPrincipal()->IsSystemPrincipal()) { + if (!loadInfo->LoadingPrincipal() || + !loadInfo->LoadingPrincipal()->IsSystemPrincipal()) { return NS_OK; } @@ -1033,7 +1033,7 @@ nsresult nsContentSecurityManager::CheckChannel(nsIChannel* aChannel) { // We shouldn't have the SEC_COOKIES_SAME_ORIGIN flag for top level loads MOZ_ASSERT(loadInfo->GetExternalContentPolicyType() != nsIContentPolicy::TYPE_DOCUMENT); - nsIPrincipal* loadingPrincipal = loadInfo->GetLoadingPrincipal(); + nsIPrincipal* loadingPrincipal = loadInfo->LoadingPrincipal(); // It doesn't matter what we pass for the second, data-inherits, argument. // Any protocol which inherits won't pay attention to cookies anyway. diff --git a/dom/security/nsMixedContentBlocker.cpp b/dom/security/nsMixedContentBlocker.cpp index a2f578e55731..ab757b193d49 100644 --- a/dom/security/nsMixedContentBlocker.cpp +++ b/dom/security/nsMixedContentBlocker.cpp @@ -280,7 +280,7 @@ nsMixedContentBlocker::AsyncOnChannelRedirect( // Get the loading Info from the old channel nsCOMPtr loadInfo = aOldChannel->LoadInfo(); - nsCOMPtr requestingPrincipal = loadInfo->GetLoadingPrincipal(); + nsCOMPtr requestingPrincipal = loadInfo->LoadingPrincipal(); // Since we are calling shouldLoad() directly on redirects, we don't go // through the code in nsContentPolicyUtils::NS_CheckContentLoadPolicy(). @@ -326,7 +326,7 @@ nsMixedContentBlocker::ShouldLoad(nsIURI* aContentLocation, nsCOMPtr requestingContext = aLoadInfo->GetLoadingContext(); nsCOMPtr requestPrincipal = aLoadInfo->TriggeringPrincipal(); nsCOMPtr requestingLocation; - nsCOMPtr loadingPrincipal = aLoadInfo->GetLoadingPrincipal(); + nsCOMPtr loadingPrincipal = aLoadInfo->LoadingPrincipal(); // We need to get a Requesting Location if possible // so we're casting to BasePrincipal to acess GetURI diff --git a/image/decoders/icon/mac/nsIconChannelCocoa.mm b/image/decoders/icon/mac/nsIconChannelCocoa.mm index 28d4559f73ee..c0e21df5a1fe 100644 --- a/image/decoders/icon/mac/nsIconChannelCocoa.mm +++ b/image/decoders/icon/mac/nsIconChannelCocoa.mm @@ -191,8 +191,7 @@ nsIconChannel::AsyncOpen(nsIStreamListener* aListener) { MOZ_ASSERT( mLoadInfo->GetSecurityMode() == 0 || mLoadInfo->GetInitialSecurityCheckDone() || (mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL && - mLoadInfo->GetLoadingPrincipal() && - mLoadInfo->GetLoadingPrincipal()->IsSystemPrincipal()), + mLoadInfo->LoadingPrincipal() && mLoadInfo->LoadingPrincipal()->IsSystemPrincipal()), "security flags in loadInfo but doContentSecurityCheck() not called"); nsCOMPtr inStream; diff --git a/image/decoders/icon/win/nsIconChannel.cpp b/image/decoders/icon/win/nsIconChannel.cpp index 2eef5fa7e1b5..a79d82e685f2 100644 --- a/image/decoders/icon/win/nsIconChannel.cpp +++ b/image/decoders/icon/win/nsIconChannel.cpp @@ -366,8 +366,8 @@ nsIconChannel::AsyncOpen(nsIStreamListener* aListener) { mLoadInfo->GetInitialSecurityCheckDone() || (mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL && - mLoadInfo->GetLoadingPrincipal() && - mLoadInfo->GetLoadingPrincipal()->IsSystemPrincipal()), + mLoadInfo->LoadingPrincipal() && + mLoadInfo->LoadingPrincipal()->IsSystemPrincipal()), "security flags in loadInfo but doContentSecurityCheck() not called"); nsCOMPtr inStream; diff --git a/ipc/glue/BackgroundUtils.cpp b/ipc/glue/BackgroundUtils.cpp index f903037502ed..1f34eab1c0e0 100644 --- a/ipc/glue/BackgroundUtils.cpp +++ b/ipc/glue/BackgroundUtils.cpp @@ -411,10 +411,12 @@ nsresult LoadInfoToLoadInfoArgs(nsILoadInfo* aLoadInfo, Maybe* aOptionalLoadInfoArgs) { nsresult rv = NS_OK; Maybe loadingPrincipalInfo; - if (nsIPrincipal* loadingPrin = aLoadInfo->GetLoadingPrincipal()) { - loadingPrincipalInfo.emplace(); - rv = PrincipalToPrincipalInfo(loadingPrin, loadingPrincipalInfo.ptr()); + if (aLoadInfo->LoadingPrincipal()) { + PrincipalInfo loadingPrincipalInfoTemp; + rv = PrincipalToPrincipalInfo(aLoadInfo->LoadingPrincipal(), + &loadingPrincipalInfoTemp); NS_ENSURE_SUCCESS(rv, rv); + loadingPrincipalInfo = Some(loadingPrincipalInfoTemp); } PrincipalInfo triggeringPrincipalInfo; @@ -423,33 +425,40 @@ nsresult LoadInfoToLoadInfoArgs(nsILoadInfo* aLoadInfo, NS_ENSURE_SUCCESS(rv, rv); Maybe principalToInheritInfo; - if (nsIPrincipal* principalToInherit = aLoadInfo->PrincipalToInherit()) { - principalToInheritInfo.emplace(); - rv = PrincipalToPrincipalInfo(principalToInherit, - principalToInheritInfo.ptr()); + if (aLoadInfo->PrincipalToInherit()) { + PrincipalInfo principalToInheritInfoTemp; + rv = PrincipalToPrincipalInfo(aLoadInfo->PrincipalToInherit(), + &principalToInheritInfoTemp); NS_ENSURE_SUCCESS(rv, rv); + principalToInheritInfo = Some(principalToInheritInfoTemp); } Maybe sandboxedLoadingPrincipalInfo; if (aLoadInfo->GetLoadingSandboxed()) { - sandboxedLoadingPrincipalInfo.emplace(); + PrincipalInfo sandboxedLoadingPrincipalInfoTemp; rv = PrincipalToPrincipalInfo(aLoadInfo->GetSandboxedLoadingPrincipal(), - sandboxedLoadingPrincipalInfo.ptr()); + &sandboxedLoadingPrincipalInfoTemp); NS_ENSURE_SUCCESS(rv, rv); + sandboxedLoadingPrincipalInfo = Some(sandboxedLoadingPrincipalInfoTemp); } Maybe topLevelPrincipalInfo; - if (nsIPrincipal* topLevenPrin = aLoadInfo->GetTopLevelPrincipal()) { - topLevelPrincipalInfo.emplace(); - rv = PrincipalToPrincipalInfo(topLevenPrin, topLevelPrincipalInfo.ptr()); + if (aLoadInfo->GetTopLevelPrincipal()) { + PrincipalInfo topLevelPrincipalInfoTemp; + rv = PrincipalToPrincipalInfo(aLoadInfo->GetTopLevelPrincipal(), + &topLevelPrincipalInfoTemp); NS_ENSURE_SUCCESS(rv, rv); + topLevelPrincipalInfo = Some(topLevelPrincipalInfoTemp); } Maybe topLevelStorageAreaPrincipalInfo; - if (nsIPrincipal* prin = aLoadInfo->GetTopLevelStorageAreaPrincipal()) { - topLevelStorageAreaPrincipalInfo.emplace(); - rv = PrincipalToPrincipalInfo(prin, topLevelStorageAreaPrincipalInfo.ptr()); + if (aLoadInfo->GetTopLevelStorageAreaPrincipal()) { + PrincipalInfo topLevelStorageAreaPrincipalInfoTemp; + rv = PrincipalToPrincipalInfo(aLoadInfo->GetTopLevelStorageAreaPrincipal(), + &topLevelStorageAreaPrincipalInfoTemp); NS_ENSURE_SUCCESS(rv, rv); + topLevelStorageAreaPrincipalInfo = + Some(topLevelStorageAreaPrincipalInfoTemp); } Maybe optionalResultPrincipalURI; diff --git a/media/mtransport/ipc/WebrtcTCPSocket.cpp b/media/mtransport/ipc/WebrtcTCPSocket.cpp index 8c24e92760dd..14197972c103 100644 --- a/media/mtransport/ipc/WebrtcTCPSocket.cpp +++ b/media/mtransport/ipc/WebrtcTCPSocket.cpp @@ -378,7 +378,7 @@ nsresult WebrtcTCPSocket::OpenWithHttpProxy() { rv = ioService->NewChannelFromURIWithProxyFlags( mURI, nullptr, // Proxy flags are overridden by SetConnectOnly() - 0, loadInfo->LoadingNode(), loadInfo->GetLoadingPrincipal(), + 0, loadInfo->LoadingNode(), loadInfo->LoadingPrincipal(), loadInfo->TriggeringPrincipal(), nsILoadInfo::SEC_DONT_FOLLOW_REDIRECTS | nsILoadInfo::SEC_COOKIES_OMIT | // We need this flag to allow loads from any origin since this channel diff --git a/modules/libjar/nsJARChannel.cpp b/modules/libjar/nsJARChannel.cpp index 972159f5a9b7..e800352ea54a 100644 --- a/modules/libjar/nsJARChannel.cpp +++ b/modules/libjar/nsJARChannel.cpp @@ -874,8 +874,8 @@ nsJARChannel::AsyncOpen(nsIStreamListener* aListener) { mLoadInfo->GetInitialSecurityCheckDone() || (mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL && - mLoadInfo->GetLoadingPrincipal() && - mLoadInfo->GetLoadingPrincipal()->IsSystemPrincipal()), + mLoadInfo->LoadingPrincipal() && + mLoadInfo->LoadingPrincipal()->IsSystemPrincipal()), "security flags in loadInfo but doContentSecurityCheck() not called"); NS_ENSURE_ARG_POINTER(listener); diff --git a/netwerk/base/LoadInfo.cpp b/netwerk/base/LoadInfo.cpp index d72c553c33be..e941c48611fd 100644 --- a/netwerk/base/LoadInfo.cpp +++ b/netwerk/base/LoadInfo.cpp @@ -727,7 +727,7 @@ LoadInfo::GetLoadingPrincipal(nsIPrincipal** aLoadingPrincipal) { return NS_OK; } -nsIPrincipal* LoadInfo::GetLoadingPrincipal() { return mLoadingPrincipal; } +nsIPrincipal* LoadInfo::LoadingPrincipal() { return mLoadingPrincipal; } NS_IMETHODIMP LoadInfo::GetTriggeringPrincipal(nsIPrincipal** aTriggeringPrincipal) { diff --git a/netwerk/base/LoadInfo.h b/netwerk/base/LoadInfo.h index d6bb696369b1..af9fa0b6bc44 100644 --- a/netwerk/base/LoadInfo.h +++ b/netwerk/base/LoadInfo.h @@ -55,7 +55,6 @@ class LoadInfo final : public nsILoadInfo { public: NS_DECL_ISUPPORTS NS_DECL_NSILOADINFO - nsIPrincipal* GetLoadingPrincipal() final; // aLoadingPrincipal MUST NOT BE NULL. LoadInfo(nsIPrincipal* aLoadingPrincipal, nsIPrincipal* aTriggeringPrincipal, diff --git a/netwerk/base/TRRLoadInfo.cpp b/netwerk/base/TRRLoadInfo.cpp index 1e836369b1eb..90e2ab09b558 100644 --- a/netwerk/base/TRRLoadInfo.cpp +++ b/netwerk/base/TRRLoadInfo.cpp @@ -32,7 +32,7 @@ TRRLoadInfo::GetLoadingPrincipal(nsIPrincipal** aLoadingPrincipal) { return NS_ERROR_NOT_IMPLEMENTED; } -nsIPrincipal* TRRLoadInfo::GetLoadingPrincipal() { return nullptr; } +nsIPrincipal* TRRLoadInfo::LoadingPrincipal() { return nullptr; } NS_IMETHODIMP TRRLoadInfo::GetTriggeringPrincipal(nsIPrincipal** aTriggeringPrincipal) { diff --git a/netwerk/base/TRRLoadInfo.h b/netwerk/base/TRRLoadInfo.h index fc5d2cd91f6f..6f233365ead3 100644 --- a/netwerk/base/TRRLoadInfo.h +++ b/netwerk/base/TRRLoadInfo.h @@ -24,7 +24,6 @@ class TRRLoadInfo final : public nsILoadInfo { public: NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_NSILOADINFO - nsIPrincipal* GetLoadingPrincipal() final; TRRLoadInfo(nsIURI* aResultPrincipalURI, nsContentPolicyType aContentPolicyType); diff --git a/netwerk/base/nsBaseChannel.cpp b/netwerk/base/nsBaseChannel.cpp index 44482c4b33eb..cdb8bfbbfaef 100644 --- a/netwerk/base/nsBaseChannel.cpp +++ b/netwerk/base/nsBaseChannel.cpp @@ -671,8 +671,8 @@ nsBaseChannel::AsyncOpen(nsIStreamListener* aListener) { mLoadInfo->GetInitialSecurityCheckDone() || (mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL && - mLoadInfo->GetLoadingPrincipal() && - mLoadInfo->GetLoadingPrincipal()->IsSystemPrincipal()), + mLoadInfo->LoadingPrincipal() && + mLoadInfo->LoadingPrincipal()->IsSystemPrincipal()), "security flags in loadInfo but doContentSecurityCheck() not called"); NS_ENSURE_TRUE(mURI, NS_ERROR_NOT_INITIALIZED); diff --git a/netwerk/base/nsILoadInfo.idl b/netwerk/base/nsILoadInfo.idl index 07f39df649e7..372c724b8e82 100644 --- a/netwerk/base/nsILoadInfo.idl +++ b/netwerk/base/nsILoadInfo.idl @@ -253,12 +253,11 @@ interface nsILoadInfo : nsISupports */ readonly attribute nsIPrincipal loadingPrincipal; -%{C++ /** * A C++-friendly version of loadingPrincipal. */ - virtual nsIPrincipal* GetLoadingPrincipal() = 0; -%} + [noscript, notxpcom, nostdcall, binaryname(LoadingPrincipal)] + nsIPrincipal binaryLoadingPrincipal(); /** * This is the principal which caused the network load to start. I.e. diff --git a/netwerk/base/nsIOService.cpp b/netwerk/base/nsIOService.cpp index 24172cb70a1a..127ac3c6558c 100644 --- a/netwerk/base/nsIOService.cpp +++ b/netwerk/base/nsIOService.cpp @@ -1853,7 +1853,7 @@ IOServiceProxyCallback::OnProxyAvailable(nsICancelable* request, if (!speculativeHandler) return NS_OK; nsCOMPtr loadInfo = channel->LoadInfo(); - nsCOMPtr principal = loadInfo->GetLoadingPrincipal(); + nsCOMPtr principal = loadInfo->LoadingPrincipal(); nsLoadFlags loadFlags = 0; channel->GetLoadFlags(&loadFlags); diff --git a/netwerk/base/nsNetUtil.cpp b/netwerk/base/nsNetUtil.cpp index 6e6730a081cf..1c09cbd940af 100644 --- a/netwerk/base/nsNetUtil.cpp +++ b/netwerk/base/nsNetUtil.cpp @@ -1974,7 +1974,7 @@ bool NS_HasBeenCrossOrigin(nsIChannel* aChannel, bool aReport) { nsCOMPtr loadInfo = aChannel->LoadInfo(); // TYPE_DOCUMENT loads have a null LoadingPrincipal and can not be cross // origin. - if (!loadInfo->GetLoadingPrincipal()) { + if (!loadInfo->LoadingPrincipal()) { return false; } @@ -1983,7 +1983,7 @@ bool NS_HasBeenCrossOrigin(nsIChannel* aChannel, bool aReport) { return true; } - nsCOMPtr loadingPrincipal = loadInfo->GetLoadingPrincipal(); + nsCOMPtr loadingPrincipal = loadInfo->LoadingPrincipal(); uint32_t mode = loadInfo->GetSecurityMode(); bool dataInherits = mode == nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_INHERITS || @@ -3059,8 +3059,8 @@ nsresult NS_CompareLoadInfoAndLoadContext(nsIChannel* aChannel) { // the loadInfo will use originAttributes from the content. Thus, the // originAttributes between loadInfo and loadContext will be different. // That's why we have to skip the comparison for the favicon loading. - if (loadInfo->GetLoadingPrincipal() && - loadInfo->GetLoadingPrincipal()->IsSystemPrincipal() && + if (loadInfo->LoadingPrincipal() && + loadInfo->LoadingPrincipal()->IsSystemPrincipal() && loadInfo->InternalContentPolicyType() == nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON) { return NS_OK; diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp index 8ed0acbd928c..f0c600e27022 100644 --- a/netwerk/protocol/http/HttpBaseChannel.cpp +++ b/netwerk/protocol/http/HttpBaseChannel.cpp @@ -2850,8 +2850,8 @@ void HttpBaseChannel::AssertPrivateBrowsingId() { // We skip testing of favicon loading here since it could be triggered by XUL // image which uses SystemPrincipal. The SystemPrincpal doesn't have // mPrivateBrowsingId. - if (mLoadInfo->GetLoadingPrincipal() && - mLoadInfo->GetLoadingPrincipal()->IsSystemPrincipal() && + if (mLoadInfo->LoadingPrincipal() && + mLoadInfo->LoadingPrincipal()->IsSystemPrincipal() && mLoadInfo->InternalContentPolicyType() == nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON) { return; @@ -3157,7 +3157,7 @@ HttpBaseChannel::CloneReplacementChannelConfig(bool aPreserveMethod, // AllRedirectsPassTimingAllowCheck on them. if (loadInfo->GetExternalContentPolicyType() != nsIContentPolicy::TYPE_DOCUMENT) { - nsCOMPtr principal = loadInfo->GetLoadingPrincipal(); + nsCOMPtr principal = loadInfo->LoadingPrincipal(); config.timedChannel->timingAllowCheckForPrincipal() = Some(oldTimedChannel->TimingAllowCheck(principal)); } diff --git a/netwerk/protocol/http/HttpChannelChild.cpp b/netwerk/protocol/http/HttpChannelChild.cpp index 500d2c9f0a5e..1b9454edc0b2 100644 --- a/netwerk/protocol/http/HttpChannelChild.cpp +++ b/netwerk/protocol/http/HttpChannelChild.cpp @@ -2427,8 +2427,8 @@ nsresult HttpChannelChild::AsyncOpenInternal(nsIStreamListener* aListener) { mLoadInfo->GetInitialSecurityCheckDone() || (mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL && - mLoadInfo->GetLoadingPrincipal() && - mLoadInfo->GetLoadingPrincipal()->IsSystemPrincipal()), + mLoadInfo->LoadingPrincipal() && + mLoadInfo->LoadingPrincipal()->IsSystemPrincipal()), "security flags in loadInfo but doContentSecurityCheck() not called"); LogCallingScriptLocation(this); diff --git a/netwerk/protocol/http/nsCORSListenerProxy.cpp b/netwerk/protocol/http/nsCORSListenerProxy.cpp index 35c32f89de8b..a3e82fc631aa 100644 --- a/netwerk/protocol/http/nsCORSListenerProxy.cpp +++ b/netwerk/protocol/http/nsCORSListenerProxy.cpp @@ -1384,7 +1384,7 @@ nsresult nsCORSListenerProxy::StartCORSPreflight( nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS, "how did we end up here?"); - nsCOMPtr principal = originalLoadInfo->GetLoadingPrincipal(); + nsCOMPtr principal = originalLoadInfo->LoadingPrincipal(); MOZ_ASSERT(principal && originalLoadInfo->GetExternalContentPolicyType() != nsIContentPolicy::TYPE_DOCUMENT, "Should not do CORS loads for top-level loads, so a " diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index 7dac273e9a86..4576c2757365 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -1475,9 +1475,8 @@ HttpTrafficCategory nsHttpChannel::CreateTrafficCategory() { } } - bool isSystemPrincipal = - mLoadInfo->GetLoadingPrincipal() && - mLoadInfo->GetLoadingPrincipal()->IsSystemPrincipal(); + bool isSystemPrincipal = mLoadInfo->LoadingPrincipal() && + mLoadInfo->LoadingPrincipal()->IsSystemPrincipal(); return HttpTrafficAnalyzer::CreateTrafficCategory( NS_UsePrivateBrowsing(this), isSystemPrincipal, isThirdParty, cos, tc); } @@ -1631,8 +1630,8 @@ nsresult EnsureMIMEOfScript(nsHttpChannel* aChannel, nsIURI* aURI, bool isPrivateWin = aLoadInfo->GetOriginAttributes().mPrivateBrowsingId > 0; bool isSameOrigin = false; - aLoadInfo->GetLoadingPrincipal()->IsSameOrigin(aURI, isPrivateWin, - &isSameOrigin); + aLoadInfo->LoadingPrincipal()->IsSameOrigin(aURI, isPrivateWin, + &isSameOrigin); if (isSameOrigin) { // same origin AccumulateCategorical( @@ -1652,7 +1651,7 @@ nsresult EnsureMIMEOfScript(nsHttpChannel* aChannel, nsIURI* aURI, bool isPrivateWin = aLoadInfo->GetOriginAttributes().mPrivateBrowsingId > 0; bool isSameOrigin = false; - aLoadInfo->GetLoadingPrincipal()->IsSameOrigin( + aLoadInfo->LoadingPrincipal()->IsSameOrigin( corsOriginURI, isPrivateWin, &isSameOrigin); if (isSameOrigin) { cors = true; @@ -6427,8 +6426,8 @@ nsHttpChannel::AsyncOpen(nsIStreamListener* aListener) { mLoadInfo->GetInitialSecurityCheckDone() || (mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL && - mLoadInfo->GetLoadingPrincipal() && - mLoadInfo->GetLoadingPrincipal()->IsSystemPrincipal()), + mLoadInfo->LoadingPrincipal() && + mLoadInfo->LoadingPrincipal()->IsSystemPrincipal()), "security flags in loadInfo but doContentSecurityCheck() not called"); LOG(("nsHttpChannel::AsyncOpen [this=%p]\n", this)); @@ -7594,7 +7593,7 @@ nsresult nsHttpChannel::ProcessCrossOriginResourcePolicyHeader() { return NS_OK; } - MOZ_ASSERT(mLoadInfo->GetLoadingPrincipal(), + MOZ_ASSERT(mLoadInfo->LoadingPrincipal(), "Resources should always have a LoadingPrincipal"); if (!mResponseHead) { return NS_OK; @@ -7629,7 +7628,7 @@ nsresult nsHttpChannel::ProcessCrossOriginResourcePolicyHeader() { // Cross-Origin-Resource-Policy = %s"same-origin" / %s"same-site" / // %s"cross-origin" if (content.EqualsLiteral("same-origin")) { - if (!channelOrigin->Equals(mLoadInfo->GetLoadingPrincipal())) { + if (!channelOrigin->Equals(mLoadInfo->LoadingPrincipal())) { return NS_ERROR_DOM_CORP_FAILED; } return NS_OK; @@ -7637,14 +7636,14 @@ nsresult nsHttpChannel::ProcessCrossOriginResourcePolicyHeader() { if (content.EqualsLiteral("same-site")) { nsAutoCString documentBaseDomain; nsAutoCString resourceBaseDomain; - mLoadInfo->GetLoadingPrincipal()->GetBaseDomain(documentBaseDomain); + mLoadInfo->LoadingPrincipal()->GetBaseDomain(documentBaseDomain); channelOrigin->GetBaseDomain(resourceBaseDomain); if (documentBaseDomain != resourceBaseDomain) { return NS_ERROR_DOM_CORP_FAILED; } nsCOMPtr resourceURI = channelOrigin->GetURI(); - if (!mLoadInfo->GetLoadingPrincipal()->SchemeIs("https") && + if (!mLoadInfo->LoadingPrincipal()->SchemeIs("https") && resourceURI->SchemeIs("https")) { return NS_ERROR_DOM_CORP_FAILED; } diff --git a/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp b/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp index 16eeba2b07f2..060dd9860fe2 100644 --- a/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp +++ b/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp @@ -931,11 +931,10 @@ bool nsHttpChannelAuthProvider::BlockPrompt(bool proxyAuth) { if (!topDoc && !xhr) { nsCOMPtr topURI; Unused << chanInternal->GetTopWindowURI(getter_AddRefs(topURI)); + nsCOMPtr loadingPrinc = loadInfo->LoadingPrincipal(); if (topURI) { mCrossOrigin = !NS_SecurityCompareURIs(topURI, mURI, true); } else { - nsIPrincipal* loadingPrinc = loadInfo->GetLoadingPrincipal(); - MOZ_ASSERT(loadingPrinc); bool sameOrigin = false; loadingPrinc->IsSameOrigin(mURI, false, &sameOrigin); mCrossOrigin = !sameOrigin; diff --git a/netwerk/protocol/websocket/WebSocketChannel.cpp b/netwerk/protocol/websocket/WebSocketChannel.cpp index 181dee4e64e9..3000990b87a0 100644 --- a/netwerk/protocol/websocket/WebSocketChannel.cpp +++ b/netwerk/protocol/websocket/WebSocketChannel.cpp @@ -3367,7 +3367,7 @@ WebSocketChannel::AsyncOpen(nsIURI* aURI, const nsACString& aOrigin, nsIProtocolProxyService::RESOLVE_PREFER_SOCKS_PROXY | nsIProtocolProxyService::RESOLVE_PREFER_HTTPS_PROXY | nsIProtocolProxyService::RESOLVE_ALWAYS_TUNNEL, - mLoadInfo->LoadingNode(), mLoadInfo->GetLoadingPrincipal(), + mLoadInfo->LoadingNode(), mLoadInfo->LoadingPrincipal(), mLoadInfo->TriggeringPrincipal(), mLoadInfo->GetSecurityFlags(), mLoadInfo->InternalContentPolicyType(), getter_AddRefs(localChannel)); NS_ENSURE_SUCCESS(rv, rv); diff --git a/netwerk/url-classifier/UrlClassifierCommon.cpp b/netwerk/url-classifier/UrlClassifierCommon.cpp index 7f342073cdb6..47c15b0d979c 100644 --- a/netwerk/url-classifier/UrlClassifierCommon.cpp +++ b/netwerk/url-classifier/UrlClassifierCommon.cpp @@ -46,7 +46,7 @@ bool UrlClassifierCommon::AddonMayLoad(nsIChannel* aChannel, nsIURI* aURI) { // loadingPrincipal is used here to ensure we are loading into an // addon principal. This allows an addon, with explicit permission, to // call out to API endpoints that may otherwise get blocked. - nsIPrincipal* loadingPrincipal = channelLoadInfo->GetLoadingPrincipal(); + nsIPrincipal* loadingPrincipal = channelLoadInfo->LoadingPrincipal(); if (!loadingPrincipal) { return false; } diff --git a/toolkit/components/antitracking/AntiTrackingUtils.cpp b/toolkit/components/antitracking/AntiTrackingUtils.cpp index 3fb64f633396..76fba92748b5 100644 --- a/toolkit/components/antitracking/AntiTrackingUtils.cpp +++ b/toolkit/components/antitracking/AntiTrackingUtils.cpp @@ -274,7 +274,7 @@ bool AntiTrackingUtils::CheckStoragePermission(nsIPrincipal* aPrincipal, } // We try to use the loading principal if there is no TopLevelPrincipal. - targetPrincipal = loadInfo->GetLoadingPrincipal(); + targetPrincipal = loadInfo->LoadingPrincipal(); } if (!targetPrincipal) { diff --git a/toolkit/components/antitracking/ContentBlocking.cpp b/toolkit/components/antitracking/ContentBlocking.cpp index 7a55e28cd2be..9391f3c0e387 100644 --- a/toolkit/components/antitracking/ContentBlocking.cpp +++ b/toolkit/components/antitracking/ContentBlocking.cpp @@ -759,7 +759,7 @@ bool ContentBlocking::ShouldAllowAccessFor(nsIChannel* aChannel, nsIURI* aURI, LOG( ("Our loadInfo lacks a top-level principal, use the loadInfo's loading " "principal instead")); - toplevelPrincipal = loadInfo->GetLoadingPrincipal(); + toplevelPrincipal = loadInfo->LoadingPrincipal(); } nsCOMPtr httpChannel = do_QueryInterface(aChannel); diff --git a/toolkit/components/extensions/webrequest/ChannelWrapper.cpp b/toolkit/components/extensions/webrequest/ChannelWrapper.cpp index 83835ac3ba2d..c6d771125e87 100644 --- a/toolkit/components/extensions/webrequest/ChannelWrapper.cpp +++ b/toolkit/components/extensions/webrequest/ChannelWrapper.cpp @@ -446,7 +446,7 @@ static inline bool IsSystemPrincipal(nsIPrincipal* aPrincipal) { bool ChannelWrapper::IsSystemLoad() const { if (nsCOMPtr loadInfo = GetLoadInfo()) { - if (nsIPrincipal* prin = loadInfo->GetLoadingPrincipal()) { + if (nsIPrincipal* prin = loadInfo->LoadingPrincipal()) { return IsSystemPrincipal(prin); } @@ -470,7 +470,7 @@ bool ChannelWrapper::CanModify() const { } if (nsCOMPtr loadInfo = GetLoadInfo()) { - if (nsIPrincipal* prin = loadInfo->GetLoadingPrincipal()) { + if (nsIPrincipal* prin = loadInfo->LoadingPrincipal()) { if (IsSystemPrincipal(prin)) { return false; } @@ -499,7 +499,7 @@ already_AddRefed ChannelWrapper::GetOriginURI() const { already_AddRefed ChannelWrapper::GetDocumentURI() const { nsCOMPtr uri; if (nsCOMPtr loadInfo = GetLoadInfo()) { - if (nsIPrincipal* prin = loadInfo->GetLoadingPrincipal()) { + if (nsIPrincipal* prin = loadInfo->LoadingPrincipal()) { if (prin->GetIsContentPrincipal()) { Unused << prin->GetURI(getter_AddRefs(uri)); } diff --git a/toolkit/components/places/PageIconProtocolHandler.cpp b/toolkit/components/places/PageIconProtocolHandler.cpp index b02cc39522b8..9e30fda1d32a 100644 --- a/toolkit/components/places/PageIconProtocolHandler.cpp +++ b/toolkit/components/places/PageIconProtocolHandler.cpp @@ -198,7 +198,7 @@ nsresult PageIconProtocolHandler::NewChannelInternal(nsIURI* aURI, nsCOMPtr channel; rv = NS_NewInputStreamChannel( getter_AddRefs(channel), aURI, pipeIn.forget(), - aLoadInfo->GetLoadingPrincipal(), + aLoadInfo->LoadingPrincipal(), nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED, nsIContentPolicy::TYPE_INTERNAL_IMAGE); NS_ENSURE_SUCCESS(rv, rv); diff --git a/toolkit/mozapps/extensions/AddonContentPolicy.cpp b/toolkit/mozapps/extensions/AddonContentPolicy.cpp index 497dae70d63b..4659d3c2be83 100644 --- a/toolkit/mozapps/extensions/AddonContentPolicy.cpp +++ b/toolkit/mozapps/extensions/AddonContentPolicy.cpp @@ -94,7 +94,8 @@ AddonContentPolicy::ShouldLoad(nsIURI* aContentLocation, nsILoadInfo* aLoadInfo, uint32_t contentType = aLoadInfo->GetExternalContentPolicyType(); nsCOMPtr requestOrigin; - if (nsIPrincipal* loadingPrincipal = aLoadInfo->GetLoadingPrincipal()) { + nsCOMPtr loadingPrincipal = aLoadInfo->LoadingPrincipal(); + if (loadingPrincipal) { loadingPrincipal->GetURI(getter_AddRefs(requestOrigin)); } diff --git a/uriloader/exthandler/nsExternalProtocolHandler.cpp b/uriloader/exthandler/nsExternalProtocolHandler.cpp index 4bba0cf202d3..8f4e2ed21d0e 100644 --- a/uriloader/exthandler/nsExternalProtocolHandler.cpp +++ b/uriloader/exthandler/nsExternalProtocolHandler.cpp @@ -213,8 +213,8 @@ NS_IMETHODIMP nsExtProtocolChannel::AsyncOpen(nsIStreamListener* aListener) { mLoadInfo->GetInitialSecurityCheckDone() || (mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL && - mLoadInfo->GetLoadingPrincipal() && - mLoadInfo->GetLoadingPrincipal()->IsSystemPrincipal()), + mLoadInfo->LoadingPrincipal() && + mLoadInfo->LoadingPrincipal()->IsSystemPrincipal()), "security flags in loadInfo but doContentSecurityCheck() not called"); NS_ENSURE_ARG_POINTER(listener);