Pass Gecko sheet base/referrer/principal from Servo_StylesheetFromUTF8Bytes through ParserContext.

This commit is contained in:
Cameron McCormack 2016-05-19 15:40:10 +10:00
parent 6dfb51f272
commit 6d67aa8a01
5 changed files with 23 additions and 5 deletions

View file

@ -11,7 +11,7 @@ name = "style"
path = "lib.rs"
[features]
gecko = []
gecko = ["gecko_bindings"]
[dependencies]
app_units = {version = "0.2.3", features = ["plugins"]}
@ -20,6 +20,7 @@ cssparser = {version = "0.5.5", features = ["heap_size", "serde-serialization"]}
encoding = "0.2"
euclid = {version = "0.6.4", features = ["plugins"]}
fnv = "1.0"
gecko_bindings = {path = "../../ports/geckolib/gecko_bindings", optional = true}
heapsize = "0.3.0"
heapsize_plugin = "0.1.2"
lazy_static = "0.2"

View file

@ -28,6 +28,8 @@ extern crate cssparser;
extern crate encoding;
extern crate euclid;
extern crate fnv;
#[cfg(feature = "gecko")]
extern crate gecko_bindings;
extern crate heapsize;
#[allow(unused_extern_crates)]
#[macro_use]

View file

@ -5,6 +5,8 @@
use cssparser::{Parser, SourcePosition};
use error_reporting::ParseErrorReporter;
#[cfg(feature = "gecko")]
use gecko_bindings::ptr::{GeckoArcPrincipal, GeckoArcURI};
use selectors::parser::ParserContext as SelectorParserContext;
use stylesheets::Origin;
use url::Url;
@ -14,6 +16,9 @@ pub struct ParserContextExtraData;
#[cfg(feature = "gecko")]
pub struct ParserContextExtraData {
pub base: Option<GeckoArcURI>,
pub referrer: Option<GeckoArcURI>,
pub principal: Option<GeckoArcPrincipal>,
}
impl ParserContextExtraData {
@ -24,7 +29,7 @@ impl ParserContextExtraData {
#[cfg(feature = "gecko")]
pub fn default() -> ParserContextExtraData {
ParserContextExtraData { }
ParserContextExtraData { base: None, referrer: None, principal: None }
}
}

View file

@ -453,6 +453,7 @@ dependencies = [
"encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gecko_bindings 0.0.1",
"heapsize 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize_plugin 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -10,7 +10,8 @@ use env_logger;
use euclid::Size2D;
use gecko_bindings::bindings::{RawGeckoDocument, RawGeckoElement, RawGeckoNode};
use gecko_bindings::bindings::{RawServoStyleSet, RawServoStyleSheet, ServoComputedValues, ServoNodeData};
use gecko_bindings::bindings::{nsIAtom};
use gecko_bindings::bindings::{ThreadSafePrincipalHolder, ThreadSafeURIHolder, nsIAtom};
use gecko_bindings::ptr::{GeckoArcPrincipal, GeckoArcURI};
use gecko_bindings::structs::SheetParsingMode;
use properties::GeckoComputedValues;
use selector_impl::{GeckoSelectorImpl, PseudoElement, SharedStyleContext, Stylesheet};
@ -121,7 +122,11 @@ pub extern "C" fn Servo_DropNodeData(data: *mut ServoNodeData) -> () {
#[no_mangle]
pub extern "C" fn Servo_StylesheetFromUTF8Bytes(bytes: *const u8,
length: u32,
mode: SheetParsingMode) -> *mut RawServoStyleSheet {
mode: SheetParsingMode,
base: *mut ThreadSafeURIHolder,
referrer: *mut ThreadSafeURIHolder,
principal: *mut ThreadSafePrincipalHolder)
-> *mut RawServoStyleSheet {
let input = unsafe { from_utf8_unchecked(slice::from_raw_parts(bytes, length as usize)) };
@ -133,7 +138,11 @@ pub extern "C" fn Servo_StylesheetFromUTF8Bytes(bytes: *const u8,
// FIXME(heycam): Pass in the real base URL.
let url = Url::parse("about:none").unwrap();
let extra_data = ParserContextExtraData { };
let extra_data = ParserContextExtraData {
base: Some(GeckoArcURI::new(base)),
referrer: Some(GeckoArcURI::new(referrer)),
principal: Some(GeckoArcPrincipal::new(principal)),
};
let sheet = Arc::new(Stylesheet::from_str(input, url, origin, Box::new(StdoutErrorReporter),
extra_data));
unsafe {