aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXidorn Quan <me@upsuper.org>2017-06-13 10:07:06 +1000
committerXidorn Quan <me@upsuper.org>2017-06-13 10:07:06 +1000
commitcdc537f23e1da29b98e203c5ad7176b49df5450b (patch)
treef1cec1a27dd118d32628ebbb886bb2d14582716c
parent1b077303237d5ecb8307f866e9172d0d8e6b132d (diff)
downloadservo-cdc537f23e1da29b98e203c5ad7176b49df5450b.tar.gz
servo-cdc537f23e1da29b98e203c5ad7176b49df5450b.zip
Bug 1331291 part 1 - Set stylesheet url_data correctly for import rule.
-rw-r--r--components/script/dom/cssstyledeclaration.rs2
-rw-r--r--components/script/dom/htmlmetaelement.rs3
-rw-r--r--components/script/stylesheet_loader.rs2
-rw-r--r--components/style/encoding_support.rs2
-rw-r--r--components/style/stylesheets/keyframes_rule.rs3
-rw-r--r--components/style/stylesheets/mod.rs3
-rw-r--r--components/style/stylesheets/rule_parser.rs2
-rw-r--r--components/style/stylesheets/stylesheet.rs13
-rw-r--r--ports/geckolib/glue.rs2
-rw-r--r--tests/unit/style/stylesheets.rs2
10 files changed, 18 insertions, 16 deletions
diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs
index ecf4b35e61c..5def880aa7d 100644
--- a/components/script/dom/cssstyledeclaration.rs
+++ b/components/script/dom/cssstyledeclaration.rs
@@ -147,7 +147,7 @@ impl CSSStyleOwner {
match *self {
CSSStyleOwner::Element(ref el) => window_from_node(&**el).Document().base_url(),
CSSStyleOwner::CSSRule(ref rule, _) => {
- rule.parent_stylesheet().style_stylesheet().url_data.clone()
+ (*rule.parent_stylesheet().style_stylesheet().url_data.read()).clone()
}
}
}
diff --git a/components/script/dom/htmlmetaelement.rs b/components/script/dom/htmlmetaelement.rs
index 888855dc7b6..cc11a9d9da4 100644
--- a/components/script/dom/htmlmetaelement.rs
+++ b/components/script/dom/htmlmetaelement.rs
@@ -19,6 +19,7 @@ use dom::node::{Node, UnbindContext, document_from_node, window_from_node};
use dom::virtualmethods::VirtualMethods;
use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix};
+use parking_lot::RwLock;
use servo_config::prefs::PREFS;
use std::ascii::AsciiExt;
use std::sync::atomic::AtomicBool;
@@ -105,7 +106,7 @@ impl HTMLMetaElement {
rules: CssRules::new(vec![rule], shared_lock),
origin: Origin::Author,
shared_lock: shared_lock.clone(),
- url_data: window_from_node(self).get_url(),
+ url_data: RwLock::new(window_from_node(self).get_url()),
namespaces: Default::default(),
media: Arc::new(shared_lock.wrap(MediaList::empty())),
// Viewport constraints are always recomputed on resize; they don't need to
diff --git a/components/script/stylesheet_loader.rs b/components/script/stylesheet_loader.rs
index 3143d8b34ad..4d2518a7cca 100644
--- a/components/script/stylesheet_loader.rs
+++ b/components/script/stylesheet_loader.rs
@@ -160,7 +160,7 @@ impl FetchResponseListener for StylesheetContext {
&data,
protocol_encoding_label,
Some(environment_encoding),
- &final_url,
+ final_url,
Some(&loader),
win.css_error_reporter());
}
diff --git a/components/style/encoding_support.rs b/components/style/encoding_support.rs
index af37e20889a..4f6365ffeae 100644
--- a/components/style/encoding_support.rs
+++ b/components/style/encoding_support.rs
@@ -79,7 +79,7 @@ impl Stylesheet {
bytes: &[u8],
protocol_encoding_label: Option<&str>,
environment_encoding: Option<EncodingRef>,
- url_data: &UrlExtraData,
+ url_data: UrlExtraData,
stylesheet_loader: Option<&StylesheetLoader>,
error_reporter: &ParseErrorReporter) {
let (string, _) = decode_stylesheet_bytes(
diff --git a/components/style/stylesheets/keyframes_rule.rs b/components/style/stylesheets/keyframes_rule.rs
index 2f63ec5ad1a..c87477a617b 100644
--- a/components/style/stylesheets/keyframes_rule.rs
+++ b/components/style/stylesheets/keyframes_rule.rs
@@ -205,9 +205,10 @@ impl Keyframe {
/// Parse a CSS keyframe.
pub fn parse<'i>(css: &'i str, parent_stylesheet: &Stylesheet)
-> Result<Arc<Locked<Self>>, ParseError<'i>> {
+ let url_data = parent_stylesheet.url_data.read();
let error_reporter = NullReporter;
let context = ParserContext::new(parent_stylesheet.origin,
- &parent_stylesheet.url_data,
+ &url_data,
&error_reporter,
Some(CssRuleType::Keyframe),
PARSING_MODE_DEFAULT,
diff --git a/components/style/stylesheets/mod.rs b/components/style/stylesheets/mod.rs
index df1bd2ae3c2..67354889b93 100644
--- a/components/style/stylesheets/mod.rs
+++ b/components/style/stylesheets/mod.rs
@@ -224,10 +224,11 @@ impl CssRule {
state: Option<State>,
loader: Option<&StylesheetLoader>
) -> Result<(Self, State), SingleRuleParseError> {
+ let url_data = parent_stylesheet.url_data.read();
let error_reporter = NullReporter;
let context = ParserContext::new(
parent_stylesheet.origin,
- &parent_stylesheet.url_data,
+ &url_data,
&error_reporter,
None,
PARSING_MODE_DEFAULT,
diff --git a/components/style/stylesheets/rule_parser.rs b/components/style/stylesheets/rule_parser.rs
index dd39070c977..34db0c1d69f 100644
--- a/components/style/stylesheets/rule_parser.rs
+++ b/components/style/stylesheets/rule_parser.rs
@@ -180,7 +180,7 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
media: media,
shared_lock: self.shared_lock.clone(),
origin: self.context.stylesheet_origin,
- url_data: self.context.url_data.clone(),
+ url_data: RwLock::new(self.context.url_data.clone()),
namespaces: RwLock::new(Namespaces::default()),
dirty_on_viewport_size_change: AtomicBool::new(false),
disabled: AtomicBool::new(false),
diff --git a/components/style/stylesheets/stylesheet.rs b/components/style/stylesheets/stylesheet.rs
index aefcb0ff926..db49e109687 100644
--- a/components/style/stylesheets/stylesheet.rs
+++ b/components/style/stylesheets/stylesheet.rs
@@ -52,7 +52,7 @@ pub struct Stylesheet {
/// The origin of this stylesheet.
pub origin: Origin,
/// The url data this stylesheet should use.
- pub url_data: UrlExtraData,
+ pub url_data: RwLock<UrlExtraData>,
/// The lock used for objects inside this stylesheet
pub shared_lock: SharedRwLock,
/// The namespaces that apply to this stylesheet.
@@ -69,17 +69,15 @@ impl Stylesheet {
/// Updates an empty stylesheet from a given string of text.
pub fn update_from_str(existing: &Stylesheet,
css: &str,
- url_data: &UrlExtraData,
+ url_data: UrlExtraData,
stylesheet_loader: Option<&StylesheetLoader>,
error_reporter: &ParseErrorReporter,
line_number_offset: u64) {
let namespaces = RwLock::new(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,
- url_data,
+ &url_data,
existing.origin,
&mut *namespaces.write(),
&existing.shared_lock,
@@ -89,6 +87,7 @@ impl Stylesheet {
line_number_offset
);
+ *existing.url_data.write() = url_data;
mem::swap(&mut *existing.namespaces.write(), &mut *namespaces.write());
existing.dirty_on_viewport_size_change
.store(dirty_on_viewport_size_change, Ordering::Release);
@@ -184,7 +183,7 @@ impl Stylesheet {
Stylesheet {
origin: origin,
- url_data: url_data,
+ url_data: RwLock::new(url_data),
namespaces: namespaces,
rules: CssRules::new(rules, &shared_lock),
media: media,
@@ -287,7 +286,7 @@ impl Clone for Stylesheet {
rules: Arc::new(lock.wrap(cloned_rules)),
media: Arc::new(lock.wrap(cloned_media)),
origin: self.origin,
- url_data: self.url_data.clone(),
+ url_data: RwLock::new((*self.url_data.read()).clone()),
shared_lock: lock,
namespaces: RwLock::new((*self.namespaces.read()).clone()),
dirty_on_viewport_size_change: AtomicBool::new(
diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs
index 705bb717804..107781b6c83 100644
--- a/ports/geckolib/glue.rs
+++ b/ports/geckolib/glue.rs
@@ -801,7 +801,7 @@ pub extern "C" fn Servo_StyleSheet_ClearAndUpdate(stylesheet: RawServoStyleSheet
};
let sheet = Stylesheet::as_arc(&stylesheet);
- Stylesheet::update_from_str(&sheet, input, url_data, loader,
+ Stylesheet::update_from_str(&sheet, input, url_data.clone(), loader,
&RustLogReporter, line_number_offset as u64);
}
diff --git a/tests/unit/style/stylesheets.rs b/tests/unit/style/stylesheets.rs
index b5f736bc116..a7929f89467 100644
--- a/tests/unit/style/stylesheets.rs
+++ b/tests/unit/style/stylesheets.rs
@@ -76,7 +76,7 @@ fn test_parse_stylesheet() {
media: Arc::new(stylesheet.shared_lock.wrap(MediaList::empty())),
shared_lock: stylesheet.shared_lock.clone(),
namespaces: RwLock::new(namespaces),
- url_data: url,
+ url_data: RwLock::new(url),
dirty_on_viewport_size_change: AtomicBool::new(false),
disabled: AtomicBool::new(false),
quirks_mode: QuirksMode::NoQuirks,