Bug 1820280 - Be consistent for which URIs we expose chrome rules. r=dshin

Differential Revision: https://phabricator.services.mozilla.com/D171640
This commit is contained in:
Emilio Cobos Álvarez 2023-03-07 20:22:23 +00:00
parent 5c665e56a8
commit 01a41fb486
9 changed files with 19 additions and 17 deletions

View File

@ -1349,7 +1349,7 @@ Document::Document(const char* aContentType)
mInUnlinkOrDeletion(false),
mHasHadScriptHandlingObject(false),
mIsBeingUsedAsImage(false),
mDocURISchemeIsChrome(false),
mChromeRulesEnabled(false),
mInChromeDocShell(false),
mIsDevToolsDocument(false),
mIsSyntheticDocument(false),
@ -4023,7 +4023,7 @@ void Document::SetDocumentURI(nsIURI* aURI) {
mDocumentURI = aURI;
nsIURI* newBase = GetDocBaseURI();
mDocURISchemeIsChrome = aURI && IsChromeURI(aURI);
mChromeRulesEnabled = URLExtraData::ChromeRulesEnabled(aURI);
bool equalBases = false;
// Changing just the ref of a URI does not change how relative URIs would

View File

@ -2614,7 +2614,7 @@ class Document : public nsINode,
return !mParentDocument && !mDisplayDocument;
}
bool IsDocumentURISchemeChrome() const { return mDocURISchemeIsChrome; }
bool ChromeRulesEnabled() const { return mChromeRulesEnabled; }
bool IsInChromeDocShell() const {
const Document* root = this;
@ -4650,8 +4650,8 @@ class Document : public nsINode,
// True if we're an SVG document being used as an image.
bool mIsBeingUsedAsImage : 1;
// True if our current document URI's scheme is chrome://
bool mDocURISchemeIsChrome : 1;
// True if our current document URI's scheme enables privileged CSS rules.
bool mChromeRulesEnabled : 1;
// True if we're loaded in a chrome docshell.
bool mInChromeDocShell : 1;

View File

@ -2977,12 +2977,11 @@ const RawServoSelectorList* nsINode::ParseSelectorList(
// want to cache the "This is not a valid selector" result.
//
// NOTE(emilio): Off-hand, getting a CallerType here might seem like a
// better idea than using IsDocumentURISchemeChrome(), but that would mean
// better idea than using ChromeRulesEnabled(), but that would mean
// that we'd need to key the selector cache by that.
// IsDocumentURISchemeChrome() gives us the same semantics as any inline
// ChromeRulesEnabled() gives us the same semantics as any inline
// style associated to a document, which seems reasonable.
return Servo_SelectorList_Parse(&aSelectorString,
doc->IsDocumentURISchemeChrome())
return Servo_SelectorList_Parse(&aSelectorString, doc->ChromeRulesEnabled())
.Consume();
});

View File

@ -2716,7 +2716,7 @@ void nsCSSFrameConstructor::SetUpDocElementContainingBlock(
if (isXUL) {
return false;
}
if (aDocElement->OwnerDoc()->IsDocumentURISchemeChrome() &&
if (aDocElement->OwnerDoc()->ChromeRulesEnabled() &&
aDocElement->AsElement()->AttrValueIs(
kNameSpaceID_None, nsGkAtoms::scrolling, nsGkAtoms::_false,
eCaseMatters)) {

View File

@ -65,7 +65,7 @@ auto PreferenceSheet::PrefsKindFor(const Document& aDoc) -> PrefsKind {
return PrefsKind::Chrome;
}
if (aDoc.IsBeingUsedAsImage() && aDoc.IsDocumentURISchemeChrome()) {
if (aDoc.IsBeingUsedAsImage() && aDoc.ChromeRulesEnabled()) {
return PrefsKind::Chrome;
}

View File

@ -22,6 +22,10 @@
namespace mozilla {
struct URLExtraData {
static bool ChromeRulesEnabled(nsIURI* aURI) {
return aURI && (aURI->SchemeIs("chrome") || aURI->SchemeIs("resource"));
}
URLExtraData(already_AddRefed<nsIURI> aBaseURI,
already_AddRefed<nsIReferrerInfo> aReferrerInfo,
already_AddRefed<nsIPrincipal> aPrincipal)
@ -34,8 +38,7 @@ struct URLExtraData {
// When we hold the URI data of a style sheet, referrer is always
// equal to the sheet URI.
nsCOMPtr<nsIURI> referrer = mReferrerInfo->GetOriginalReferrer();
mChromeRulesEnabled = referrer && (referrer->SchemeIs("chrome") ||
referrer->SchemeIs("resource"));
mChromeRulesEnabled = ChromeRulesEnabled(referrer);
}
URLExtraData(nsIURI* aBaseURI, nsIReferrerInfo* aReferrerInfo,

View File

@ -37,7 +37,7 @@ void SVGImageContext::MaybeStoreContextPaint(SVGImageContext& aContext,
}
if (StaticPrefs::svg_embedder_prefers_color_scheme_content_enabled() ||
aPresContext.Document()->IsDocumentURISchemeChrome()) {
aPresContext.Document()->ChromeRulesEnabled()) {
auto scheme = LookAndFeel::ColorSchemeForStyle(
*aPresContext.Document(), aStyle.StyleUI()->mColorScheme.bits,
ColorSchemeMode::Preferred);

View File

@ -146,7 +146,7 @@ impl CssEnvironment {
if let Some(var) = ENVIRONMENT_VARIABLES.iter().find(|var| var.name == *name) {
return Some((var.evaluator)(device));
}
if !device.is_chrome_document() {
if !device.chrome_rules_enabled_for_document() {
return None;
}
let var = CHROME_ENVIRONMENT_VARIABLES

View File

@ -559,7 +559,7 @@ impl Device {
/// This check is consistent with how we enable chrome rules for chrome:// and resource://
/// stylesheets (and thus chrome:// documents).
#[inline]
pub fn is_chrome_document(&self) -> bool {
self.document().mDocURISchemeIsChrome()
pub fn chrome_rules_enabled_for_document(&self) -> bool {
self.document().mChromeRulesEnabled()
}
}