mirror of
https://github.com/servo/servo.git
synced 2025-06-21 07:38:59 +01:00
Allow pages to finish loading when external stylesheets have network errors.
This commit is contained in:
parent
810735a846
commit
1b495de29c
2 changed files with 59 additions and 41 deletions
|
@ -289,43 +289,46 @@ impl AsyncResponseListener for StylesheetContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn response_complete(&mut self, status: Result<(), NetworkError>) {
|
fn response_complete(&mut self, status: Result<(), NetworkError>) {
|
||||||
|
let elem = self.elem.root();
|
||||||
|
let document = document_from_node(&*elem);
|
||||||
|
|
||||||
if status.is_err() {
|
if status.is_err() {
|
||||||
self.elem.root().upcast::<EventTarget>().fire_simple_event("error");
|
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() {
|
if elem.parser_inserted.get() {
|
||||||
document.decrement_script_blocking_stylesheet_count();
|
document.decrement_script_blocking_stylesheet_count();
|
||||||
}
|
}
|
||||||
|
|
||||||
document.finish_load(LoadType::Stylesheet(self.url.clone()));
|
document.finish_load(LoadType::Stylesheet(self.url.clone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,17 +7,32 @@
|
||||||
<div id="log"></div>
|
<div id="log"></div>
|
||||||
<div id="test">
|
<div id="test">
|
||||||
<script>
|
<script>
|
||||||
//var t404 = async_test("Should get an error event for a 404 error.")
|
var t404 = async_test("Should get an error event for a 404 error.")
|
||||||
//t404.step(function() {
|
t404.step(function() {
|
||||||
// var elt = document.createElement("link");
|
var elt = document.createElement("link");
|
||||||
// elt.onerror = t404.step_func(function() {
|
elt.onerror = t404.step_func(function() {
|
||||||
// assert_true(true, "Got error event for 404 error.")
|
assert_true(true, "Got error event for 404 error.")
|
||||||
// t404.done()
|
t404.step_timeout(function() { t404.done() }, 0);
|
||||||
// })
|
})
|
||||||
// elt.rel = "stylesheet";
|
elt.onload = t404.unreached_func("load event should not be fired");
|
||||||
// elt.href = 404 error;
|
elt.rel = "stylesheet";
|
||||||
// document.getElementsByTagName("head")[0].appendChild(elt);
|
elt.href = "nonexistent_stylesheet.css";
|
||||||
//})
|
document.getElementsByTagName("head")[0].appendChild(elt);
|
||||||
|
})
|
||||||
|
|
||||||
|
var tUnsupported = async_test("Should get an error event for an unsupported URL.")
|
||||||
|
tUnsupported.step(function() {
|
||||||
|
var elt = document.createElement("link");
|
||||||
|
elt.onerror = tUnsupported.step_func(function() {
|
||||||
|
assert_true(true, "Got error event for unsupported URL.")
|
||||||
|
tUnsupported.step_timeout(function() { tUnsupported.done() }, 0);
|
||||||
|
})
|
||||||
|
elt.onload = tUnsupported.unreached_func("load event should not be fired");
|
||||||
|
elt.rel = "stylesheet";
|
||||||
|
elt.href = "nonexistent:stylesheet.css";
|
||||||
|
document.getElementsByTagName("head")[0].appendChild(elt);
|
||||||
|
})
|
||||||
|
|
||||||
var tText = async_test("Should get an error event for a text/plain response.")
|
var tText = async_test("Should get an error event for a text/plain response.")
|
||||||
tText.step(function() {
|
tText.step(function() {
|
||||||
var elt = document.createElement("link");
|
var elt = document.createElement("link");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue