зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1740230 - 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:
Родитель
1956ff62e0
Коммит
bd406d8841
|
@ -2867,7 +2867,15 @@ const RawServoSelectorList* nsINode::ParseSelectorList(
|
|||
RawServoSelectorList* list = cache.GetListOrInsertFrom(aSelectorString, [&] {
|
||||
// Note that we want to cache even if null was returned, because we
|
||||
// want to cache the "This is not a valid selector" result.
|
||||
return Servo_SelectorList_Parse(&aSelectorString).Consume();
|
||||
//
|
||||
// NOTE(emilio): Off-hand, getting a CallerType here might seem like a
|
||||
// better idea than using IsDocumentURISchemeChrome(), but that would mean
|
||||
// that we'd need to key the selector cache by that.
|
||||
// IsDocumentURISchemeChrome() gives us the same semantics as any inline
|
||||
// style associated to a document, which seems reasonable.
|
||||
return Servo_SelectorList_Parse(&aSelectorString,
|
||||
doc->IsDocumentURISchemeChrome())
|
||||
.Consume();
|
||||
});
|
||||
|
||||
if (!list) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -704,7 +704,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)]
|
||||
|
|
|
@ -2506,7 +2506,7 @@ pub extern "C" fn Servo_StyleRule_SetSelectorText(
|
|||
let parser = SelectorParser {
|
||||
stylesheet_origin: contents.origin,
|
||||
namespaces: &namespaces,
|
||||
url_data: Some(&url_data),
|
||||
url_data: &url_data,
|
||||
};
|
||||
|
||||
let mut parser_input = ParserInput::new(&value_str);
|
||||
|
@ -6638,11 +6638,18 @@ pub extern "C" fn Servo_HasPendingRestyleAncestor(
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn Servo_SelectorList_Parse(
|
||||
selector_list: &nsACString,
|
||||
is_chrome: bool,
|
||||
) -> OwnedOrNull<RawServoSelectorList> {
|
||||
use style::selector_parser::SelectorParser;
|
||||
|
||||
let url_data = UrlExtraData::from_ptr_ref(if is_chrome {
|
||||
&DUMMY_CHROME_URL_DATA
|
||||
} else {
|
||||
&DUMMY_URL_DATA
|
||||
});
|
||||
|
||||
let input = selector_list.as_str_unchecked();
|
||||
let selector_list = match SelectorParser::parse_author_origin_no_namespace(&input) {
|
||||
let selector_list = match SelectorParser::parse_author_origin_no_namespace(&input, url_data) {
|
||||
Ok(selector_list) => selector_list,
|
||||
Err(..) => return OwnedOrNull::null(),
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче