Use final url for updating stylesheet from @import rule. r?emilio draft
authorXidorn Quan <me@upsuper.org>
Fri, 31 Mar 2017 16:50:51 +1100
changeset 554627 cafc6507117cde4b9f169f9455dc3ee462730836
parent 554626 4886bc0f17aab91bcf1ff9df8d0b5b5f2572e5e3
child 554628 4afc2eb15c52808fcaaf3f0ff79a0ea4c19c12bd
push id52016
push userxquan@mozilla.com
push dateSat, 01 Apr 2017 07:30:38 +0000
reviewersemilio
milestone55.0a1
Use final url for updating stylesheet from @import rule. r?emilio MozReview-Commit-ID: 7deRxBGcB7i
servo/components/script/stylesheet_loader.rs
servo/components/style/encoding_support.rs
servo/components/style/stylesheets.rs
servo/ports/geckolib/glue.rs
--- a/servo/components/script/stylesheet_loader.rs
+++ b/servo/components/script/stylesheet_loader.rs
@@ -156,16 +156,17 @@ impl FetchResponseListener for Styleshee
                         win.layout_chan().send(Msg::AddStylesheet(sheet)).unwrap();
                     }
                 }
                 StylesheetContextSource::Import(ref stylesheet) => {
                     Stylesheet::update_from_bytes(&stylesheet,
                                                   &data,
                                                   protocol_encoding_label,
                                                   Some(environment_encoding),
+                                                  &final_url,
                                                   Some(&loader),
                                                   win.css_error_reporter());
                 }
             }
 
             document.invalidate_stylesheets();
 
             // FIXME: Revisit once consensus is reached at:
--- a/servo/components/style/encoding_support.rs
+++ b/servo/components/style/encoding_support.rs
@@ -69,18 +69,20 @@ impl Stylesheet {
     }
 
     /// Updates an empty stylesheet with a set of bytes that reached over the
     /// network.
     pub fn update_from_bytes(existing: &Stylesheet,
                              bytes: &[u8],
                              protocol_encoding_label: Option<&str>,
                              environment_encoding: Option<EncodingRef>,
+                             url_data: &UrlExtraData,
                              stylesheet_loader: Option<&StylesheetLoader>,
                              error_reporter: &ParseErrorReporter) {
         let (string, _) = decode_stylesheet_bytes(
             bytes, protocol_encoding_label, environment_encoding);
         Self::update_from_str(existing,
                               &string,
+                              url_data,
                               stylesheet_loader,
                               error_reporter)
     }
 }
--- a/servo/components/style/stylesheets.rs
+++ b/servo/components/style/stylesheets.rs
@@ -584,21 +584,24 @@ impl ToCssWithGuard for StyleRule {
 /// A @font-face rule
 #[cfg(feature = "servo")]
 pub type FontFaceRule = FontFaceData;
 
 impl Stylesheet {
     /// Updates an empty stylesheet from a given string of text.
     pub fn update_from_str(existing: &Stylesheet,
                            css: &str,
+                           url_data: &UrlExtraData,
                            stylesheet_loader: Option<&StylesheetLoader>,
                            error_reporter: &ParseErrorReporter) {
         let mut namespaces = Namespaces::default();
+        // FIXME: we really should update existing.url_data with the given url_data,
+        // otherwise newly inserted rule may not have the right base url.
         let (rules, dirty_on_viewport_size_change) = Stylesheet::parse_rules(
-            css, &existing.url_data, existing.origin, &mut namespaces,
+            css, url_data, existing.origin, &mut namespaces,
             &existing.shared_lock, stylesheet_loader, error_reporter,
         );
 
         *existing.namespaces.write() = namespaces;
         existing.dirty_on_viewport_size_change
             .store(dirty_on_viewport_size_change, Ordering::Release);
 
         // Acquire the lock *after* parsing, to minimize the exclusive section.
--- a/servo/ports/geckolib/glue.rs
+++ b/servo/ports/geckolib/glue.rs
@@ -359,34 +359,36 @@ pub extern "C" fn Servo_StyleSheet_FromU
     ).into_strong()
 }
 
 #[no_mangle]
 pub extern "C" fn Servo_StyleSheet_ClearAndUpdate(stylesheet: RawServoStyleSheetBorrowed,
                                                   loader: *mut Loader,
                                                   gecko_stylesheet: *mut ServoStyleSheet,
                                                   data: *const nsACString,
-                                                  _extra_data: *mut URLExtraData)
+                                                  extra_data: *mut URLExtraData)
 {
     let input = unsafe { data.as_ref().unwrap().as_str_unchecked() };
+    let url_data = unsafe { RefPtr::from_ptr_ref(&extra_data) };
 
     let loader = if loader.is_null() {
         None
     } else {
         Some(StylesheetLoader::new(loader, gecko_stylesheet))
     };
 
     // FIXME(emilio): loader.as_ref() doesn't typecheck for some reason?
     let loader: Option<&StyleStylesheetLoader> = match loader {
         None => None,
         Some(ref s) => Some(s),
     };
 
     let sheet = Stylesheet::as_arc(&stylesheet);
-    Stylesheet::update_from_str(&sheet, input, loader, &StdoutErrorReporter);
+    Stylesheet::update_from_str(&sheet, input, url_data,
+                                loader, &StdoutErrorReporter);
 }
 
 #[no_mangle]
 pub extern "C" fn Servo_StyleSet_AppendStyleSheet(raw_data: RawServoStyleSetBorrowed,
                                                   raw_sheet: RawServoStyleSheetBorrowed,
                                                   flush: bool) {
     let global_style_data = &*GLOBAL_STYLE_DATA;
     let guard = global_style_data.shared_lock.read();