Auto merge of #18512 - tromey:preserve-style-sheet-source-url, r=SimonSapin

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.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18512)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-09-15 08:07:49 -05:00 committed by GitHub
commit 7cc0af37cf
19 changed files with 74 additions and 30 deletions

View file

@ -36,7 +36,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

@ -1977,6 +1977,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