From 2f5607b8d052b0bbefdf8cbd625c296720816b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 31 May 2020 17:11:57 +0000 Subject: [PATCH] Bug 1642221 - Rename SheetLoadData::mLoaderPrincipal to mTriggeringPrincipal. r=jwatt I'm about to introduce the concept of "Loader principal" (as in "the principal of the CSS loader"), and SheetLoadData already has an mLoaderPrincipal. However SheetLoadData's principal is just the triggering principal (the principal that initiated the load). So name it that with consistency with SheetInfo::mTriggeringPrincipal etc. Differential Revision: https://phabricator.services.mozilla.com/D77613 --- layout/inspector/InspectorUtils.cpp | 1 + layout/style/Loader.cpp | 46 ++++++++++++++-------------- layout/style/Loader.h | 11 ++++--- layout/style/SheetLoadData.h | 13 ++++---- uriloader/preload/PreloadHashKey.cpp | 3 +- uriloader/preload/PreloadHashKey.h | 8 +++-- 6 files changed, 45 insertions(+), 37 deletions(-) diff --git a/layout/inspector/InspectorUtils.cpp b/layout/inspector/InspectorUtils.cpp index 69bd9cb8ea15..0cdc005238b3 100644 --- a/layout/inspector/InspectorUtils.cpp +++ b/layout/inspector/InspectorUtils.cpp @@ -27,6 +27,7 @@ #include "mozilla/dom/Element.h" #include "mozilla/dom/CSSStyleRule.h" #include "mozilla/dom/InspectorUtilsBinding.h" +#include "mozilla/dom/LinkStyle.h" #include "mozilla/dom/ToJSValue.h" #include "nsCSSProps.h" #include "nsCSSValue.h" diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index 7debcbcecfc9..98153e14fb30 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -254,7 +254,7 @@ class SheetLoadDataHashKey : public nsURIHashKey { SheetLoadDataHashKey::SheetLoadDataHashKey(css::SheetLoadData& aLoadData) : nsURIHashKey(aLoadData.mURI), - mPrincipal(aLoadData.mLoaderPrincipal), + mPrincipal(aLoadData.mTriggeringPrincipal), mReferrerInfo(aLoadData.ReferrerInfo()), mCORSMode(aLoadData.mSheet->GetCORSMode()), mParsingMode(aLoadData.mSheet->ParsingMode()), @@ -278,7 +278,7 @@ SheetLoadData::SheetLoadData(Loader* aLoader, const nsAString& aTitle, nsINode* aOwningNode, IsAlternate aIsAlternate, MediaMatched aMediaMatches, IsPreload aIsPreload, nsICSSLoaderObserver* aObserver, - nsIPrincipal* aLoaderPrincipal, + nsIPrincipal* aTriggeringPrincipal, nsIReferrerInfo* aReferrerInfo, nsINode* aRequestingNode) : mLoader(aLoader), @@ -305,7 +305,7 @@ SheetLoadData::SheetLoadData(Loader* aLoader, const nsAString& aTitle, mIsPreload(aIsPreload), mOwningNode(aOwningNode), mObserver(aObserver), - mLoaderPrincipal(aLoaderPrincipal), + mTriggeringPrincipal(aTriggeringPrincipal), mReferrerInfo(aReferrerInfo), mRequestingNode(aRequestingNode), mPreloadEncoding(nullptr) { @@ -317,7 +317,7 @@ SheetLoadData::SheetLoadData(Loader* aLoader, const nsAString& aTitle, SheetLoadData::SheetLoadData(Loader* aLoader, nsIURI* aURI, StyleSheet* aSheet, SheetLoadData* aParentData, nsICSSLoaderObserver* aObserver, - nsIPrincipal* aLoaderPrincipal, + nsIPrincipal* aTriggeringPrincipal, nsIReferrerInfo* aReferrerInfo, nsINode* aRequestingNode) : mLoader(aLoader), @@ -344,7 +344,7 @@ SheetLoadData::SheetLoadData(Loader* aLoader, nsIURI* aURI, StyleSheet* aSheet, mIsPreload(IsPreload::No), mOwningNode(nullptr), mObserver(aObserver), - mLoaderPrincipal(aLoaderPrincipal), + mTriggeringPrincipal(aTriggeringPrincipal), mReferrerInfo(aReferrerInfo), mRequestingNode(aRequestingNode), mPreloadEncoding(nullptr) { @@ -361,7 +361,7 @@ SheetLoadData::SheetLoadData( Loader* aLoader, nsIURI* aURI, StyleSheet* aSheet, bool aSyncLoad, UseSystemPrincipal aUseSystemPrincipal, IsPreload aIsPreload, const Encoding* aPreloadEncoding, nsICSSLoaderObserver* aObserver, - nsIPrincipal* aLoaderPrincipal, nsIReferrerInfo* aReferrerInfo, + nsIPrincipal* aTriggeringPrincipal, nsIReferrerInfo* aReferrerInfo, nsINode* aRequestingNode) : mLoader(aLoader), mEncoding(nullptr), @@ -386,7 +386,7 @@ SheetLoadData::SheetLoadData( mIsPreload(aIsPreload), mOwningNode(nullptr), mObserver(aObserver), - mLoaderPrincipal(aLoaderPrincipal), + mTriggeringPrincipal(aTriggeringPrincipal), mReferrerInfo(aReferrerInfo), mRequestingNode(aRequestingNode), mPreloadEncoding(aPreloadEncoding) { @@ -539,10 +539,10 @@ static void AssertIncompleteSheetMatches(const SheetLoadData& aData, const SheetLoadDataHashKey& aKey) { #ifdef DEBUG bool debugEqual; - MOZ_ASSERT((!aKey.GetPrincipal() && !aData.mLoaderPrincipal) || - (aKey.GetPrincipal() && aData.mLoaderPrincipal && + MOZ_ASSERT((!aKey.GetPrincipal() && !aData.mTriggeringPrincipal) || + (aKey.GetPrincipal() && aData.mTriggeringPrincipal && NS_SUCCEEDED(aKey.GetPrincipal()->Equals( - aData.mLoaderPrincipal, &debugEqual)) && + aData.mTriggeringPrincipal, &debugEqual)) && debugEqual), "Principals should be the same"); #endif @@ -954,9 +954,9 @@ nsresult SheetLoadData::VerifySheetReadyToParse(nsresult aStatus, mSheet->SetPrincipal(principal); - if (mLoaderPrincipal && mSheet->GetCORSMode() == CORS_NONE) { + if (mTriggeringPrincipal && mSheet->GetCORSMode() == CORS_NONE) { bool subsumed; - result = mLoaderPrincipal->Subsumes(principal, &subsumed); + result = mTriggeringPrincipal->Subsumes(principal, &subsumed); if (NS_FAILED(result) || !subsumed) { mIsCrossOriginNoCORS = true; } @@ -997,9 +997,9 @@ nsresult SheetLoadData::VerifySheetReadyToParse(nsresult aStatus, uint32_t errorFlag; bool sameOrigin = true; - if (mLoaderPrincipal) { + if (mTriggeringPrincipal) { bool subsumed; - result = mLoaderPrincipal->Subsumes(principal, &subsumed); + result = mTriggeringPrincipal->Subsumes(principal, &subsumed); if (NS_FAILED(result) || !subsumed) { sameOrigin = false; } @@ -1147,10 +1147,10 @@ nsresult Loader::CheckContentPolicy(nsIPrincipal* aLoadingPrincipal, * the result of CreateSheet(). */ std::tuple, Loader::SheetState> Loader::CreateSheet( - nsIURI* aURI, nsIContent* aLinkingContent, nsIPrincipal* aLoaderPrincipal, - css::SheetParsingMode aParsingMode, CORSMode aCORSMode, - nsIReferrerInfo* aLoadingReferrerInfo, const nsAString& aIntegrity, - bool aSyncLoad, IsPreload aIsPreload) { + nsIURI* aURI, nsIContent* aLinkingContent, + nsIPrincipal* aTriggeringPrincipal, css::SheetParsingMode aParsingMode, + CORSMode aCORSMode, nsIReferrerInfo* aLoadingReferrerInfo, + const nsAString& aIntegrity, bool aSyncLoad, IsPreload aIsPreload) { MOZ_ASSERT(aURI, "This path is not taken for inline stylesheets"); LOG(("css::Loader::CreateSheet(%s)", aURI->GetSpecOrDefault().get())); @@ -1170,7 +1170,7 @@ std::tuple, Loader::SheetState> Loader::CreateSheet( SRICheck::IntegrityMetadata(aIntegrity, sourceUri, mReporter, &sriMetadata); } - SheetLoadDataHashKey key(aURI, aLoaderPrincipal, aLoadingReferrerInfo, + SheetLoadDataHashKey key(aURI, aTriggeringPrincipal, aLoadingReferrerInfo, aCORSMode, aParsingMode, sriMetadata, aIsPreload); auto cacheResult = mSheets->Lookup(key, aSyncLoad); if (const auto& [styleSheet, sheetState] = cacheResult; styleSheet) { @@ -1400,10 +1400,10 @@ nsresult Loader::LoadSheet(SheetLoadData& aLoadData, SheetState aSheetState) { // This is because of a case where the node is the document being styled and // the principal is the stylesheet (perhaps from a different origin) that is // applying the styles. - if (aLoadData.mRequestingNode && aLoadData.mLoaderPrincipal) { + if (aLoadData.mRequestingNode && aLoadData.mTriggeringPrincipal) { rv = NS_NewChannelWithTriggeringPrincipal( getter_AddRefs(channel), aLoadData.mURI, aLoadData.mRequestingNode, - aLoadData.mLoaderPrincipal, securityFlags, contentPolicyType); + aLoadData.mTriggeringPrincipal, securityFlags, contentPolicyType); } else { // either we are loading something inside a document, in which case // we should always have a requestingNode, or we are loading something @@ -1543,10 +1543,10 @@ nsresult Loader::LoadSheet(SheetLoadData& aLoadData, SheetState aSheetState) { // and a principal. This is because of a case where the node is the document // being styled and the principal is the stylesheet (perhaps from a different // origin) that is applying the styles. - if (aLoadData.mRequestingNode && aLoadData.mLoaderPrincipal) { + if (aLoadData.mRequestingNode && aLoadData.mTriggeringPrincipal) { rv = NS_NewChannelWithTriggeringPrincipal( getter_AddRefs(channel), aLoadData.mURI, aLoadData.mRequestingNode, - aLoadData.mLoaderPrincipal, securityFlags, contentPolicyType, + aLoadData.mTriggeringPrincipal, securityFlags, contentPolicyType, /* PerformanceStorage */ nullptr, loadGroup); } else { // either we are loading something inside a document, in which case diff --git a/layout/style/Loader.h b/layout/style/Loader.h index eea6105a6fde..5d0a6bc78c24 100644 --- a/layout/style/Loader.h +++ b/layout/style/Loader.h @@ -338,10 +338,10 @@ class Loader final { }; std::tuple, SheetState> CreateSheet( - const SheetInfo& aInfo, nsIPrincipal* aLoaderPrincipal, + const SheetInfo& aInfo, nsIPrincipal* aTriggeringPrincipal, css::SheetParsingMode aParsingMode, bool aSyncLoad, IsPreload aIsPreload) { - return CreateSheet(aInfo.mURI, aInfo.mContent, aLoaderPrincipal, + return CreateSheet(aInfo.mURI, aInfo.mContent, aTriggeringPrincipal, aParsingMode, aInfo.mCORSMode, aInfo.mReferrerInfo, aInfo.mIntegrity, aSyncLoad, aIsPreload); } @@ -350,9 +350,10 @@ class Loader final { // must be non-null then. The loader principal must never be null // if aURI is not null. std::tuple, SheetState> CreateSheet( - nsIURI* aURI, nsIContent* aLinkingContent, nsIPrincipal* aLoaderPrincipal, - css::SheetParsingMode, CORSMode, nsIReferrerInfo* aLoadingReferrerInfo, - const nsAString& aIntegrity, bool aSyncLoad, IsPreload aIsPreload); + nsIURI* aURI, nsIContent* aLinkingContent, + nsIPrincipal* aTriggeringPrincipal, css::SheetParsingMode, CORSMode, + nsIReferrerInfo* aLoadingReferrerInfo, const nsAString& aIntegrity, + bool aSyncLoad, IsPreload aIsPreload); // Pass in either a media string or the MediaList from the CSSParser. Don't // pass both. diff --git a/layout/style/SheetLoadData.h b/layout/style/SheetLoadData.h index ea7b860d59de..eb7c2c12950f 100644 --- a/layout/style/SheetLoadData.h +++ b/layout/style/SheetLoadData.h @@ -50,20 +50,21 @@ class SheetLoadData final : public nsIRunnable, public nsIThreadObserver { StyleSheet* aSheet, bool aSyncLoad, nsINode* aOwningNode, IsAlternate aIsAlternate, MediaMatched aMediaMatched, IsPreload aIsPreload, nsICSSLoaderObserver* aObserver, - nsIPrincipal* aLoaderPrincipal, nsIReferrerInfo* aReferrerInfo, - nsINode* aRequestingNode); + nsIPrincipal* aTriggeringPrincipal, + nsIReferrerInfo* aReferrerInfo, nsINode* aRequestingNode); // Data for loading a sheet linked from an @import rule SheetLoadData(Loader* aLoader, nsIURI* aURI, StyleSheet* aSheet, SheetLoadData* aParentData, nsICSSLoaderObserver* aObserver, - nsIPrincipal* aLoaderPrincipal, nsIReferrerInfo* aReferrerInfo, - nsINode* aRequestingNode); + nsIPrincipal* aTriggeringPrincipal, + nsIReferrerInfo* aReferrerInfo, nsINode* aRequestingNode); // Data for loading a non-document sheet SheetLoadData(Loader* aLoader, nsIURI* aURI, StyleSheet* aSheet, bool aSyncLoad, UseSystemPrincipal, IsPreload, const Encoding* aPreloadEncoding, - nsICSSLoaderObserver* aObserver, nsIPrincipal* aLoaderPrincipal, + nsICSSLoaderObserver* aObserver, + nsIPrincipal* aTriggeringPrincipal, nsIReferrerInfo* aReferrerInfo, nsINode* aRequestingNode); nsIReferrerInfo* ReferrerInfo() { return mReferrerInfo; } @@ -193,7 +194,7 @@ class SheetLoadData final : public nsIRunnable, public nsIThreadObserver { const nsCOMPtr mObserver; // The principal that identifies who started loading us. - const nsCOMPtr mLoaderPrincipal; + const nsCOMPtr mTriggeringPrincipal; // Referrer info of the load. const nsCOMPtr mReferrerInfo; diff --git a/uriloader/preload/PreloadHashKey.cpp b/uriloader/preload/PreloadHashKey.cpp index a796222f9e55..865af9a1dbbe 100644 --- a/uriloader/preload/PreloadHashKey.cpp +++ b/uriloader/preload/PreloadHashKey.cpp @@ -5,6 +5,7 @@ #include "PreloadHashKey.h" #include "mozilla/dom/Element.h" // StringToCORSMode +#include "mozilla/css/SheetLoadData.h" #include "nsIPrincipal.h" #include "nsIReferrerInfo.h" @@ -117,7 +118,7 @@ PreloadHashKey PreloadHashKey::CreateAsStyle( // static PreloadHashKey PreloadHashKey::CreateAsStyle( css::SheetLoadData& aSheetLoadData) { - return CreateAsStyle(aSheetLoadData.mURI, aSheetLoadData.mLoaderPrincipal, + return CreateAsStyle(aSheetLoadData.mURI, aSheetLoadData.mTriggeringPrincipal, aSheetLoadData.ReferrerInfo(), aSheetLoadData.mSheet->GetCORSMode(), aSheetLoadData.mSheet->ParsingMode()); diff --git a/uriloader/preload/PreloadHashKey.h b/uriloader/preload/PreloadHashKey.h index 3917e49418da..922392690bf7 100644 --- a/uriloader/preload/PreloadHashKey.h +++ b/uriloader/preload/PreloadHashKey.h @@ -6,7 +6,7 @@ #define PreloadHashKey_h__ #include "mozilla/CORSMode.h" -#include "mozilla/css/SheetLoadData.h" +#include "mozilla/css/SheetParsingMode.h" #include "mozilla/dom/ReferrerPolicyBinding.h" #include "mozilla/dom/ScriptKind.h" #include "nsURIHashKey.h" @@ -16,6 +16,10 @@ class nsIReferrerInfo; namespace mozilla { +namespace css { +class SheetLoadData; +} + /** * This key is used for coalescing and lookup of preloading or regular * speculative loads. It consists of: @@ -54,7 +58,7 @@ class PreloadHashKey : public nsURIHashKey { nsIReferrerInfo* aReferrerInfo, CORSMode aCORSMode, css::SheetParsingMode aParsingMode); - static PreloadHashKey CreateAsStyle(css::SheetLoadData& aSheetLoadData); + static PreloadHashKey CreateAsStyle(css::SheetLoadData&); // Construct key for "image" static PreloadHashKey CreateAsImage(