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
This commit is contained in:
Emilio Cobos Álvarez 2021-01-16 18:26:52 +00:00
Родитель 4a781c4a41
Коммит 2e092ef47c
6 изменённых файлов: 14 добавлений и 12 удалений

Просмотреть файл

@ -1142,7 +1142,7 @@ already_AddRefed<StyleSheet> StyleSheet::CreateEmptyChildSheet(
// (3) The stylesheet is a chrome stylesheet, since those can use // (3) The stylesheet is a chrome stylesheet, since those can use
// -moz-bool-pref, which needs to access the pref service, which is not // -moz-bool-pref, which needs to access the pref service, which is not
// threadsafe. // 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 // If the browser is recording CSS errors, we need to use the sequential path
// because the parallel path doesn't support that. // because the parallel path doesn't support that.
Document* doc = aLoader.GetDocument(); 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 // Note that UA stylesheets can also use -moz-bool-pref, but those are always
// parsed sync. // parsed sync.
if (dom::IsChromeURI(aSheetURI)) { if (aUrlData->ChromeRulesEnabled()) {
return false; return false;
} }
@ -1179,7 +1179,7 @@ RefPtr<StyleSheetParsePromise> StyleSheet::ParseSheet(
: StyleAllowImportRules::Yes; : StyleAllowImportRules::Yes;
const bool shouldRecordCounters = const bool shouldRecordCounters =
aLoader.GetDocument() && aLoader.GetDocument()->GetStyleUseCounters(); aLoader.GetDocument() && aLoader.GetDocument()->GetStyleUseCounters();
if (!AllowParallelParse(aLoader, GetSheetURI())) { if (!AllowParallelParse(aLoader, Inner().mURLData)) {
UniquePtr<StyleUseCounters> counters = UniquePtr<StyleUseCounters> counters =
shouldRecordCounters ? Servo_UseCounters_Create().Consume() : nullptr; shouldRecordCounters ? Servo_UseCounters_Create().Consume() : nullptr;

Просмотреть файл

@ -27,7 +27,7 @@ void URLExtraData::Init() {
sDummyChrome = sDummyChrome =
new URLExtraData(baseURI.forget(), referrerInfo.forget(), new URLExtraData(baseURI.forget(), referrerInfo.forget(),
NullPrincipal::CreateWithoutOriginAttributes()); NullPrincipal::CreateWithoutOriginAttributes());
sDummyChrome->mIsChrome = true; sDummyChrome->mChromeRulesEnabled = true;
} }
/* static */ /* static */

Просмотреть файл

@ -34,7 +34,8 @@ struct URLExtraData {
// When we hold the URI data of a style sheet, referrer is always // When we hold the URI data of a style sheet, referrer is always
// equal to the sheet URI. // equal to the sheet URI.
nsCOMPtr<nsIURI> referrer = mReferrerInfo->GetOriginalReferrer(); nsCOMPtr<nsIURI> referrer = mReferrerInfo->GetOriginalReferrer();
mIsChrome = referrer ? dom::IsChromeURI(referrer) : false; mChromeRulesEnabled = referrer && (referrer->SchemeIs("chrome") ||
referrer->SchemeIs("resource"));
} }
URLExtraData(nsIURI* aBaseURI, nsIReferrerInfo* aReferrerInfo, URLExtraData(nsIURI* aBaseURI, nsIReferrerInfo* aReferrerInfo,
@ -48,6 +49,8 @@ struct URLExtraData {
nsIReferrerInfo* ReferrerInfo() const { return mReferrerInfo; } nsIReferrerInfo* ReferrerInfo() const { return mReferrerInfo; }
nsIPrincipal* Principal() const { return mPrincipal; } nsIPrincipal* Principal() const { return mPrincipal; }
bool ChromeRulesEnabled() const { return mChromeRulesEnabled; }
static URLExtraData* Dummy() { static URLExtraData* Dummy() {
MOZ_ASSERT(sDummy); MOZ_ASSERT(sDummy);
return sDummy; return sDummy;
@ -73,8 +76,7 @@ struct URLExtraData {
nsCOMPtr<nsIReferrerInfo> mReferrerInfo; nsCOMPtr<nsIReferrerInfo> mReferrerInfo;
nsCOMPtr<nsIPrincipal> mPrincipal; nsCOMPtr<nsIPrincipal> mPrincipal;
// True if referrer is a chrome:// URI. bool mChromeRulesEnabled;
bool mIsChrome;
static StaticRefPtr<URLExtraData> sDummy; static StaticRefPtr<URLExtraData> sDummy;
static StaticRefPtr<URLExtraData> sDummyChrome; static StaticRefPtr<URLExtraData> sDummyChrome;

Просмотреть файл

@ -140,7 +140,7 @@ impl<'a> ParserContext<'a> {
/// Returns whether chrome-only rules should be parsed. /// Returns whether chrome-only rules should be parsed.
#[inline] #[inline]
pub fn chrome_rules_enabled(&self) -> bool { 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. /// Whether we're in a user-agent stylesheet or chrome rules are enabled.

Просмотреть файл

@ -75,7 +75,7 @@ impl<'a> SelectorParser<'a> {
/// Whether we're parsing selectors in a stylesheet that has chrome /// Whether we're parsing selectors in a stylesheet that has chrome
/// privilege. /// privilege.
pub fn chrome_rules_enabled(&self) -> bool { 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
} }
} }

Просмотреть файл

@ -156,8 +156,8 @@ impl UrlExtraData {
/// True if this URL scheme is chrome. /// True if this URL scheme is chrome.
#[inline] #[inline]
pub fn is_chrome(&self) -> bool { pub fn chrome_rules_enabled(&self) -> bool {
self.as_ref().mIsChrome self.as_ref().mChromeRulesEnabled
} }
/// Create a reference to this `UrlExtraData` from a reference to pointer. /// Create a reference to this `UrlExtraData` from a reference to pointer.
@ -215,7 +215,7 @@ impl fmt::Debug for UrlExtraData {
formatter formatter
.debug_struct("URLExtraData") .debug_struct("URLExtraData")
.field("is_chrome", &self.is_chrome()) .field("chrome_rules_enabled", &self.chrome_rules_enabled())
.field( .field(
"base", "base",
&DebugURI(self.as_ref().mBaseURI.raw::<structs::nsIURI>()), &DebugURI(self.as_ref().mBaseURI.raw::<structs::nsIURI>()),