mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +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
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue