diff options
author | Till Schneidereit <till@tillschneidereit.net> | 2015-10-12 16:03:42 +0200 |
---|---|---|
committer | Till Schneidereit <till@tillschneidereit.net> | 2015-10-26 21:35:09 +0100 |
commit | a0c5d47910556c1df9a6947b2049a94a562c571c (patch) | |
tree | 21ca1484b754bdc0720d9b6752828b5f2da93c6c /components/script/document_loader.rs | |
parent | 6b95c3957b32db1f7a25738229381e046e9be6e7 (diff) | |
download | servo-a0c5d47910556c1df9a6947b2049a94a562c571c.tar.gz servo-a0c5d47910556c1df9a6947b2049a94a562c571c.zip |
Improve spec-compliance of script loading and execution during document startup
Including proper support for async and deferred scripts.
Diffstat (limited to 'components/script/document_loader.rs')
-rw-r--r-- | components/script/document_loader.rs | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/components/script/document_loader.rs b/components/script/document_loader.rs index 65e875b538b..2cfa9096d9c 100644 --- a/components/script/document_loader.rs +++ b/components/script/document_loader.rs @@ -8,9 +8,7 @@ use msg::constellation_msg::{PipelineId}; use net_traits::AsyncResponseTarget; use net_traits::{Metadata, PendingAsyncLoad, ResourceTask, load_whole_resource}; -use script_task::MainThreadScriptMsg; use std::sync::Arc; -use std::sync::mpsc::Sender; use url::Url; #[derive(JSTraceable, PartialEq, Clone, Debug, HeapSizeOf)] @@ -40,15 +38,9 @@ pub struct DocumentLoader { /// are lots of iframes. #[ignore_heap_size_of = "channels are hard"] pub resource_task: Arc<ResourceTask>, - notifier_data: Option<NotifierData>, + pipeline: Option<PipelineId>, blocking_loads: Vec<LoadType>, -} - -#[derive(JSTraceable, HeapSizeOf)] -pub struct NotifierData { - #[ignore_heap_size_of = "trait objects are hard"] - pub script_chan: Sender<MainThreadScriptMsg>, - pub pipeline: PipelineId, + events_inhibited: bool, } impl DocumentLoader { @@ -59,15 +51,16 @@ impl DocumentLoader { /// We use an `Arc<ResourceTask>` here in order to avoid file descriptor exhaustion when there /// are lots of iframes. pub fn new_with_task(resource_task: Arc<ResourceTask>, - data: Option<NotifierData>, + pipeline: Option<PipelineId>, initial_load: Option<Url>) -> DocumentLoader { let initial_loads = initial_load.into_iter().map(LoadType::PageSource).collect(); DocumentLoader { resource_task: resource_task, - notifier_data: data, + pipeline: pipeline, blocking_loads: initial_loads, + events_inhibited: false, } } @@ -76,8 +69,7 @@ impl DocumentLoader { pub fn prepare_async_load(&mut self, load: LoadType) -> PendingAsyncLoad { let url = load.url().clone(); self.blocking_loads.push(load); - let pipeline = self.notifier_data.as_ref().map(|data| data.pipeline); - PendingAsyncLoad::new((*self.resource_task).clone(), url, pipeline) + PendingAsyncLoad::new((*self.resource_task).clone(), url, self.pipeline) } /// Create and initiate a new network request. @@ -98,12 +90,6 @@ impl DocumentLoader { pub fn finish_load(&mut self, load: LoadType) { let idx = self.blocking_loads.iter().position(|unfinished| *unfinished == 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() { - script_chan.send(MainThreadScriptMsg::DocumentLoadsComplete(pipeline)).unwrap(); - } - } } pub fn is_blocked(&self) -> bool { @@ -112,6 +98,9 @@ impl DocumentLoader { } pub fn inhibit_events(&mut self) { - self.notifier_data = None; + self.events_inhibited = true; + } + pub fn events_inhibited(&self) -> bool { + self.events_inhibited } } |