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-15 21:26:57 +00:00
Родитель 9f86a56cd1
Коммит 8798b5286b
5 изменённых файлов: 9 добавлений и 9 удалений

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

@ -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,
@ -73,8 +74,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>()),