Preserve sourceURL comment on style sheets

In addition to the sourceMappingURL comment, there is a second special
comment, "sourceURL", that can be used to set the "display name" of a
style sheet for developer tools.  This name is also used as the base
URL for the source-map URL resolution algorithm.  sourceURL is
described here:
https://blog.getfirebug.com/2009/08/11/give-your-eval-a-name-with-sourceurl/
The devtools feature bug is here:
https://bugzilla.mozilla.org/show_bug.cgi?id=880831

This patch changes servo to preserve and expose this value for use in M-C.
This commit is contained in:
Tom Tromey 2017-09-14 12:38:05 -06:00
parent 2cbd27c83a
commit c48226ff6f
19 changed files with 74 additions and 30 deletions

View file

@ -13,7 +13,7 @@ path = "lib.rs"
azure = {git = "https://github.com/servo/rust-azure"}
canvas_traits = {path = "../canvas_traits"}
compositing = {path = "../compositing"}
cssparser = "0.21.0"
cssparser = "0.21.1"
euclid = "0.15"
fnv = "1.0"
gleam = "0.4"

View file

@ -10,7 +10,7 @@ name = "canvas_traits"
path = "lib.rs"
[dependencies]
cssparser = "0.21.0"
cssparser = "0.21.1"
euclid = "0.15"
heapsize = "0.4"
heapsize_derive = "0.1"

View file

@ -10,7 +10,7 @@ path = "lib.rs"
[dependencies]
app_units = "0.5.5"
cssparser = "0.21.0"
cssparser = "0.21.1"
euclid = "0.15"
hashglobe = { path = "../hashglobe" }
servo_arc = { path = "../servo_arc" }

View file

@ -33,7 +33,7 @@ byteorder = "1.0"
canvas_traits = {path = "../canvas_traits"}
caseless = "0.1.0"
cookie = "0.6"
cssparser = "0.21.0"
cssparser = "0.21.1"
deny_public_fields = {path = "../deny_public_fields"}
devtools_traits = {path = "../devtools_traits"}
dom_struct = {path = "../dom_struct"}

View file

@ -110,6 +110,7 @@ impl HTMLMetaElement {
quirks_mode: document.quirks_mode(),
url_data: RwLock::new(window_from_node(self).get_url()),
source_map_url: RwLock::new(None),
source_url: RwLock::new(None),
},
media: Arc::new(shared_lock.wrap(MediaList::empty())),
shared_lock: shared_lock.clone(),

View file

@ -292,6 +292,7 @@ impl<'a> StyleStylesheetLoader for StylesheetLoader<'a> {
quirks_mode: context.quirks_mode,
namespaces: RwLock::new(Namespaces::default()),
source_map_url: RwLock::new(None),
source_url: RwLock::new(None),
},
media: media,
shared_lock: lock.clone(),

View file

@ -13,7 +13,7 @@ path = "lib.rs"
app_units = "0.5"
atomic_refcell = "0.1"
canvas_traits = {path = "../canvas_traits"}
cssparser = "0.21.0"
cssparser = "0.21.1"
euclid = "0.15"
gfx_traits = {path = "../gfx_traits"}
heapsize = "0.4"

View file

@ -25,7 +25,7 @@ unstable = []
[dependencies]
bitflags = "0.7"
matches = "0.1"
cssparser = "0.21.0"
cssparser = "0.21.1"
log = "0.3"
fnv = "1.0"
malloc_size_of = { path = "../malloc_size_of" }

View file

@ -37,7 +37,7 @@ atomic_refcell = "0.1"
bitflags = "0.7"
byteorder = "1.0"
cfg-if = "0.1.0"
cssparser = "0.21.0"
cssparser = "0.21.1"
encoding = {version = "0.2", optional = true}
euclid = "0.15"
fallible = { path = "../fallible" }

View file

@ -1970,6 +1970,10 @@ extern "C" {
RawServoStyleSheetContentsBorrowed,
result: *mut nsAString);
}
extern "C" {
pub fn Servo_StyleSheet_GetSourceURL(sheet: RawServoStyleSheetContentsBorrowed,
result: *mut nsAString);
}
extern "C" {
pub fn Servo_StyleSheet_GetOrigin(sheet:
RawServoStyleSheetContentsBorrowed)

View file

@ -62,6 +62,8 @@ pub struct StylesheetContents {
pub quirks_mode: QuirksMode,
/// This stylesheet's source map URL.
pub source_map_url: RwLock<Option<String>>,
/// This stylesheet's source URL.
pub source_url: RwLock<Option<String>>,
}
impl StylesheetContents {
@ -78,7 +80,7 @@ impl StylesheetContents {
line_number_offset: u32
) -> Self {
let namespaces = RwLock::new(Namespaces::default());
let (rules, source_map_url) = Stylesheet::parse_rules(
let (rules, source_map_url, source_url) = Stylesheet::parse_rules(
css,
&url_data,
origin,
@ -97,6 +99,7 @@ impl StylesheetContents {
namespaces: namespaces,
quirks_mode: quirks_mode,
source_map_url: RwLock::new(source_map_url),
source_url: RwLock::new(source_url),
}
}
@ -146,6 +149,7 @@ impl DeepCloneWithLock for StylesheetContents {
url_data: RwLock::new((*self.url_data.read()).clone()),
namespaces: RwLock::new((*self.namespaces.read()).clone()),
source_map_url: RwLock::new((*self.source_map_url.read()).clone()),
source_url: RwLock::new((*self.source_map_url.read()).clone()),
}
}
}
@ -314,7 +318,7 @@ impl Stylesheet {
where R: ParseErrorReporter
{
let namespaces = RwLock::new(Namespaces::default());
let (rules, source_map_url) =
let (rules, source_map_url, source_url) =
Stylesheet::parse_rules(
css,
&url_data,
@ -337,6 +341,7 @@ impl Stylesheet {
let mut guard = existing.shared_lock.write();
*existing.contents.rules.write_with(&mut guard) = CssRules(rules);
*existing.contents.source_map_url.write() = source_map_url;
*existing.contents.source_url.write() = source_url;
}
fn parse_rules<R: ParseErrorReporter>(
@ -349,7 +354,7 @@ impl Stylesheet {
error_reporter: &R,
quirks_mode: QuirksMode,
line_number_offset: u32
) -> (Vec<CssRule>, Option<String>) {
) -> (Vec<CssRule>, Option<String>, Option<String>) {
let mut rules = Vec::new();
let mut input = ParserInput::new_with_line_number_offset(css, line_number_offset);
let mut input = Parser::new(&mut input);
@ -399,7 +404,8 @@ impl Stylesheet {
}
let source_map_url = input.current_source_map_url().map(String::from);
(rules, source_map_url)
let source_url = input.current_source_url().map(String::from);
(rules, source_map_url, source_url)
}
/// Creates an empty stylesheet and parses it with a given base url, origin

View file

@ -16,7 +16,7 @@ gecko = []
[dependencies]
app_units = "0.5"
bitflags = "0.7"
cssparser = "0.21.0"
cssparser = "0.21.1"
euclid = "0.15"
heapsize = {version = "0.4", optional = true}
heapsize_derive = {version = "0.1", optional = true}