mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
stylo: Pass parser URL data in Servo_DeclarationBlock_SetProperty*
MozReview-Commit-ID: EVk4aEoyiXv
This commit is contained in:
parent
14d8eb93ba
commit
eda6a4fc4f
6 changed files with 132 additions and 25 deletions
|
@ -317,6 +317,7 @@ mod bindings {
|
||||||
"FontFamilyType",
|
"FontFamilyType",
|
||||||
"FragmentOrURL",
|
"FragmentOrURL",
|
||||||
"FrameRequestCallback",
|
"FrameRequestCallback",
|
||||||
|
"GeckoParserExtraData",
|
||||||
"gfxAlternateValue",
|
"gfxAlternateValue",
|
||||||
"gfxFontFeature",
|
"gfxFontFeature",
|
||||||
"gfxFontVariation",
|
"gfxFontVariation",
|
||||||
|
@ -538,6 +539,7 @@ mod bindings {
|
||||||
"RawServoDeclarationBlock",
|
"RawServoDeclarationBlock",
|
||||||
"RawGeckoPresContext",
|
"RawGeckoPresContext",
|
||||||
"RawGeckoPresContextOwned",
|
"RawGeckoPresContextOwned",
|
||||||
|
"GeckoParserExtraData",
|
||||||
"RefPtr",
|
"RefPtr",
|
||||||
"ThreadSafeURIHolder",
|
"ThreadSafeURIHolder",
|
||||||
"ThreadSafePrincipalHolder",
|
"ThreadSafePrincipalHolder",
|
||||||
|
|
|
@ -14,6 +14,7 @@ use gecko_bindings::structs::RawServoAnimationValue;
|
||||||
use gecko_bindings::structs::RawServoDeclarationBlock;
|
use gecko_bindings::structs::RawServoDeclarationBlock;
|
||||||
use gecko_bindings::structs::RawGeckoPresContext;
|
use gecko_bindings::structs::RawGeckoPresContext;
|
||||||
use gecko_bindings::structs::RawGeckoPresContextOwned;
|
use gecko_bindings::structs::RawGeckoPresContextOwned;
|
||||||
|
use gecko_bindings::structs::GeckoParserExtraData;
|
||||||
use gecko_bindings::structs::RefPtr;
|
use gecko_bindings::structs::RefPtr;
|
||||||
use gecko_bindings::structs::ThreadSafeURIHolder;
|
use gecko_bindings::structs::ThreadSafeURIHolder;
|
||||||
use gecko_bindings::structs::ThreadSafePrincipalHolder;
|
use gecko_bindings::structs::ThreadSafePrincipalHolder;
|
||||||
|
@ -1339,10 +1340,8 @@ extern "C" {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_ParseProperty(property: *const nsACString_internal,
|
pub fn Servo_ParseProperty(property: *const nsACString_internal,
|
||||||
value: *const nsACString_internal,
|
value: *const nsACString_internal,
|
||||||
base_url: *const nsACString_internal,
|
base: *const nsACString_internal,
|
||||||
base: *mut ThreadSafeURIHolder,
|
data: *const GeckoParserExtraData)
|
||||||
referrer: *mut ThreadSafeURIHolder,
|
|
||||||
principal: *mut ThreadSafePrincipalHolder)
|
|
||||||
-> RawServoDeclarationBlockStrong;
|
-> RawServoDeclarationBlockStrong;
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -1466,7 +1465,12 @@ extern "C" {
|
||||||
*const nsACString_internal,
|
*const nsACString_internal,
|
||||||
value:
|
value:
|
||||||
*const nsACString_internal,
|
*const nsACString_internal,
|
||||||
is_important: bool) -> bool;
|
is_important: bool,
|
||||||
|
base:
|
||||||
|
*const nsACString_internal,
|
||||||
|
data:
|
||||||
|
*const GeckoParserExtraData)
|
||||||
|
-> bool;
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_DeclarationBlock_SetPropertyById(declarations:
|
pub fn Servo_DeclarationBlock_SetPropertyById(declarations:
|
||||||
|
@ -1474,7 +1478,12 @@ extern "C" {
|
||||||
property: nsCSSPropertyID,
|
property: nsCSSPropertyID,
|
||||||
value:
|
value:
|
||||||
*const nsACString_internal,
|
*const nsACString_internal,
|
||||||
is_important: bool) -> bool;
|
is_important: bool,
|
||||||
|
base:
|
||||||
|
*const nsACString_internal,
|
||||||
|
data:
|
||||||
|
*const GeckoParserExtraData)
|
||||||
|
-> bool;
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_DeclarationBlock_RemoveProperty(declarations:
|
pub fn Servo_DeclarationBlock_RemoveProperty(declarations:
|
||||||
|
|
|
@ -25749,6 +25749,40 @@ pub mod root {
|
||||||
impl Clone for ServoBundledURI {
|
impl Clone for ServoBundledURI {
|
||||||
fn clone(&self) -> Self { *self }
|
fn clone(&self) -> Self { *self }
|
||||||
}
|
}
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct GeckoParserExtraData {
|
||||||
|
pub mBaseURI: root::RefPtr<root::nsMainThreadPtrHolder<root::nsIURI>>,
|
||||||
|
pub mReferrer: root::RefPtr<root::nsMainThreadPtrHolder<root::nsIURI>>,
|
||||||
|
pub mPrincipal: root::RefPtr<root::nsMainThreadPtrHolder<root::nsIPrincipal>>,
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn bindgen_test_layout_GeckoParserExtraData() {
|
||||||
|
assert_eq!(::std::mem::size_of::<GeckoParserExtraData>() , 24usize ,
|
||||||
|
concat ! (
|
||||||
|
"Size of: " , stringify ! ( GeckoParserExtraData ) ));
|
||||||
|
assert_eq! (::std::mem::align_of::<GeckoParserExtraData>() , 8usize ,
|
||||||
|
concat ! (
|
||||||
|
"Alignment of " , stringify ! ( GeckoParserExtraData ) ));
|
||||||
|
assert_eq! (unsafe {
|
||||||
|
& ( * ( 0 as * const GeckoParserExtraData ) ) . mBaseURI
|
||||||
|
as * const _ as usize } , 0usize , concat ! (
|
||||||
|
"Alignment of field: " , stringify ! (
|
||||||
|
GeckoParserExtraData ) , "::" , stringify ! ( mBaseURI )
|
||||||
|
));
|
||||||
|
assert_eq! (unsafe {
|
||||||
|
& ( * ( 0 as * const GeckoParserExtraData ) ) . mReferrer
|
||||||
|
as * const _ as usize } , 8usize , concat ! (
|
||||||
|
"Alignment of field: " , stringify ! (
|
||||||
|
GeckoParserExtraData ) , "::" , stringify ! ( mReferrer )
|
||||||
|
));
|
||||||
|
assert_eq! (unsafe {
|
||||||
|
& ( * ( 0 as * const GeckoParserExtraData ) ) . mPrincipal
|
||||||
|
as * const _ as usize } , 16usize , concat ! (
|
||||||
|
"Alignment of field: " , stringify ! (
|
||||||
|
GeckoParserExtraData ) , "::" , stringify ! ( mPrincipal )
|
||||||
|
));
|
||||||
|
}
|
||||||
pub type nsMediaFeatureValueGetter =
|
pub type nsMediaFeatureValueGetter =
|
||||||
::std::option::Option<unsafe extern "C" fn(aPresContext:
|
::std::option::Option<unsafe extern "C" fn(aPresContext:
|
||||||
*mut root::nsPresContext,
|
*mut root::nsPresContext,
|
||||||
|
|
|
@ -25148,6 +25148,40 @@ pub mod root {
|
||||||
impl Clone for ServoBundledURI {
|
impl Clone for ServoBundledURI {
|
||||||
fn clone(&self) -> Self { *self }
|
fn clone(&self) -> Self { *self }
|
||||||
}
|
}
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct GeckoParserExtraData {
|
||||||
|
pub mBaseURI: root::RefPtr<root::nsMainThreadPtrHolder<root::nsIURI>>,
|
||||||
|
pub mReferrer: root::RefPtr<root::nsMainThreadPtrHolder<root::nsIURI>>,
|
||||||
|
pub mPrincipal: root::RefPtr<root::nsMainThreadPtrHolder<root::nsIPrincipal>>,
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn bindgen_test_layout_GeckoParserExtraData() {
|
||||||
|
assert_eq!(::std::mem::size_of::<GeckoParserExtraData>() , 24usize ,
|
||||||
|
concat ! (
|
||||||
|
"Size of: " , stringify ! ( GeckoParserExtraData ) ));
|
||||||
|
assert_eq! (::std::mem::align_of::<GeckoParserExtraData>() , 8usize ,
|
||||||
|
concat ! (
|
||||||
|
"Alignment of " , stringify ! ( GeckoParserExtraData ) ));
|
||||||
|
assert_eq! (unsafe {
|
||||||
|
& ( * ( 0 as * const GeckoParserExtraData ) ) . mBaseURI
|
||||||
|
as * const _ as usize } , 0usize , concat ! (
|
||||||
|
"Alignment of field: " , stringify ! (
|
||||||
|
GeckoParserExtraData ) , "::" , stringify ! ( mBaseURI )
|
||||||
|
));
|
||||||
|
assert_eq! (unsafe {
|
||||||
|
& ( * ( 0 as * const GeckoParserExtraData ) ) . mReferrer
|
||||||
|
as * const _ as usize } , 8usize , concat ! (
|
||||||
|
"Alignment of field: " , stringify ! (
|
||||||
|
GeckoParserExtraData ) , "::" , stringify ! ( mReferrer )
|
||||||
|
));
|
||||||
|
assert_eq! (unsafe {
|
||||||
|
& ( * ( 0 as * const GeckoParserExtraData ) ) . mPrincipal
|
||||||
|
as * const _ as usize } , 16usize , concat ! (
|
||||||
|
"Alignment of field: " , stringify ! (
|
||||||
|
GeckoParserExtraData ) , "::" , stringify ! ( mPrincipal )
|
||||||
|
));
|
||||||
|
}
|
||||||
pub type nsMediaFeatureValueGetter =
|
pub type nsMediaFeatureValueGetter =
|
||||||
::std::option::Option<unsafe extern "C" fn(aPresContext:
|
::std::option::Option<unsafe extern "C" fn(aPresContext:
|
||||||
*mut root::nsPresContext,
|
*mut root::nsPresContext,
|
||||||
|
|
|
@ -43,6 +43,22 @@ impl Default for ParserContextExtraData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
impl ParserContextExtraData {
|
||||||
|
/// Construct from a GeckoParserExtraData
|
||||||
|
///
|
||||||
|
/// GeckoParserExtraData must live longer than this call
|
||||||
|
pub unsafe fn new(data: *const ::gecko_bindings::structs::GeckoParserExtraData) -> Self {
|
||||||
|
// the to_safe calls are safe since we trust that we have references to
|
||||||
|
// real Gecko refptrs. The dereferencing of data is safe because this function
|
||||||
|
// is expected to be called with a `data` living longer than this function.
|
||||||
|
unsafe { ParserContextExtraData {
|
||||||
|
base: Some((*data).mBaseURI.to_safe()),
|
||||||
|
referrer: Some((*data).mReferrer.to_safe()),
|
||||||
|
principal: Some((*data).mPrincipal.to_safe()),
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
}
|
||||||
/// The data that the parser needs from outside in order to parse a stylesheet.
|
/// The data that the parser needs from outside in order to parse a stylesheet.
|
||||||
pub struct ParserContext<'a> {
|
pub struct ParserContext<'a> {
|
||||||
/// The `Origin` of the stylesheet, whether it's a user, author or
|
/// The `Origin` of the stylesheet, whether it's a user, author or
|
||||||
|
|
|
@ -681,11 +681,21 @@ pub extern "C" fn Servo_StyleSet_Drop(data: RawServoStyleSetOwned) -> () {
|
||||||
let _ = data.into_box::<PerDocumentStyleData>();
|
let _ = data.into_box::<PerDocumentStyleData>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Must be a macro since we need to store the base_url on the stack somewhere
|
||||||
|
/// Initializes the data needed for constructing a ParserContext from
|
||||||
|
/// Gecko-side values
|
||||||
|
macro_rules! make_context {
|
||||||
|
(($base:ident, $data:ident) => ($base_url:ident, $extra_data:ident)) => {
|
||||||
|
let base_str = unsafe { $base.as_ref().unwrap().as_str_unchecked() };
|
||||||
|
let $base_url = ServoUrl::parse(base_str).unwrap();
|
||||||
|
let $extra_data = unsafe { ParserContextExtraData::new($data) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_ParseProperty(property: *const nsACString, value: *const nsACString,
|
pub extern "C" fn Servo_ParseProperty(property: *const nsACString, value: *const nsACString,
|
||||||
base_url: *const nsACString, base: *mut ThreadSafeURIHolder,
|
base: *const nsACString,
|
||||||
referrer: *mut ThreadSafeURIHolder,
|
data: *const structs::GeckoParserExtraData)
|
||||||
principal: *mut ThreadSafePrincipalHolder)
|
|
||||||
-> RawServoDeclarationBlockStrong {
|
-> RawServoDeclarationBlockStrong {
|
||||||
let name = unsafe { property.as_ref().unwrap().as_str_unchecked() };
|
let name = unsafe { property.as_ref().unwrap().as_str_unchecked() };
|
||||||
let id = if let Ok(id) = PropertyId::parse(name.into()) {
|
let id = if let Ok(id) = PropertyId::parse(name.into()) {
|
||||||
|
@ -694,15 +704,11 @@ pub extern "C" fn Servo_ParseProperty(property: *const nsACString, value: *const
|
||||||
return RawServoDeclarationBlockStrong::null()
|
return RawServoDeclarationBlockStrong::null()
|
||||||
};
|
};
|
||||||
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
||||||
let base_str = unsafe { base_url.as_ref().unwrap().as_str_unchecked() };
|
|
||||||
let base_url = ServoUrl::parse(base_str).unwrap();
|
|
||||||
let extra_data = unsafe { ParserContextExtraData {
|
|
||||||
base: Some(GeckoArcURI::new(base)),
|
|
||||||
referrer: Some(GeckoArcURI::new(referrer)),
|
|
||||||
principal: Some(GeckoArcPrincipal::new(principal)),
|
|
||||||
}};
|
|
||||||
|
|
||||||
let context = ParserContext::new_with_extra_data(Origin::Author, &base_url,
|
make_context!((base, data) => (base_url, extra_data));
|
||||||
|
|
||||||
|
let context = ParserContext::new_with_extra_data(Origin::Author,
|
||||||
|
&base_url,
|
||||||
Box::new(StdoutErrorReporter),
|
Box::new(StdoutErrorReporter),
|
||||||
extra_data);
|
extra_data);
|
||||||
|
|
||||||
|
@ -819,11 +825,11 @@ pub extern "C" fn Servo_DeclarationBlock_GetPropertyIsImportant(declarations: Ra
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_property(declarations: RawServoDeclarationBlockBorrowed, property_id: PropertyId,
|
fn set_property(declarations: RawServoDeclarationBlockBorrowed, property_id: PropertyId,
|
||||||
value: *const nsACString, is_important: bool) -> bool {
|
value: *const nsACString, is_important: bool,
|
||||||
|
base: *const nsACString, data: *const structs::GeckoParserExtraData) -> bool {
|
||||||
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
||||||
// FIXME Needs real URL and ParserContextExtraData.
|
|
||||||
let base_url = &*DUMMY_BASE_URL;
|
make_context!((base, data) => (base_url, extra_data));
|
||||||
let extra_data = ParserContextExtraData::default();
|
|
||||||
if let Ok(parsed) = parse_one_declaration(property_id, value, &base_url,
|
if let Ok(parsed) = parse_one_declaration(property_id, value, &base_url,
|
||||||
Box::new(StdoutErrorReporter), extra_data) {
|
Box::new(StdoutErrorReporter), extra_data) {
|
||||||
let mut declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations).write();
|
let mut declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations).write();
|
||||||
|
@ -841,15 +847,21 @@ fn set_property(declarations: RawServoDeclarationBlockBorrowed, property_id: Pro
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_DeclarationBlock_SetProperty(declarations: RawServoDeclarationBlockBorrowed,
|
pub extern "C" fn Servo_DeclarationBlock_SetProperty(declarations: RawServoDeclarationBlockBorrowed,
|
||||||
property: *const nsACString, value: *const nsACString,
|
property: *const nsACString, value: *const nsACString,
|
||||||
is_important: bool) -> bool {
|
is_important: bool,
|
||||||
set_property(declarations, get_property_id_from_property!(property, false), value, is_important)
|
base: *const nsACString,
|
||||||
|
data: *const structs::GeckoParserExtraData) -> bool {
|
||||||
|
set_property(declarations, get_property_id_from_property!(property, false),
|
||||||
|
value, is_important, base, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_DeclarationBlock_SetPropertyById(declarations: RawServoDeclarationBlockBorrowed,
|
pub extern "C" fn Servo_DeclarationBlock_SetPropertyById(declarations: RawServoDeclarationBlockBorrowed,
|
||||||
property: nsCSSPropertyID, value: *const nsACString,
|
property: nsCSSPropertyID, value: *const nsACString,
|
||||||
is_important: bool) -> bool {
|
is_important: bool,
|
||||||
set_property(declarations, get_property_id_from_nscsspropertyid!(property, false), value, is_important)
|
base: *const nsACString,
|
||||||
|
data: *const structs::GeckoParserExtraData) -> bool {
|
||||||
|
set_property(declarations, get_property_id_from_nscsspropertyid!(property, false),
|
||||||
|
value, is_important, base, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_property(declarations: RawServoDeclarationBlockBorrowed, property_id: PropertyId) {
|
fn remove_property(declarations: RawServoDeclarationBlockBorrowed, property_id: PropertyId) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue