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
This commit is contained in:
Emilio Cobos Álvarez 2020-05-31 17:11:57 +00:00
parent 1ba1fb1c93
commit 2f5607b8d0
6 changed files with 45 additions and 37 deletions

View File

@ -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"

View File

@ -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<RefPtr<StyleSheet>, 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<RefPtr<StyleSheet>, 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

View File

@ -338,10 +338,10 @@ class Loader final {
};
std::tuple<RefPtr<StyleSheet>, 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<RefPtr<StyleSheet>, 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.

View File

@ -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<nsICSSLoaderObserver> mObserver;
// The principal that identifies who started loading us.
const nsCOMPtr<nsIPrincipal> mLoaderPrincipal;
const nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
// Referrer info of the load.
const nsCOMPtr<nsIReferrerInfo> mReferrerInfo;

View File

@ -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());

View File

@ -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(