diff --git a/src/components/main/css/select.rs b/src/components/main/css/select.rs index e65c76c6e25..10ac49875d5 100644 --- a/src/components/main/css/select.rs +++ b/src/components/main/css/select.rs @@ -3,12 +3,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use style::{Stylesheet, Stylist, UserAgentOrigin, with_errors_silenced}; +use extra::url; pub fn new_stylist() -> Stylist { let mut stylist = Stylist::new(); - let ua_stylesheet = with_errors_silenced( - || Stylesheet::from_bytes(include_bin!("user-agent.css"), None, None)); + let ua_stylesheet = with_errors_silenced(|| Stylesheet::from_bytes( + include_bin!("user-agent.css"), + url::from_str("chrome:///user-agent.css").unwrap(), + None, + None)); stylist.add_stylesheet(ua_stylesheet, UserAgentOrigin); stylist } diff --git a/src/components/script/html/cssparse.rs b/src/components/script/html/cssparse.rs index 15532d76ab8..76d294e978e 100644 --- a/src/components/script/html/cssparse.rs +++ b/src/components/script/html/cssparse.rs @@ -48,10 +48,11 @@ pub fn spawn_css_parser(provenance: StylesheetProvenance, let protocol_encoding_label = metadata.charset.as_ref().map(|s| s.as_slice()); let iter = ProgressMsgPortIterator { progress_port: progress_port }; Stylesheet::from_bytes_iter( - iter, protocol_encoding_label, Some(environment_encoding)) + iter, metadata.final_url, + protocol_encoding_label, Some(environment_encoding)) } - InlineProvenance(_, data) => { - Stylesheet::from_str(data, environment_encoding) + InlineProvenance(base_url, data) => { + Stylesheet::from_str(data, base_url, environment_encoding) } }; result_chan.send(sheet); diff --git a/src/components/style/stylesheets.rs b/src/components/style/stylesheets.rs index ab4ebb30a53..034f77a2f71 100644 --- a/src/components/style/stylesheets.rs +++ b/src/components/style/stylesheets.rs @@ -4,6 +4,7 @@ use std::iter::Iterator; use std::ascii::StrAsciiExt; +use extra::url::Url; use encoding::EncodingObj; @@ -23,6 +24,7 @@ pub struct Stylesheet { rules: ~[CSSRule], namespaces: NamespaceMap, encoding: EncodingObj, + base_url: Url, } @@ -40,25 +42,25 @@ pub struct StyleRule { impl Stylesheet { pub fn from_bytes_iter>( - mut input: I, protocol_encoding_label: Option<&str>, + mut input: I, base_url: Url, protocol_encoding_label: Option<&str>, environment_encoding: Option) -> Stylesheet { let mut bytes = ~[]; // TODO: incremental decoding and tokinization/parsing for chunk in input { bytes.push_all(chunk) } - Stylesheet::from_bytes(bytes, protocol_encoding_label, environment_encoding) + Stylesheet::from_bytes(bytes, base_url, protocol_encoding_label, environment_encoding) } pub fn from_bytes( - bytes: &[u8], protocol_encoding_label: Option<&str>, + bytes: &[u8], base_url: Url, protocol_encoding_label: Option<&str>, environment_encoding: Option) -> Stylesheet { let (string, used_encoding) = decode_stylesheet_bytes( bytes, protocol_encoding_label, environment_encoding); - Stylesheet::from_str(string, used_encoding) + Stylesheet::from_str(string, base_url, used_encoding) } - pub fn from_str(css: &str, encoding: EncodingObj) -> Stylesheet { + pub fn from_str(css: &str, base_url: Url, encoding: EncodingObj) -> Stylesheet { static STATE_CHARSET: uint = 1; static STATE_IMPORTS: uint = 2; static STATE_NAMESPACES: uint = 3; @@ -117,7 +119,7 @@ impl Stylesheet { } state = next_state; } - Stylesheet{ rules: rules, namespaces: namespaces, encoding: encoding } + Stylesheet{ rules: rules, namespaces: namespaces, encoding: encoding, base_url: base_url } } }