Refactor resource loader protocol to send metadata first

This commit is contained in:
Keegan McAllister 2013-10-09 16:23:07 -07:00
parent cb67a50a95
commit 48af4e53a9
6 changed files with 81 additions and 65 deletions

View file

@ -25,7 +25,7 @@ use std::from_str::FromStr;
use hubbub::hubbub;
use servo_msg::constellation_msg::{ConstellationChan, SubpageId};
use servo_net::image_cache_task::ImageCacheTask;
use servo_net::resource_task::{ProgressMsg, Done, Load, Payload, UrlChange, ResourceTask};
use servo_net::resource_task::{Load, Payload, Done, ResourceTask};
use servo_util::tree::TreeNodeRef;
use servo_util::url::make_url;
use extra::url::Url;
@ -170,10 +170,10 @@ fn js_script_listener(to_parent: SharedChan<HtmlDiscoveryMessage>,
// TODO: change copy to move once we can move into closures
resource_task.send(Load(url.clone(), input_chan));
let progress_port = input_port.recv().progress_port;
let mut buf = ~[];
loop {
match input_port.recv() {
UrlChange(*) => (), // don't care that URL changed
match progress_port.recv() {
Payload(data) => {
buf.push_all(data);
}
@ -331,25 +331,13 @@ pub fn parse_html(cx: *JSContext,
}
let js_chan = SharedChan::new(js_msg_chan);
// Process any UrlChange messages before we build the parser, because the
// tree handler functions need to know the final URL.
let mut final_url = url.clone();
// Wait for the LoadResponse so that the parser knows the final URL.
let (input_port, input_chan) = comm::stream();
resource_task.send(Load(url.clone(), input_chan));
let mut progress_msg: ProgressMsg;
loop {
progress_msg = input_port.recv();
match progress_msg {
UrlChange(url) => {
debug!("page URL changed to %s", url.to_str());
final_url = url;
}
_ => break
}
}
let load_response = input_port.recv();
let url2 = final_url.clone();
let url3 = final_url.clone();
let url2 = load_response.metadata.final_url.clone();
let url3 = url2.clone();
// Build the root node.
let root = @HTMLHtmlElement { htmlelement: HTMLElement::new(HTMLHtmlElementTypeId, ~"html", document) };
@ -573,11 +561,7 @@ pub fn parse_html(cx: *JSContext,
debug!("loaded page");
loop {
// We already have a message from the earlier UrlChange processing.
match progress_msg {
UrlChange(*) => {
fail!("got UrlChange message after others");
}
match load_response.progress_port.recv() {
Payload(data) => {
debug!("received data");
parser.parse_chunk(data);
@ -589,7 +573,6 @@ pub fn parse_html(cx: *JSContext,
break;
}
}
progress_msg = input_port.recv();
}
css_chan.send(CSSTaskExit);
@ -598,7 +581,7 @@ pub fn parse_html(cx: *JSContext,
HtmlParserResult {
root: root,
discovery_port: discovery_port,
url: final_url,
url: load_response.metadata.final_url,
}
}