From 2e092ef47ce9ac99ae90a32c051eb392ef0e943f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 16 Jan 2021 18:26:52 +0000 Subject: [PATCH] Bug 1551040 - Allow resource:// stylesheets to use chrome-only rules. r=boris We'll use it to use @-moz-document from plaintext.css. Differential Revision: https://phabricator.services.mozilla.com/D101516 --- layout/style/StyleSheet.cpp | 6 +++--- layout/style/URLExtraData.cpp | 2 +- layout/style/URLExtraData.h | 8 +++++--- servo/components/style/parser.rs | 2 +- servo/components/style/selector_parser.rs | 2 +- servo/components/style/stylesheets/mod.rs | 6 +++--- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/layout/style/StyleSheet.cpp b/layout/style/StyleSheet.cpp index b5338dea0c88..c9fe228d5230 100644 --- a/layout/style/StyleSheet.cpp +++ b/layout/style/StyleSheet.cpp @@ -1142,7 +1142,7 @@ already_AddRefed StyleSheet::CreateEmptyChildSheet( // (3) The stylesheet is a chrome stylesheet, since those can use // -moz-bool-pref, which needs to access the pref service, which is not // threadsafe. -static bool AllowParallelParse(css::Loader& aLoader, nsIURI* aSheetURI) { +static bool AllowParallelParse(css::Loader& aLoader, URLExtraData* aUrlData) { // If the browser is recording CSS errors, we need to use the sequential path // because the parallel path doesn't support that. Document* doc = aLoader.GetDocument(); @@ -1157,7 +1157,7 @@ static bool AllowParallelParse(css::Loader& aLoader, nsIURI* aSheetURI) { // // Note that UA stylesheets can also use -moz-bool-pref, but those are always // parsed sync. - if (dom::IsChromeURI(aSheetURI)) { + if (aUrlData->ChromeRulesEnabled()) { return false; } @@ -1179,7 +1179,7 @@ RefPtr StyleSheet::ParseSheet( : StyleAllowImportRules::Yes; const bool shouldRecordCounters = aLoader.GetDocument() && aLoader.GetDocument()->GetStyleUseCounters(); - if (!AllowParallelParse(aLoader, GetSheetURI())) { + if (!AllowParallelParse(aLoader, Inner().mURLData)) { UniquePtr counters = shouldRecordCounters ? Servo_UseCounters_Create().Consume() : nullptr; diff --git a/layout/style/URLExtraData.cpp b/layout/style/URLExtraData.cpp index 76e414164bed..5eb7abd4a47e 100644 --- a/layout/style/URLExtraData.cpp +++ b/layout/style/URLExtraData.cpp @@ -27,7 +27,7 @@ void URLExtraData::Init() { sDummyChrome = new URLExtraData(baseURI.forget(), referrerInfo.forget(), NullPrincipal::CreateWithoutOriginAttributes()); - sDummyChrome->mIsChrome = true; + sDummyChrome->mChromeRulesEnabled = true; } /* static */ diff --git a/layout/style/URLExtraData.h b/layout/style/URLExtraData.h index 71c002de90a8..9b715b523941 100644 --- a/layout/style/URLExtraData.h +++ b/layout/style/URLExtraData.h @@ -34,7 +34,8 @@ struct URLExtraData { // When we hold the URI data of a style sheet, referrer is always // equal to the sheet URI. nsCOMPtr referrer = mReferrerInfo->GetOriginalReferrer(); - mIsChrome = referrer ? dom::IsChromeURI(referrer) : false; + mChromeRulesEnabled = referrer && (referrer->SchemeIs("chrome") || + referrer->SchemeIs("resource")); } URLExtraData(nsIURI* aBaseURI, nsIReferrerInfo* aReferrerInfo, @@ -48,6 +49,8 @@ struct URLExtraData { nsIReferrerInfo* ReferrerInfo() const { return mReferrerInfo; } nsIPrincipal* Principal() const { return mPrincipal; } + bool ChromeRulesEnabled() const { return mChromeRulesEnabled; } + static URLExtraData* Dummy() { MOZ_ASSERT(sDummy); return sDummy; @@ -73,8 +76,7 @@ struct URLExtraData { nsCOMPtr mReferrerInfo; nsCOMPtr mPrincipal; - // True if referrer is a chrome:// URI. - bool mIsChrome; + bool mChromeRulesEnabled; static StaticRefPtr sDummy; static StaticRefPtr sDummyChrome; diff --git a/servo/components/style/parser.rs b/servo/components/style/parser.rs index 27ba5ea7320a..837b97400241 100644 --- a/servo/components/style/parser.rs +++ b/servo/components/style/parser.rs @@ -140,7 +140,7 @@ impl<'a> ParserContext<'a> { /// Returns whether chrome-only rules should be parsed. #[inline] pub fn chrome_rules_enabled(&self) -> bool { - self.url_data.is_chrome() || self.stylesheet_origin == Origin::User + self.url_data.chrome_rules_enabled() || self.stylesheet_origin == Origin::User } /// Whether we're in a user-agent stylesheet or chrome rules are enabled. diff --git a/servo/components/style/selector_parser.rs b/servo/components/style/selector_parser.rs index a8b5c3bc33e6..52675abf45a7 100644 --- a/servo/components/style/selector_parser.rs +++ b/servo/components/style/selector_parser.rs @@ -75,7 +75,7 @@ impl<'a> SelectorParser<'a> { /// Whether we're parsing selectors in a stylesheet that has chrome /// privilege. pub fn chrome_rules_enabled(&self) -> bool { - self.url_data.map_or(false, |d| d.is_chrome()) || self.stylesheet_origin == Origin::User + self.url_data.map_or(false, |d| d.chrome_rules_enabled()) || self.stylesheet_origin == Origin::User } } diff --git a/servo/components/style/stylesheets/mod.rs b/servo/components/style/stylesheets/mod.rs index 219c5632a3cd..fd9be56b5b53 100644 --- a/servo/components/style/stylesheets/mod.rs +++ b/servo/components/style/stylesheets/mod.rs @@ -156,8 +156,8 @@ impl UrlExtraData { /// True if this URL scheme is chrome. #[inline] - pub fn is_chrome(&self) -> bool { - self.as_ref().mIsChrome + pub fn chrome_rules_enabled(&self) -> bool { + self.as_ref().mChromeRulesEnabled } /// Create a reference to this `UrlExtraData` from a reference to pointer. @@ -215,7 +215,7 @@ impl fmt::Debug for UrlExtraData { formatter .debug_struct("URLExtraData") - .field("is_chrome", &self.is_chrome()) + .field("chrome_rules_enabled", &self.chrome_rules_enabled()) .field( "base", &DebugURI(self.as_ref().mBaseURI.raw::()),