Auto merge of #11913 - jdm:stylesheet-error, r=Ms2ger

Avoid stalled pages containing unreachable stylesheets

This hits some of the pages in the performance testsuite, and leads to a poor user experience since the document load event is never dispatched and the page never finishes parsing.

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #11535 (github issue number if applicable).
- [X] There are tests for these changes OR

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11913)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-06-29 11:42:40 -05:00 committed by GitHub
commit 55ab7a8b12
2 changed files with 59 additions and 41 deletions

View file

@ -289,43 +289,46 @@ impl AsyncResponseListener for StylesheetContext {
}
fn response_complete(&mut self, status: Result<(), NetworkError>) {
let elem = self.elem.root();
let document = document_from_node(&*elem);
if status.is_err() {
self.elem.root().upcast::<EventTarget>().fire_simple_event("error");
return;
} else {
let data = mem::replace(&mut self.data, vec!());
let metadata = match self.metadata.take() {
Some(meta) => meta,
None => return,
};
// TODO: Get the actual value. http://dev.w3.org/csswg/css-syntax/#environment-encoding
let environment_encoding = UTF_8 as EncodingRef;
let protocol_encoding_label = metadata.charset.as_ref().map(|s| &**s);
let final_url = metadata.final_url;
let win = window_from_node(&*elem);
let mut sheet = Stylesheet::from_bytes(&data, final_url, protocol_encoding_label,
Some(environment_encoding), Origin::Author,
win.css_error_reporter(),
ParserContextExtraData::default());
let media = self.media.take().unwrap();
sheet.set_media(Some(media));
let sheet = Arc::new(sheet);
let elem = elem.r();
let document = document.r();
let win = window_from_node(elem);
win.layout_chan().send(Msg::AddStylesheet(sheet.clone())).unwrap();
*elem.stylesheet.borrow_mut() = Some(sheet);
document.invalidate_stylesheets();
}
let data = mem::replace(&mut self.data, vec!());
let metadata = match self.metadata.take() {
Some(meta) => meta,
None => return,
};
// TODO: Get the actual value. http://dev.w3.org/csswg/css-syntax/#environment-encoding
let environment_encoding = UTF_8 as EncodingRef;
let protocol_encoding_label = metadata.charset.as_ref().map(|s| &**s);
let final_url = metadata.final_url;
let elem = self.elem.root();
let win = window_from_node(&*elem);
let mut sheet = Stylesheet::from_bytes(&data, final_url, protocol_encoding_label,
Some(environment_encoding), Origin::Author,
win.css_error_reporter(),
ParserContextExtraData::default());
let media = self.media.take().unwrap();
sheet.set_media(Some(media));
let sheet = Arc::new(sheet);
let elem = elem.r();
let document = document_from_node(elem);
let document = document.r();
let win = window_from_node(elem);
win.layout_chan().send(Msg::AddStylesheet(sheet.clone())).unwrap();
*elem.stylesheet.borrow_mut() = Some(sheet);
document.invalidate_stylesheets();
if elem.parser_inserted.get() {
document.decrement_script_blocking_stylesheet_count();
}
document.finish_load(LoadType::Stylesheet(self.url.clone()));
}
}