mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Fire load event for external stylesheets
Do not load stylesheets with the wrong Content-Type Fixes #11912, #11910
This commit is contained in:
parent
7a7bdf51ad
commit
aed761509b
4 changed files with 19 additions and 13 deletions
|
@ -22,6 +22,7 @@ use dom::virtualmethods::VirtualMethods;
|
|||
use encoding::EncodingRef;
|
||||
use encoding::all::UTF_8;
|
||||
use hyper::header::ContentType;
|
||||
use hyper::http::RawStatus;
|
||||
use hyper::mime::{Mime, TopLevel, SubLevel};
|
||||
use ipc_channel::ipc;
|
||||
use ipc_channel::router::ROUTER;
|
||||
|
@ -296,15 +297,18 @@ impl AsyncResponseListener for StylesheetContext {
|
|||
fn response_complete(&mut self, status: Result<(), NetworkError>) {
|
||||
let elem = self.elem.root();
|
||||
let document = document_from_node(&*elem);
|
||||
let mut successful = false;
|
||||
|
||||
if status.is_err() {
|
||||
self.elem.root().upcast::<EventTarget>().fire_simple_event("error");
|
||||
} else {
|
||||
let data = mem::replace(&mut self.data, vec!());
|
||||
if status.is_ok() {
|
||||
let metadata = match self.metadata.take() {
|
||||
Some(meta) => meta,
|
||||
None => return,
|
||||
};
|
||||
let is_css = metadata.content_type.map_or(false, |ContentType(Mime(top, sub, _))|
|
||||
top == TopLevel::Text && sub == SubLevel::Css);
|
||||
|
||||
let data = if is_css { mem::replace(&mut self.data, vec!()) } else { vec!() };
|
||||
|
||||
// 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);
|
||||
|
@ -328,6 +332,9 @@ impl AsyncResponseListener for StylesheetContext {
|
|||
|
||||
*elem.stylesheet.borrow_mut() = Some(sheet);
|
||||
document.invalidate_stylesheets();
|
||||
|
||||
// FIXME: Revisit once consensus is reached at: https://github.com/whatwg/html/issues/1142
|
||||
successful = metadata.status.map_or(false, |RawStatus(code, _)| code == 200);
|
||||
}
|
||||
|
||||
if elem.parser_inserted.get() {
|
||||
|
@ -335,6 +342,10 @@ impl AsyncResponseListener for StylesheetContext {
|
|||
}
|
||||
|
||||
document.finish_load(LoadType::Stylesheet(self.url.clone()));
|
||||
|
||||
let event = if successful { "load" } else { "error" };
|
||||
|
||||
elem.upcast::<EventTarget>().fire_simple_event(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
[content-type-001.htm]
|
||||
type: reftest
|
||||
expected: FAIL
|
|
@ -10,12 +10,9 @@ var t = async_test("Check if the stylesheet's load event blocks the document loa
|
|||
document.getElementById('style_test').onload = t.step_func(function() {
|
||||
saw_link_onload = true;
|
||||
});
|
||||
window.addEventListener('load', function() {
|
||||
t.step_func(function() {
|
||||
assert_true(saw_link_onload);
|
||||
});
|
||||
t.done();
|
||||
}, false);
|
||||
window.addEventListener('load', t.step_func_done(function() {
|
||||
assert_true(saw_link_onload);
|
||||
}));
|
||||
</script>
|
||||
</head>
|
||||
</html>
|
||||
|
|
|
@ -40,6 +40,7 @@ tText.step(function() {
|
|||
assert_true(true, "Got error event for 404 error.")
|
||||
tText.done()
|
||||
})
|
||||
elt.onload = tText.unreached_func("load event should not be fired");
|
||||
elt.rel = "stylesheet";
|
||||
elt.href = "../../../../../common/css-red.txt";
|
||||
document.getElementsByTagName("head")[0].appendChild(elt);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue