Create URLExtraData for holding base uri, referrer, and principal.

This commit is contained in:
Xidorn Quan 2017-04-03 13:32:21 +10:00
parent a31271b07f
commit 0a97a0df0c
9 changed files with 35 additions and 82 deletions

View file

@ -367,7 +367,6 @@ mod bindings {
"nsCursorImage", "nsCursorImage",
"nsFont", "nsFont",
"nsIAtom", "nsIAtom",
"nsIURI",
"nsMainThreadPtrHandle", "nsMainThreadPtrHandle",
"nsMainThreadPtrHolder", "nsMainThreadPtrHolder",
"nsMargin", "nsMargin",
@ -604,10 +603,8 @@ mod bindings {
"RawGeckoPresContext", "RawGeckoPresContext",
"RawGeckoPresContextOwned", "RawGeckoPresContextOwned",
"RawGeckoStyleAnimationList", "RawGeckoStyleAnimationList",
"GeckoParserExtraData", "RawGeckoURLExtraData",
"RefPtr", "RefPtr",
"ThreadSafeURIHolder",
"ThreadSafePrincipalHolder",
"CSSPseudoClassType", "CSSPseudoClassType",
"TraversalRootBehavior", "TraversalRootBehavior",
"FontFamilyList", "FontFamilyList",
@ -630,7 +627,6 @@ mod bindings {
"nsCursorImage", "nsCursorImage",
"nsFont", "nsFont",
"nsIAtom", "nsIAtom",
"nsIURI",
"nsMediaFeature", "nsMediaFeature",
"nsRestyleHint", "nsRestyleHint",
"nsStyleBackground", "nsStyleBackground",

View file

@ -5,8 +5,8 @@
//! Common handling for the specified value CSS url() values. //! Common handling for the specified value CSS url() values.
use cssparser::CssStringWriter; use cssparser::CssStringWriter;
use gecko_bindings::structs::ServoBundledURI; use gecko_bindings::structs::{ServoBundledURI, URLExtraData};
use gecko_bindings::sugar::refptr::{GeckoArcPrincipal, GeckoArcURI}; use gecko_bindings::sugar::refptr::RefPtr;
use parser::ParserContext; use parser::ParserContext;
use std::borrow::Cow; use std::borrow::Cow;
use std::fmt::{self, Write}; use std::fmt::{self, Write};
@ -22,12 +22,8 @@ pub struct SpecifiedUrl {
/// really large. /// really large.
serialization: Arc<String>, serialization: Arc<String>,
/// The base URI. /// The URL extra data.
pub base: GeckoArcURI, pub extra_data: RefPtr<URLExtraData>,
/// The referrer.
pub referrer: GeckoArcURI,
/// The principal that originated this URI.
pub principal: GeckoArcPrincipal,
} }
impl SpecifiedUrl { impl SpecifiedUrl {
@ -39,7 +35,7 @@ impl SpecifiedUrl {
context: &ParserContext) context: &ParserContext)
-> Result<Self, ()> { -> Result<Self, ()> {
let extra = &context.extra_data; let extra = &context.extra_data;
if extra.base.is_none() || extra.referrer.is_none() || extra.principal.is_none() { if extra.data.is_none() {
// FIXME(heycam) should ensure we always have a principal, etc., // FIXME(heycam) should ensure we always have a principal, etc.,
// when parsing style attributes and re-parsing due to CSS // when parsing style attributes and re-parsing due to CSS
// Variables. // Variables.
@ -49,9 +45,7 @@ impl SpecifiedUrl {
Ok(SpecifiedUrl { Ok(SpecifiedUrl {
serialization: Arc::new(url.into_owned()), serialization: Arc::new(url.into_owned()),
base: extra.base.as_ref().unwrap().clone(), extra_data: extra.data.as_ref().unwrap().clone(),
referrer: extra.referrer.as_ref().unwrap().clone(),
principal: extra.principal.as_ref().unwrap().clone(),
}) })
} }
@ -88,9 +82,7 @@ impl SpecifiedUrl {
ServoBundledURI { ServoBundledURI {
mURLString: ptr, mURLString: ptr,
mURLStringLength: len as u32, mURLStringLength: len as u32,
mBaseURI: self.base.get(), mExtraData: self.extra_data.get(),
mReferrer: self.referrer.get(),
mPrincipal: self.principal.get(),
} }
} }
} }

View file

@ -261,12 +261,9 @@ macro_rules! impl_threadsafe_refcount {
); );
} }
impl_threadsafe_refcount!(::gecko_bindings::structs::ThreadSafePrincipalHolder, impl_threadsafe_refcount!(::gecko_bindings::structs::RawGeckoURLExtraData,
Gecko_AddRefPrincipalArbitraryThread, Gecko_AddRefURLExtraDataArbitraryThread,
Gecko_ReleasePrincipalArbitraryThread); Gecko_ReleaseURLExtraDataArbitraryThread);
impl_threadsafe_refcount!(::gecko_bindings::structs::ThreadSafeURIHolder,
Gecko_AddRefURIArbitraryThread,
Gecko_ReleaseURIArbitraryThread);
impl_threadsafe_refcount!(::gecko_bindings::structs::nsStyleQuoteValues, impl_threadsafe_refcount!(::gecko_bindings::structs::nsStyleQuoteValues,
Gecko_AddRefQuoteValuesArbitraryThread, Gecko_AddRefQuoteValuesArbitraryThread,
Gecko_ReleaseQuoteValuesArbitraryThread); Gecko_ReleaseQuoteValuesArbitraryThread);
@ -276,10 +273,3 @@ impl_threadsafe_refcount!(::gecko_bindings::structs::nsCSSValueSharedList,
impl_threadsafe_refcount!(::gecko_bindings::structs::mozilla::css::URLValue, impl_threadsafe_refcount!(::gecko_bindings::structs::mozilla::css::URLValue,
Gecko_AddRefCSSURLValueArbitraryThread, Gecko_AddRefCSSURLValueArbitraryThread,
Gecko_ReleaseCSSURLValueArbitraryThread); Gecko_ReleaseCSSURLValueArbitraryThread);
/// A Gecko `ThreadSafePrincipalHolder` wrapped in a safe refcounted pointer, to
/// use during stylesheet parsing and style computation.
pub type GeckoArcPrincipal = RefPtr<::gecko_bindings::structs::ThreadSafePrincipalHolder>;
/// A Gecko `ThreadSafeURIHolder` wrapped in a safe refcounted pointer, to use
/// during stylesheet parsing and style computation.
pub type GeckoArcURI = RefPtr<::gecko_bindings::structs::ThreadSafeURIHolder>;

View file

@ -9,7 +9,9 @@
use cssparser::{Parser, SourcePosition, UnicodeRange}; use cssparser::{Parser, SourcePosition, UnicodeRange};
use error_reporting::ParseErrorReporter; use error_reporting::ParseErrorReporter;
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
use gecko_bindings::sugar::refptr::{GeckoArcPrincipal, GeckoArcURI}; use gecko_bindings::structs::URLExtraData;
#[cfg(feature = "gecko")]
use gecko_bindings::sugar::refptr::RefPtr;
use servo_url::ServoUrl; use servo_url::ServoUrl;
use style_traits::OneOrMoreCommaSeparated; use style_traits::OneOrMoreCommaSeparated;
use stylesheets::Origin; use stylesheets::Origin;
@ -21,12 +23,8 @@ pub struct ParserContextExtraData;
/// Extra data that the style backend may need to parse stylesheets. /// Extra data that the style backend may need to parse stylesheets.
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
pub struct ParserContextExtraData { pub struct ParserContextExtraData {
/// The base URI. /// The URL extra data.
pub base: Option<GeckoArcURI>, pub data: Option<RefPtr<URLExtraData>>,
/// The referrer URI.
pub referrer: Option<GeckoArcURI>,
/// The principal that loaded this stylesheet.
pub principal: Option<GeckoArcPrincipal>,
} }
#[cfg(not(feature = "gecko"))] #[cfg(not(feature = "gecko"))]
@ -39,7 +37,7 @@ impl Default for ParserContextExtraData {
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
impl Default for ParserContextExtraData { impl Default for ParserContextExtraData {
fn default() -> Self { fn default() -> Self {
ParserContextExtraData { base: None, referrer: None, principal: None } ParserContextExtraData { data: None }
} }
} }
@ -48,15 +46,10 @@ impl ParserContextExtraData {
/// Construct from a GeckoParserExtraData /// Construct from a GeckoParserExtraData
/// ///
/// GeckoParserExtraData must live longer than this call /// GeckoParserExtraData must live longer than this call
pub unsafe fn new(data: *const ::gecko_bindings::structs::GeckoParserExtraData) -> Self { pub unsafe fn new(data: *mut URLExtraData) -> Self {
// the to_safe calls are safe since we trust that we have references to ParserContextExtraData {
// real Gecko refptrs. The dereferencing of data is safe because this function data: Some(RefPtr::new(data)),
// 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.

View file

@ -2158,8 +2158,7 @@ ${helpers.predefined_type("-moz-binding", "UrlOrNone", "Either::Second(None_)",
animatable="False", animatable="False",
gecko_ffi_name="mBinding", gecko_ffi_name="mBinding",
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-binding)", spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-binding)",
disable_when_testing="True", disable_when_testing="True")}
boxed=True)}
${helpers.single_keyword("-moz-orient", ${helpers.single_keyword("-moz-orient",
"inline block horizontal vertical", "inline block horizontal vertical",

View file

@ -121,19 +121,16 @@ ${helpers.single_keyword("clip-rule", "nonzero evenodd",
${helpers.predefined_type("marker-start", "UrlOrNone", "Either::Second(None_)", ${helpers.predefined_type("marker-start", "UrlOrNone", "Either::Second(None_)",
products="gecko", products="gecko",
boxed = product == "gecko",
animatable="False", animatable="False",
spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties")} spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties")}
${helpers.predefined_type("marker-mid", "UrlOrNone", "Either::Second(None_)", ${helpers.predefined_type("marker-mid", "UrlOrNone", "Either::Second(None_)",
products="gecko", products="gecko",
boxed = product == "gecko",
animatable="False", animatable="False",
spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties")} spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties")}
${helpers.predefined_type("marker-end", "UrlOrNone", "Either::Second(None_)", ${helpers.predefined_type("marker-end", "UrlOrNone", "Either::Second(None_)",
products="gecko", products="gecko",
boxed = product == "gecko",
animatable="False", animatable="False",
spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties")} spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties")}

View file

@ -38,7 +38,6 @@ ${helpers.single_keyword("list-style-type", """
spec="https://drafts.csswg.org/css-lists/#propdef-list-style-type")} spec="https://drafts.csswg.org/css-lists/#propdef-list-style-type")}
${helpers.predefined_type("list-style-image", "UrlOrNone", "Either::Second(None_)", ${helpers.predefined_type("list-style-image", "UrlOrNone", "Either::Second(None_)",
boxed = product == "gecko",
initial_specified_value="Either::Second(None_)", animatable=False, initial_specified_value="Either::Second(None_)", animatable=False,
spec="https://drafts.csswg.org/css-lists/#propdef-list-style-image")} spec="https://drafts.csswg.org/css-lists/#propdef-list-style-image")}

View file

@ -54,16 +54,15 @@ use style::gecko_bindings::bindings::nsTimingFunctionBorrowed;
use style::gecko_bindings::bindings::nsTimingFunctionBorrowedMut; use style::gecko_bindings::bindings::nsTimingFunctionBorrowedMut;
use style::gecko_bindings::structs; use style::gecko_bindings::structs;
use style::gecko_bindings::structs::{SheetParsingMode, nsIAtom, nsCSSPropertyID}; use style::gecko_bindings::structs::{SheetParsingMode, nsIAtom, nsCSSPropertyID};
use style::gecko_bindings::structs::{ThreadSafePrincipalHolder, ThreadSafeURIHolder};
use style::gecko_bindings::structs::{nsRestyleHint, nsChangeHint, nsCSSFontFaceRule}; use style::gecko_bindings::structs::{nsRestyleHint, nsChangeHint, nsCSSFontFaceRule};
use style::gecko_bindings::structs::Loader; use style::gecko_bindings::structs::Loader;
use style::gecko_bindings::structs::RawGeckoPresContextOwned; use style::gecko_bindings::structs::RawGeckoPresContextOwned;
use style::gecko_bindings::structs::ServoStyleSheet; use style::gecko_bindings::structs::ServoStyleSheet;
use style::gecko_bindings::structs::URLExtraData;
use style::gecko_bindings::structs::nsCSSValueSharedList; use style::gecko_bindings::structs::nsCSSValueSharedList;
use style::gecko_bindings::structs::nsresult; use style::gecko_bindings::structs::nsresult;
use style::gecko_bindings::sugar::ownership::{FFIArcHelpers, HasFFI, HasArcFFI, HasBoxFFI}; use style::gecko_bindings::sugar::ownership::{FFIArcHelpers, HasFFI, HasArcFFI, HasBoxFFI};
use style::gecko_bindings::sugar::ownership::{HasSimpleFFI, Strong}; use style::gecko_bindings::sugar::ownership::{HasSimpleFFI, Strong};
use style::gecko_bindings::sugar::refptr::{GeckoArcPrincipal, GeckoArcURI};
use style::gecko_properties::{self, style_structs}; use style::gecko_properties::{self, style_structs};
use style::keyframes::KeyframesStepValue; use style::keyframes::KeyframesStepValue;
use style::media_queries::{MediaList, parse_media_query_list}; use style::media_queries::{MediaList, parse_media_query_list};
@ -331,9 +330,7 @@ pub extern "C" fn Servo_StyleSheet_FromUTF8Bytes(loader: *mut Loader,
data: *const nsACString, data: *const nsACString,
mode: SheetParsingMode, mode: SheetParsingMode,
base_url: *const nsACString, base_url: *const nsACString,
base: *mut ThreadSafeURIHolder, extra_data: *mut URLExtraData)
referrer: *mut ThreadSafeURIHolder,
principal: *mut ThreadSafePrincipalHolder)
-> RawServoStyleSheetStrong { -> RawServoStyleSheetStrong {
let global_style_data = &*GLOBAL_STYLE_DATA; let global_style_data = &*GLOBAL_STYLE_DATA;
let input = unsafe { data.as_ref().unwrap().as_str_unchecked() }; let input = unsafe { data.as_ref().unwrap().as_str_unchecked() };
@ -346,11 +343,7 @@ pub extern "C" fn Servo_StyleSheet_FromUTF8Bytes(loader: *mut Loader,
let base_str = unsafe { base_url.as_ref().unwrap().as_str_unchecked() }; let base_str = unsafe { base_url.as_ref().unwrap().as_str_unchecked() };
let url = ServoUrl::parse(base_str).unwrap(); let url = ServoUrl::parse(base_str).unwrap();
let extra_data = unsafe { ParserContextExtraData { let extra_data = unsafe { ParserContextExtraData::new(extra_data) };
base: Some(GeckoArcURI::new(base)),
referrer: Some(GeckoArcURI::new(referrer)),
principal: Some(GeckoArcPrincipal::new(principal)),
}};
let loader = if loader.is_null() { let loader = if loader.is_null() {
None None
} else { } else {
@ -375,16 +368,10 @@ pub extern "C" fn Servo_StyleSheet_ClearAndUpdate(stylesheet: RawServoStyleSheet
loader: *mut Loader, loader: *mut Loader,
gecko_stylesheet: *mut ServoStyleSheet, gecko_stylesheet: *mut ServoStyleSheet,
data: *const nsACString, data: *const nsACString,
base: *mut ThreadSafeURIHolder, extra_data: *mut URLExtraData)
referrer: *mut ThreadSafeURIHolder,
principal: *mut ThreadSafePrincipalHolder)
{ {
let input = unsafe { data.as_ref().unwrap().as_str_unchecked() }; let input = unsafe { data.as_ref().unwrap().as_str_unchecked() };
let extra_data = unsafe { ParserContextExtraData { let extra_data = unsafe { ParserContextExtraData::new(extra_data) };
base: Some(GeckoArcURI::new(base)),
referrer: Some(GeckoArcURI::new(referrer)),
principal: Some(GeckoArcPrincipal::new(principal)),
}};
let loader = if loader.is_null() { let loader = if loader.is_null() {
None None
@ -792,7 +779,7 @@ macro_rules! make_context {
#[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: *const nsACString, base: *const nsACString,
data: *const structs::GeckoParserExtraData) data: *mut URLExtraData)
-> 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()) {
@ -824,7 +811,7 @@ pub extern "C" fn Servo_ParseProperty(property: *const nsACString, value: *const
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_ParseEasing(easing: *const nsAString, pub extern "C" fn Servo_ParseEasing(easing: *const nsAString,
base: *const nsACString, base: *const nsACString,
data: *const structs::GeckoParserExtraData, data: *mut URLExtraData,
output: nsTimingFunctionBorrowedMut) output: nsTimingFunctionBorrowedMut)
-> bool { -> bool {
use style::properties::longhands::transition_timing_function; use style::properties::longhands::transition_timing_function;
@ -845,7 +832,7 @@ pub extern "C" fn Servo_ParseEasing(easing: *const nsAString,
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_ParseStyleAttribute(data: *const nsACString, pub extern "C" fn Servo_ParseStyleAttribute(data: *const nsACString,
base: *const nsACString, base: *const nsACString,
raw_extra_data: *const structs::GeckoParserExtraData) raw_extra_data: *mut URLExtraData)
-> RawServoDeclarationBlockStrong { -> RawServoDeclarationBlockStrong {
let global_style_data = &*GLOBAL_STYLE_DATA; let global_style_data = &*GLOBAL_STYLE_DATA;
let value = unsafe { data.as_ref().unwrap().as_str_unchecked() }; let value = unsafe { data.as_ref().unwrap().as_str_unchecked() };
@ -965,7 +952,7 @@ 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, value: *const nsACString, is_important: bool,
base: *const nsACString, data: *const structs::GeckoParserExtraData) -> bool { base: *const nsACString, data: *mut URLExtraData) -> bool {
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() }; let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
make_context!((base, data) => (base_url, extra_data)); make_context!((base, data) => (base_url, extra_data));
@ -985,7 +972,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetProperty(declarations: RawServoDecla
property: *const nsACString, value: *const nsACString, property: *const nsACString, value: *const nsACString,
is_important: bool, is_important: bool,
base: *const nsACString, base: *const nsACString,
data: *const structs::GeckoParserExtraData) -> bool { data: *mut URLExtraData) -> bool {
set_property(declarations, get_property_id_from_property!(property, false), set_property(declarations, get_property_id_from_property!(property, false),
value, is_important, base, data) value, is_important, base, data)
} }
@ -995,7 +982,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetPropertyById(declarations: RawServoD
property: nsCSSPropertyID, value: *const nsACString, property: nsCSSPropertyID, value: *const nsACString,
is_important: bool, is_important: bool,
base: *const nsACString, base: *const nsACString,
data: *const structs::GeckoParserExtraData) -> bool { data: *mut URLExtraData) -> bool {
set_property(declarations, get_property_id_from_nscsspropertyid!(property, false), set_property(declarations, get_property_id_from_nscsspropertyid!(property, false),
value, is_important, base, data) value, is_important, base, data)
} }

View file

@ -44,13 +44,13 @@ impl StyleStylesheetLoader for StylesheetLoader {
// so this raw pointer will still be valid. // so this raw pointer will still be valid.
let (spec_bytes, spec_len): (*const u8, usize) = import.url.as_slice_components(); let (spec_bytes, spec_len): (*const u8, usize) = import.url.as_slice_components();
let base_uri = import.url.base.mRawPtr; let base_url_data = import.url.extra_data.get();
let arc = make_arc(import); let arc = make_arc(import);
unsafe { unsafe {
Gecko_LoadStyleSheet(self.0, Gecko_LoadStyleSheet(self.0,
self.1, self.1,
HasArcFFI::arc_as_borrowed(&arc), HasArcFFI::arc_as_borrowed(&arc),
base_uri, base_url_data,
spec_bytes, spec_bytes,
spec_len as u32, spec_len as u32,
media_string.as_bytes().as_ptr(), media_string.as_bytes().as_ptr(),