mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: Allow matches() / querySelector() / etc on chrome docs to access chrome-only selectors. r=boris
Without this some tests fail with the previous patch because code like: https://searchfox.org/mozilla-central/rev/267682a8f45221bf0bfe999d4a0239706a43bc56/browser/base/content/browser-gestureSupport.js#651 starts throwing. Unfortunately I had missed that on my try run, because the error message didn't include that exception (it seemed like an intermittent browser-chrome failure instead). We could expose a ChromeOnly API for this, but this seems better. This fixes it trivially, and also removes the "no url data" situation from the selector parser, which is nice. Differential Revision: https://phabricator.services.mozilla.com/D130818
This commit is contained in:
parent
a0e29d7032
commit
04282ff04c
3 changed files with 9 additions and 8 deletions
|
@ -46,7 +46,7 @@ pub struct SelectorParser<'a> {
|
|||
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>,
|
||||
pub url_data: &'a UrlExtraData,
|
||||
}
|
||||
|
||||
impl<'a> SelectorParser<'a> {
|
||||
|
@ -54,14 +54,15 @@ impl<'a> SelectorParser<'a> {
|
|||
/// account namespaces.
|
||||
///
|
||||
/// This is used for some DOM APIs like `querySelector`.
|
||||
pub fn parse_author_origin_no_namespace(
|
||||
input: &str,
|
||||
) -> Result<SelectorList<SelectorImpl>, ParseError> {
|
||||
pub fn parse_author_origin_no_namespace<'i>(
|
||||
input: &'i str,
|
||||
url_data: &UrlExtraData,
|
||||
) -> Result<SelectorList<SelectorImpl>, ParseError<'i>> {
|
||||
let namespaces = Namespaces::default();
|
||||
let parser = SelectorParser {
|
||||
stylesheet_origin: Origin::Author,
|
||||
namespaces: &namespaces,
|
||||
url_data: None,
|
||||
url_data,
|
||||
};
|
||||
let mut input = ParserInput::new(input);
|
||||
SelectorList::parse(&parser, &mut CssParser::new(&mut input))
|
||||
|
@ -75,7 +76,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.chrome_rules_enabled()) ||
|
||||
self.url_data.chrome_rules_enabled() ||
|
||||
self.stylesheet_origin == Origin::User
|
||||
}
|
||||
}
|
||||
|
|
|
@ -710,7 +710,7 @@ impl<'a, 'b, 'i> QualifiedRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
|||
let selector_parser = SelectorParser {
|
||||
stylesheet_origin: self.context.stylesheet_origin,
|
||||
namespaces: self.namespaces,
|
||||
url_data: Some(self.context.url_data),
|
||||
url_data: self.context.url_data,
|
||||
};
|
||||
let selectors = SelectorList::parse(&selector_parser, input)?;
|
||||
if self.context.error_reporting_enabled() {
|
||||
|
|
|
@ -335,7 +335,7 @@ impl RawSelector {
|
|||
let parser = SelectorParser {
|
||||
namespaces,
|
||||
stylesheet_origin: context.stylesheet_origin,
|
||||
url_data: Some(context.url_data),
|
||||
url_data: context.url_data,
|
||||
};
|
||||
|
||||
#[allow(unused_variables)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue