Auto merge of #13525 - servo:empty-href, r=emilio

Ignore stylesheet links with an empty href.

<!-- 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/13525)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-10-02 13:02:14 -05:00 committed by GitHub
commit 3eb6fc4818
5 changed files with 104 additions and 49 deletions

View file

@ -197,62 +197,69 @@ impl VirtualMethods for HTMLLinkElement {
impl HTMLLinkElement { impl HTMLLinkElement {
/// https://html.spec.whatwg.org/multipage/#concept-link-obtain
fn handle_stylesheet_url(&self, href: &str) { fn handle_stylesheet_url(&self, href: &str) {
let document = document_from_node(self); let document = document_from_node(self);
if document.browsing_context().is_none() { if document.browsing_context().is_none() {
return; return;
} }
match document.base_url().join(href) { // Step 1.
Ok(url) => { if href.is_empty() {
let element = self.upcast::<Element>(); return;
let mq_attribute = element.get_attribute(&ns!(), &atom!("media"));
let value = mq_attribute.r().map(|a| a.value());
let mq_str = match value {
Some(ref value) => &***value,
None => "",
};
let mut css_parser = CssParser::new(&mq_str);
let media = parse_media_query_list(&mut css_parser);
// TODO: #8085 - Don't load external stylesheets if the node's mq doesn't match.
let elem = Trusted::new(self);
let context = Arc::new(Mutex::new(StylesheetContext {
elem: elem,
media: Some(media),
data: vec!(),
metadata: None,
url: url.clone(),
}));
let (action_sender, action_receiver) = ipc::channel().unwrap();
let listener = NetworkListener {
context: context,
script_chan: document.window().networking_task_source(),
wrapper: Some(document.window().get_runnable_wrapper()),
};
let response_target = AsyncResponseTarget {
sender: action_sender,
};
ROUTER.add_route(action_receiver.to_opaque(), box move |message| {
listener.notify_action(message.to().unwrap());
});
if self.parser_inserted.get() {
document.increment_script_blocking_stylesheet_count();
}
let referrer_policy = match self.RelList().Contains("noreferrer".into()) {
true => Some(ReferrerPolicy::NoReferrer),
false => None,
};
document.load_async(LoadType::Stylesheet(url), response_target, referrer_policy);
}
Err(e) => debug!("Parsing url {} failed: {}", href, e)
} }
// Step 2.
let url = match document.base_url().join(href) {
Err(e) => return debug!("Parsing url {} failed: {}", href, e),
Ok(url) => url,
};
let element = self.upcast::<Element>();
let mq_attribute = element.get_attribute(&ns!(), &atom!("media"));
let value = mq_attribute.r().map(|a| a.value());
let mq_str = match value {
Some(ref value) => &***value,
None => "",
};
let mut css_parser = CssParser::new(&mq_str);
let media = parse_media_query_list(&mut css_parser);
// TODO: #8085 - Don't load external stylesheets if the node's mq doesn't match.
let elem = Trusted::new(self);
let context = Arc::new(Mutex::new(StylesheetContext {
elem: elem,
media: Some(media),
data: vec!(),
metadata: None,
url: url.clone(),
}));
let (action_sender, action_receiver) = ipc::channel().unwrap();
let listener = NetworkListener {
context: context,
script_chan: document.window().networking_task_source(),
wrapper: Some(document.window().get_runnable_wrapper()),
};
let response_target = AsyncResponseTarget {
sender: action_sender,
};
ROUTER.add_route(action_receiver.to_opaque(), box move |message| {
listener.notify_action(message.to().unwrap());
});
if self.parser_inserted.get() {
document.increment_script_blocking_stylesheet_count();
}
let referrer_policy = match self.RelList().Contains("noreferrer".into()) {
true => Some(ReferrerPolicy::NoReferrer),
false => None,
};
document.load_async(LoadType::Stylesheet(url), response_target, referrer_policy);
} }
fn handle_favicon_url(&self, rel: &str, href: &str, sizes: &Option<String>) { fn handle_favicon_url(&self, rel: &str, href: &str, sizes: &Option<String>) {

View file

@ -37715,6 +37715,18 @@
"deleted_reftests": {}, "deleted_reftests": {},
"items": { "items": {
"reftest": { "reftest": {
"html/semantics/document-metadata/the-link-element/stylesheet-empty-href.html": [
{
"path": "html/semantics/document-metadata/the-link-element/stylesheet-empty-href.html",
"references": [
[
"/html/semantics/document-metadata/the-link-element/stylesheet-empty-href-ref.html",
"=="
]
],
"url": "/html/semantics/document-metadata/the-link-element/stylesheet-empty-href.html"
}
],
"html/semantics/document-metadata/the-link-element/stylesheet-media.html": [ "html/semantics/document-metadata/the-link-element/stylesheet-media.html": [
{ {
"path": "html/semantics/document-metadata/the-link-element/stylesheet-media.html", "path": "html/semantics/document-metadata/the-link-element/stylesheet-media.html",
@ -37744,6 +37756,18 @@
} }
}, },
"reftest_nodes": { "reftest_nodes": {
"html/semantics/document-metadata/the-link-element/stylesheet-empty-href.html": [
{
"path": "html/semantics/document-metadata/the-link-element/stylesheet-empty-href.html",
"references": [
[
"/html/semantics/document-metadata/the-link-element/stylesheet-empty-href-ref.html",
"=="
]
],
"url": "/html/semantics/document-metadata/the-link-element/stylesheet-empty-href.html"
}
],
"html/semantics/document-metadata/the-link-element/stylesheet-media.html": [ "html/semantics/document-metadata/the-link-element/stylesheet-media.html": [
{ {
"path": "html/semantics/document-metadata/the-link-element/stylesheet-media.html", "path": "html/semantics/document-metadata/the-link-element/stylesheet-media.html",

View file

@ -0,0 +1,9 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Test</title>
<style>
body {
color: green;
}
</style>
<p>This text should be green.

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Test</title>
<link rel=match href=stylesheet-empty-href-ref.html>
<style>
body {
color: green;
}
</style>
<base href=resources/empty-href.css>
<link rel=stylesheet href>
<p>This text should be green.