style: Introduce Chrome UI privilege for parsers

The motivation is that Chrome XBL stylesheets can be parsed under author
level, but we allow some event-state pseudo classes like
:-moz-handled-clicktoplay to be used.

Also synchronize the privilege of pseudo classes in
non_ts_pseudo_class_list.rs and nsCSSPseudoClassList.h (except :fullscreen).

MozReview-Commit-ID: 8fUjjC8hbQO
This commit is contained in:
Ting-Yu Lin 2017-07-31 16:03:51 +08:00
parent fd3b399d26
commit 585c00f235
8 changed files with 63 additions and 23 deletions

View file

@ -11,7 +11,7 @@ use selectors::Element;
use selectors::parser::SelectorList;
use std::fmt::Debug;
use style_traits::ParseError;
use stylesheets::{Origin, Namespaces};
use stylesheets::{Origin, Namespaces, UrlExtraData};
/// A convenient alias for the type that represents an attribute value used for
/// selector parser implementation.
@ -52,6 +52,9 @@ pub struct SelectorParser<'a> {
pub stylesheet_origin: Origin,
/// The namespace set of the stylesheet.
pub namespaces: &'a Namespaces,
/// The extra URL data of the stylesheet, which is used to look up
/// whether we are parsing a chrome:// URL style sheet.
pub url_data: Option<&'a UrlExtraData>,
}
impl<'a> SelectorParser<'a> {
@ -65,6 +68,7 @@ impl<'a> SelectorParser<'a> {
let parser = SelectorParser {
stylesheet_origin: Origin::Author,
namespaces: &namespaces,
url_data: None,
};
let mut input = ParserInput::new(input);
SelectorList::parse(&parser, &mut CssParser::new(&mut input))
@ -74,6 +78,12 @@ impl<'a> SelectorParser<'a> {
pub fn in_user_agent_stylesheet(&self) -> bool {
matches!(self.stylesheet_origin, Origin::UserAgent)
}
/// Whether we're parsing selectors in a stylesheet that has chrome
/// privilege.
pub fn in_chrome_stylesheet(&self) -> bool {
self.url_data.map_or(false, |d| d.is_chrome())
}
}
/// This enumeration determines if a pseudo-element is eagerly cascaded or not.