mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
auto merge of #2152 : jsanders/servo/fix-inline-css-resource-task-failure, r=jdm
Fixes #2121 I thought this would be better than passing an `Option<ResourceTask>` to `parse_css` because it avoids having to handle the potential failure at runtime when unwrapping. No test included, but the error was reproducible by running content/test_getBoundingClientRect.html, and this fixes it. Glad to find a way to add an explicit test if need be.
This commit is contained in:
commit
4379809e88
2 changed files with 8 additions and 12 deletions
|
@ -14,23 +14,21 @@ use url::Url;
|
||||||
|
|
||||||
/// Where a style sheet comes from.
|
/// Where a style sheet comes from.
|
||||||
pub enum StylesheetProvenance {
|
pub enum StylesheetProvenance {
|
||||||
UrlProvenance(Url),
|
UrlProvenance(Url, ResourceTask),
|
||||||
InlineProvenance(Url, ~str),
|
InlineProvenance(Url, ~str),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parses the style data and returns the stylesheet
|
// Parses the style data and returns the stylesheet
|
||||||
pub fn parse_inline_css(url: Url, data: ~str) -> Stylesheet {
|
pub fn parse_inline_css(url: Url, data: ~str) -> Stylesheet {
|
||||||
let resource_task = ResourceTask(); // Resource task is not used for inline parsing
|
parse_css(InlineProvenance(url, data))
|
||||||
parse_css(InlineProvenance(url, data), resource_task)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_css(provenance: StylesheetProvenance,
|
fn parse_css(provenance: StylesheetProvenance) -> Stylesheet {
|
||||||
resource_task: ResourceTask) -> Stylesheet {
|
|
||||||
// TODO: Get the actual value. http://dev.w3.org/csswg/css-syntax/#environment-encoding
|
// TODO: Get the actual value. http://dev.w3.org/csswg/css-syntax/#environment-encoding
|
||||||
let environment_encoding = UTF_8 as EncodingRef;
|
let environment_encoding = UTF_8 as EncodingRef;
|
||||||
|
|
||||||
match provenance {
|
match provenance {
|
||||||
UrlProvenance(url) => {
|
UrlProvenance(url, resource_task) => {
|
||||||
debug!("cssparse: loading style sheet at {:s}", url.to_str());
|
debug!("cssparse: loading style sheet at {:s}", url.to_str());
|
||||||
let (input_chan, input_port) = channel();
|
let (input_chan, input_port) = channel();
|
||||||
resource_task.send(Load(url, input_chan));
|
resource_task.send(Load(url, input_chan));
|
||||||
|
@ -50,13 +48,11 @@ fn parse_css(provenance: StylesheetProvenance,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn spawn_css_parser(provenance: StylesheetProvenance,
|
pub fn spawn_css_parser(provenance: StylesheetProvenance) -> Receiver<Stylesheet> {
|
||||||
resource_task: ResourceTask)
|
|
||||||
-> Receiver<Stylesheet> {
|
|
||||||
let (result_chan, result_port) = channel();
|
let (result_chan, result_port) = channel();
|
||||||
|
|
||||||
spawn_named("cssparser", proc() {
|
spawn_named("cssparser", proc() {
|
||||||
result_chan.send(parse_css(provenance, resource_task));
|
result_chan.send(parse_css(provenance));
|
||||||
});
|
});
|
||||||
|
|
||||||
return result_port;
|
return result_port;
|
||||||
|
|
|
@ -111,7 +111,7 @@ fn css_link_listener(to_parent: Sender<HtmlDiscoveryMessage>,
|
||||||
loop {
|
loop {
|
||||||
match from_parent.recv_opt() {
|
match from_parent.recv_opt() {
|
||||||
Some(CSSTaskNewFile(provenance)) => {
|
Some(CSSTaskNewFile(provenance)) => {
|
||||||
result_vec.push(spawn_css_parser(provenance, resource_task.clone()));
|
result_vec.push(spawn_css_parser(provenance));
|
||||||
}
|
}
|
||||||
Some(CSSTaskExit) | None => {
|
Some(CSSTaskExit) | None => {
|
||||||
break;
|
break;
|
||||||
|
@ -357,7 +357,7 @@ pub fn parse_html(page: &Page,
|
||||||
}) => {
|
}) => {
|
||||||
debug!("found CSS stylesheet: {:s}", href.get().value_ref());
|
debug!("found CSS stylesheet: {:s}", href.get().value_ref());
|
||||||
let url = parse_url(href.get().value_ref(), Some(url2.clone()));
|
let url = parse_url(href.get().value_ref(), Some(url2.clone()));
|
||||||
css_chan2.send(CSSTaskNewFile(UrlProvenance(url)));
|
css_chan2.send(CSSTaskNewFile(UrlProvenance(url, resource_task.clone())));
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue