mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
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:
parent
2cbd27c83a
commit
c48226ff6f
19 changed files with 74 additions and 30 deletions
28
Cargo.lock
generated
28
Cargo.lock
generated
|
@ -336,7 +336,7 @@ dependencies = [
|
|||
"azure 0.21.0 (git+https://github.com/servo/rust-azure)",
|
||||
"canvas_traits 0.0.1",
|
||||
"compositing 0.0.1",
|
||||
"cssparser 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cssparser 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"euclid 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gleam 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -352,7 +352,7 @@ dependencies = [
|
|||
name = "canvas_traits"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"cssparser 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cssparser 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"euclid 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"heapsize_derive 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -600,7 +600,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "cssparser"
|
||||
version = "0.21.0"
|
||||
version = "0.21.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cssparser-macros 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1087,7 +1087,7 @@ name = "geckoservo"
|
|||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cssparser 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cssparser 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1156,7 +1156,7 @@ dependencies = [
|
|||
name = "gfx_tests"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"cssparser 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cssparser 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gfx 0.0.1",
|
||||
"ipc-channel 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"style 0.0.1",
|
||||
|
@ -1749,7 +1749,7 @@ name = "malloc_size_of"
|
|||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"app_units 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cssparser 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cssparser 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"euclid 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hashglobe 0.1.0",
|
||||
"servo_arc 0.0.1",
|
||||
|
@ -2579,7 +2579,7 @@ dependencies = [
|
|||
"caseless 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cmake 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cookie 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cssparser 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cssparser 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"deny_public_fields 0.0.1",
|
||||
"devtools_traits 0.0.1",
|
||||
"dom_struct 0.0.1",
|
||||
|
@ -2651,7 +2651,7 @@ dependencies = [
|
|||
"app_units 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"canvas_traits 0.0.1",
|
||||
"cssparser 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cssparser 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"euclid 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gfx_traits 0.0.1",
|
||||
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -2723,7 +2723,7 @@ name = "selectors"
|
|||
version = "0.19.0"
|
||||
dependencies = [
|
||||
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cssparser 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cssparser 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"malloc_size_of 0.0.1",
|
||||
|
@ -3128,7 +3128,7 @@ dependencies = [
|
|||
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cssparser 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cssparser 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"euclid 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"fallible 0.0.1",
|
||||
|
@ -3189,7 +3189,7 @@ version = "0.0.1"
|
|||
dependencies = [
|
||||
"app_units 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cssparser 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cssparser 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"euclid 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"html5ever 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -3211,7 +3211,7 @@ version = "0.0.1"
|
|||
dependencies = [
|
||||
"app_units 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cssparser 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cssparser 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"euclid 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"heapsize_derive 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -3228,7 +3228,7 @@ name = "stylo_tests"
|
|||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cssparser 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cssparser 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"euclid 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"geckoservo 0.0.1",
|
||||
|
@ -3819,7 +3819,7 @@ dependencies = [
|
|||
"checksum core-foundation-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "41115a6aa5d3e1e5ef98148373f25971d1fad53818553f216495f9e67e90a624"
|
||||
"checksum core-graphics 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a9f841e9637adec70838c537cae52cb4c751cc6514ad05669b51d107c2021c79"
|
||||
"checksum core-text 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "16ce16d9ed00181016c11ff48e561314bec92bfbce9fe48f319366618d4e5de6"
|
||||
"checksum cssparser 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e88f0308699ff4e42b2ae57f170673f180a5b41f59364c95ae5c0c8022dbcbd1"
|
||||
"checksum cssparser 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a1dbaec53fe0184bd20e3efd5cb36fcf3286ce4070181ae125ac5a137c7f7fd1"
|
||||
"checksum cssparser-macros 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "079adec4af52bb5275eadd004292028c79eb3c5f5b4ee8086a36d4197032f6df"
|
||||
"checksum darling 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9861a8495606435477df581bc858ccf15a3469747edf175b94a4704fd9aaedac"
|
||||
"checksum darling_core 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1486a8b00b45062c997f767738178b43219133dd0c8c826cb811e60563810821"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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" }
|
||||
|
|
|
@ -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"}
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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" }
|
||||
|
|
|
@ -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" }
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -15,7 +15,7 @@ gecko_debug = ["style/gecko_debug"]
|
|||
|
||||
[dependencies]
|
||||
atomic_refcell = "0.1"
|
||||
cssparser = "0.21.0"
|
||||
cssparser = "0.21.1"
|
||||
env_logger = {version = "0.4", default-features = false} # disable `regex` to reduce code size
|
||||
libc = "0.2"
|
||||
log = {version = "0.3.5", features = ["release_max_level_info"]}
|
||||
|
|
|
@ -1120,6 +1120,18 @@ pub extern "C" fn Servo_StyleSheet_GetSourceMapURL(
|
|||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_StyleSheet_GetSourceURL(
|
||||
sheet: RawServoStyleSheetContentsBorrowed,
|
||||
result: *mut nsAString
|
||||
) {
|
||||
let contents = StylesheetContents::as_arc(&sheet);
|
||||
let url_opt = contents.source_url.read();
|
||||
if let Some(ref url) = *url_opt {
|
||||
write!(unsafe { &mut *result }, "{}", url).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn read_locked_arc<T, R, F>(raw: &<Locked<T> as HasFFI>::FFIType, func: F) -> R
|
||||
where Locked<T>: HasArcFFI, F: FnOnce(&T) -> R
|
||||
{
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "lib.rs"
|
|||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
cssparser = "0.21.0"
|
||||
cssparser = "0.21.1"
|
||||
gfx = {path = "../../../components/gfx"}
|
||||
ipc-channel = "0.8"
|
||||
style = {path = "../../../components/style"}
|
||||
|
|
|
@ -12,7 +12,7 @@ doctest = false
|
|||
[dependencies]
|
||||
byteorder = "1.0"
|
||||
app_units = "0.5"
|
||||
cssparser = "0.21.0"
|
||||
cssparser = "0.21.1"
|
||||
euclid = "0.15"
|
||||
html5ever = "0.19"
|
||||
parking_lot = "0.4"
|
||||
|
|
|
@ -249,6 +249,7 @@ fn test_parse_stylesheet() {
|
|||
})))
|
||||
], &stylesheet.shared_lock),
|
||||
source_map_url: RwLock::new(None),
|
||||
source_url: RwLock::new(None),
|
||||
},
|
||||
media: Arc::new(stylesheet.shared_lock.wrap(MediaList::empty())),
|
||||
shared_lock: stylesheet.shared_lock.clone(),
|
||||
|
@ -377,3 +378,22 @@ fn test_source_map_url() {
|
|||
assert_eq!(*url_opt, test.1);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_source_url() {
|
||||
let tests = vec![
|
||||
("", None),
|
||||
("/*# sourceURL=something */", Some("something".to_string())),
|
||||
];
|
||||
|
||||
for test in tests {
|
||||
let url = ServoUrl::parse("about::test").unwrap();
|
||||
let lock = SharedRwLock::new();
|
||||
let media = Arc::new(lock.wrap(MediaList::empty()));
|
||||
let stylesheet = Stylesheet::from_str(test.0, url.clone(), Origin::UserAgent, media, lock,
|
||||
None, &CSSErrorReporterTest, QuirksMode::NoQuirks,
|
||||
0);
|
||||
let url_opt = stylesheet.contents.source_url.read();
|
||||
assert_eq!(*url_opt, test.1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ doctest = false
|
|||
|
||||
[dependencies]
|
||||
atomic_refcell = "0.1"
|
||||
cssparser = "0.21.0"
|
||||
cssparser = "0.21.1"
|
||||
env_logger = "0.4"
|
||||
euclid = "0.15"
|
||||
geckoservo = {path = "../../../ports/geckolib"}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue