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
// -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<StyleSheetParsePromise> StyleSheet::ParseSheet(
: StyleAllowImportRules::Yes;
const bool shouldRecordCounters =
aLoader.GetDocument() && aLoader.GetDocument()->GetStyleUseCounters();
if (!AllowParallelParse(aLoader, GetSheetURI())) {
if (!AllowParallelParse(aLoader, Inner().mURLData)) {
UniquePtr<StyleUseCounters> counters =
shouldRecordCounters ? Servo_UseCounters_Create().Consume() : nullptr;

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

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

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

@ -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<nsIURI> 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<nsIReferrerInfo> mReferrerInfo;
nsCOMPtr<nsIPrincipal> mPrincipal;
// True if referrer is a chrome:// URI.
bool mIsChrome;
bool mChromeRulesEnabled;
static StaticRefPtr<URLExtraData> sDummy;
static StaticRefPtr<URLExtraData> sDummyChrome;

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

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

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

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

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

@ -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::<structs::nsIURI>()),