stylo: Honor CallerType for media query parsing.

So that matchMedia can parse internal stuff in Chrome code.

Bug: 1410074
Reviewed-by: xidorn
MozReview-Commit-ID: 6M4HHqVJ1dp
This commit is contained in:
Emilio Cobos Álvarez 2017-10-19 16:16:02 +02:00
parent 5da0a8d872
commit 21b314e633
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 37 additions and 10 deletions

View file

@ -14,6 +14,7 @@ use gecko_bindings::structs::mozilla::css::ErrorReporter;
use gecko_bindings::structs::mozilla::css::ImageValue;
use gecko_bindings::structs::mozilla::css::URLValue;
use gecko_bindings::structs::mozilla::css::URLValueData;
use gecko_bindings::structs::mozilla::dom::CallerType;
use gecko_bindings::structs::mozilla::AnonymousCounterStyle;
use gecko_bindings::structs::mozilla::AtomArray;
use gecko_bindings::structs::mozilla::MallocSizeOf;
@ -2868,7 +2869,8 @@ extern "C" {
}
extern "C" {
pub fn Servo_MediaList_SetText(list: RawServoMediaListBorrowed,
text: *const nsACString);
text: *const nsACString,
aCallerType: CallerType);
}
extern "C" {
pub fn Servo_MediaList_GetLength(list: RawServoMediaListBorrowed) -> u32;

View file

@ -78,7 +78,7 @@ use style::gecko_bindings::bindings::nsTArrayBorrowed_uintptr_t;
use style::gecko_bindings::bindings::nsTimingFunctionBorrowed;
use style::gecko_bindings::bindings::nsTimingFunctionBorrowedMut;
use style::gecko_bindings::structs;
use style::gecko_bindings::structs::{CSSPseudoElementType, CompositeOperation};
use style::gecko_bindings::structs::{CallerType, CSSPseudoElementType, CompositeOperation};
use style::gecko_bindings::structs::{Loader, LoaderReusableStyleSheets};
use style::gecko_bindings::structs::{RawServoStyleRule, ServoStyleContextStrong, RustString};
use style::gecko_bindings::structs::{ServoStyleSheet, SheetParsingMode, nsAtom, nsCSSPropertyID};
@ -2793,16 +2793,41 @@ pub extern "C" fn Servo_MediaList_GetText(list: RawServoMediaListBorrowed, resul
}
#[no_mangle]
pub extern "C" fn Servo_MediaList_SetText(list: RawServoMediaListBorrowed, text: *const nsACString) {
let text = unsafe { text.as_ref().unwrap().as_str_unchecked() };
pub unsafe extern "C" fn Servo_MediaList_SetText(
list: RawServoMediaListBorrowed,
text: *const nsACString,
caller_type: CallerType,
) {
let text = (*text).as_str_unchecked();
let mut input = ParserInput::new(&text);
let mut parser = Parser::new(&mut input);
let url_data = unsafe { dummy_url_data() };
let context = ParserContext::new_for_cssom(url_data, Some(CssRuleType::Media),
let url_data = dummy_url_data();
// TODO(emilio): If the need for `CallerType` appears in more places,
// consider adding an explicit member in `ParserContext` instead of doing
// this (or adding a dummy "chrome://" url data).
//
// For media query parsing it's effectively the same, so for now...
let origin = match caller_type {
CallerType::System => Origin::UserAgent,
CallerType::NonSystem => Origin::Author,
};
let context = ParserContext::new(
origin,
url_data,
Some(CssRuleType::Media),
PARSING_MODE_DEFAULT,
QuirksMode::NoQuirks);
QuirksMode::NoQuirks,
);
write_locked_arc(list, |list: &mut MediaList| {
*list = parse_media_query_list(&context, &mut parser, &NullReporter);
*list = parse_media_query_list(
&context,
&mut parser,
&NullReporter,
);
})
}