Auto merge of #14911 - charlesvdv:alternate-stylesheet, r=cbrewster

Handle properly alternate stylesheet

<!-- Please describe your changes on the following line: -->
Alternate stylesheet are now fetched and then desactivated instead of ignoring them.

I don't know if tests are required to check if the stylesheet is correctly loaded and disabled ?
<!-- 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
- [X] These changes fix #14881 (github issue number if applicable).

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

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- 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/14911)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-01-11 10:34:04 -08:00 committed by GitHub
commit cfc74e2060
5 changed files with 23 additions and 16 deletions

View file

@ -99,6 +99,17 @@ impl HTMLLinkElement {
}) })
}) })
} }
pub fn is_alternate(&self) -> bool {
let rel = get_attr(self.upcast(), &local_name!("rel"));
match rel {
Some(ref value) => {
value.split(HTML_SPACE_CHARACTERS)
.any(|s| s.eq_ignore_ascii_case("alternate"))
},
None => false,
}
}
} }
fn get_attr(element: &Element, local_name: &LocalName) -> Option<String> { fn get_attr(element: &Element, local_name: &LocalName) -> Option<String> {
@ -112,17 +123,8 @@ fn get_attr(element: &Element, local_name: &LocalName) -> Option<String> {
fn string_is_stylesheet(value: &Option<String>) -> bool { fn string_is_stylesheet(value: &Option<String>) -> bool {
match *value { match *value {
Some(ref value) => { Some(ref value) => {
let mut found_stylesheet = false; value.split(HTML_SPACE_CHARACTERS)
for s in value.split(HTML_SPACE_CHARACTERS).into_iter() { .any(|s| s.eq_ignore_ascii_case("stylesheet"))
if s.eq_ignore_ascii_case("alternate") {
return false;
}
if s.eq_ignore_ascii_case("stylesheet") {
found_stylesheet = true;
}
}
found_stylesheet
}, },
None => false, None => false,
} }

View file

@ -138,6 +138,9 @@ impl FetchResponseListener for StylesheetContext {
Some(&loader), Some(&loader),
win.css_error_reporter(), win.css_error_reporter(),
ParserContextExtraData::default())); ParserContextExtraData::default()));
if elem.downcast::<HTMLLinkElement>().unwrap().is_alternate() {
sheet.set_disabled(true);
}
elem.downcast::<HTMLLinkElement>() elem.downcast::<HTMLLinkElement>()
.unwrap() .unwrap()
.set_stylesheet(sheet.clone()); .set_stylesheet(sheet.clone());

View file

@ -1,14 +1,11 @@
[subresource-integrity.sub.html] [subresource-integrity.sub.html]
type: testharness type: testharness
expected: TIMEOUT expected: OK
[Style: <crossorigin='anonymous'> with correct hash, ACAO: *] [Style: <crossorigin='anonymous'> with correct hash, ACAO: *]
expected: FAIL expected: FAIL
[Style: Same-origin with correct sha256 and sha512 hash, rel='alternate stylesheet' enabled] [Style: Same-origin with correct sha256 and sha512 hash, rel='alternate stylesheet' enabled]
expected: NOTRUN expected: FAIL
[Style: Same-origin with incorrect sha256 and sha512 hash, rel='alternate stylesheet' enabled]
expected: NOTRUN
[Style: Same-origin with incorrect hash.] [Style: Same-origin with incorrect hash.]
expected: FAIL expected: FAIL

View file

@ -0,0 +1,3 @@
body {
background-color: black;
}

View file

@ -1,3 +1,5 @@
@import url("alternate-import.css");
div { div {
background-color: red; background-color: red;
} }