servo: Merge #5727 - Make external script sources load asynchronously, yet still block furthe (from jdm:parserinterrupt2); r=mbrubeck

...r parsing. Hook up document loading to async networking events.

Relies on https://github.com/servo/html5ever/pull/107, so we'll likely need to backport it rather than wait for the next rustc upgrade.

Source-Repo: https://github.com/servo/servo
Source-Revision: dd319c1a998bbd3eeb84fdc4ca8a41ee7877ca37
This commit is contained in:
Josh Matthews
2015-05-21 12:37:06 -05:00
parent cac2fc4d3c
commit c3f30a7985
9 changed files with 432 additions and 180 deletions

View File

@@ -7,13 +7,12 @@
use script_task::{ScriptMsg, ScriptChan};
use msg::constellation_msg::{PipelineId};
use net_traits::{LoadResponse, Metadata, load_whole_resource, ResourceTask, PendingAsyncLoad};
use net_traits::{Metadata, load_whole_resource, ResourceTask, PendingAsyncLoad};
use net_traits::AsyncResponseTarget;
use url::Url;
use std::sync::mpsc::Receiver;
#[jstraceable]
#[derive(PartialEq, Clone)]
#[derive(PartialEq, Clone, Debug)]
pub enum LoadType {
Image(Url),
Script(Url),
@@ -75,9 +74,9 @@ impl DocumentLoader {
}
/// Create and initiate a new network request.
pub fn load_async(&mut self, load: LoadType) -> Receiver<LoadResponse> {
pub fn load_async(&mut self, load: LoadType, listener: Box<AsyncResponseTarget + Send>) {
let pending = self.prepare_async_load(load);
pending.load()
pending.load_async(listener)
}
/// Create, initiate, and await the response for a new network request.
@@ -91,7 +90,7 @@ impl DocumentLoader {
/// Mark an in-progress network request complete.
pub fn finish_load(&mut self, load: LoadType) {
let idx = self.blocking_loads.iter().position(|unfinished| *unfinished == load);
self.blocking_loads.remove(idx.expect("unknown completed load"));
self.blocking_loads.remove(idx.expect(&format!("unknown completed load {:?}", load)));
if let Some(NotifierData { ref script_chan, pipeline }) = self.notifier_data {
if !self.is_blocked() {
@@ -101,6 +100,7 @@ impl DocumentLoader {
}
pub fn is_blocked(&self) -> bool {
//TODO: Ensure that we report blocked if parsing is still ongoing.
!self.blocking_loads.is_empty()
}