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

@ -54,16 +54,15 @@ use style::gecko_bindings::bindings::nsTimingFunctionBorrowed;
use style::gecko_bindings::bindings::nsTimingFunctionBorrowedMut;
use style::gecko_bindings::structs;
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::Loader;
use style::gecko_bindings::structs::RawGeckoPresContextOwned;
use style::gecko_bindings::structs::ServoStyleSheet;
use style::gecko_bindings::structs::URLExtraData;
use style::gecko_bindings::structs::nsCSSValueSharedList;
use style::gecko_bindings::structs::nsresult;
use style::gecko_bindings::sugar::ownership::{FFIArcHelpers, HasFFI, HasArcFFI, HasBoxFFI};
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::keyframes::KeyframesStepValue;
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,
mode: SheetParsingMode,
base_url: *const nsACString,
base: *mut ThreadSafeURIHolder,
referrer: *mut ThreadSafeURIHolder,
principal: *mut ThreadSafePrincipalHolder)
extra_data: *mut URLExtraData)
-> RawServoStyleSheetStrong {
let global_style_data = &*GLOBAL_STYLE_DATA;
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 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 extra_data = unsafe { ParserContextExtraData::new(extra_data) };
let loader = if loader.is_null() {
None
} else {
@ -375,16 +368,10 @@ pub extern "C" fn Servo_StyleSheet_ClearAndUpdate(stylesheet: RawServoStyleSheet
loader: *mut Loader,
gecko_stylesheet: *mut ServoStyleSheet,
data: *const nsACString,
base: *mut ThreadSafeURIHolder,
referrer: *mut ThreadSafeURIHolder,
principal: *mut ThreadSafePrincipalHolder)
extra_data: *mut URLExtraData)
{
let input = unsafe { data.as_ref().unwrap().as_str_unchecked() };
let extra_data = unsafe { ParserContextExtraData {
base: Some(GeckoArcURI::new(base)),
referrer: Some(GeckoArcURI::new(referrer)),
principal: Some(GeckoArcPrincipal::new(principal)),
}};
let extra_data = unsafe { ParserContextExtraData::new(extra_data) };
let loader = if loader.is_null() {
None
@ -792,7 +779,7 @@ macro_rules! make_context {
#[no_mangle]
pub extern "C" fn Servo_ParseProperty(property: *const nsACString, value: *const nsACString,
base: *const nsACString,
data: *const structs::GeckoParserExtraData)
data: *mut URLExtraData)
-> RawServoDeclarationBlockStrong {
let name = unsafe { property.as_ref().unwrap().as_str_unchecked() };
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]
pub extern "C" fn Servo_ParseEasing(easing: *const nsAString,
base: *const nsACString,
data: *const structs::GeckoParserExtraData,
data: *mut URLExtraData,
output: nsTimingFunctionBorrowedMut)
-> bool {
use style::properties::longhands::transition_timing_function;
@ -845,7 +832,7 @@ pub extern "C" fn Servo_ParseEasing(easing: *const nsAString,
#[no_mangle]
pub extern "C" fn Servo_ParseStyleAttribute(data: *const nsACString,
base: *const nsACString,
raw_extra_data: *const structs::GeckoParserExtraData)
raw_extra_data: *mut URLExtraData)
-> RawServoDeclarationBlockStrong {
let global_style_data = &*GLOBAL_STYLE_DATA;
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,
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() };
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,
is_important: bool,
base: *const nsACString,
data: *const structs::GeckoParserExtraData) -> bool {
data: *mut URLExtraData) -> bool {
set_property(declarations, get_property_id_from_property!(property, false),
value, is_important, base, data)
}
@ -995,7 +982,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetPropertyById(declarations: RawServoD
property: nsCSSPropertyID, value: *const nsACString,
is_important: bool,
base: *const nsACString,
data: *const structs::GeckoParserExtraData) -> bool {
data: *mut URLExtraData) -> bool {
set_property(declarations, get_property_id_from_nscsspropertyid!(property, false),
value, is_important, base, data)
}

View file

@ -44,13 +44,13 @@ impl StyleStylesheetLoader for StylesheetLoader {
// so this raw pointer will still be valid.
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);
unsafe {
Gecko_LoadStyleSheet(self.0,
self.1,
HasArcFFI::arc_as_borrowed(&arc),
base_uri,
base_url_data,
spec_bytes,
spec_len as u32,
media_string.as_bytes().as_ptr(),