From a0c5d47910556c1df9a6947b2049a94a562c571c Mon Sep 17 00:00:00 2001 From: Till Schneidereit Date: Mon, 12 Oct 2015 16:03:42 +0200 Subject: Improve spec-compliance of script loading and execution during document startup Including proper support for async and deferred scripts. --- components/script/document_loader.rs | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) (limited to 'components/script/document_loader.rs') 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, - notifier_data: Option, + pipeline: Option, blocking_loads: Vec, -} - -#[derive(JSTraceable, HeapSizeOf)] -pub struct NotifierData { - #[ignore_heap_size_of = "trait objects are hard"] - pub script_chan: Sender, - pub pipeline: PipelineId, + events_inhibited: bool, } impl DocumentLoader { @@ -59,15 +51,16 @@ impl DocumentLoader { /// We use an `Arc` here in order to avoid file descriptor exhaustion when there /// are lots of iframes. pub fn new_with_task(resource_task: Arc, - data: Option, + pipeline: Option, initial_load: Option) -> 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 } } -- cgit v1.2.3