diff --git a/components/script/dom/eventsource.rs b/components/script/dom/eventsource.rs index f0b5726e6a319..48b762978ca09 100644 --- a/components/script/dom/eventsource.rs +++ b/components/script/dom/eventsource.rs @@ -100,7 +100,7 @@ impl EventSourceContext { let global = event_source.global(); let event_source = self.event_source.clone(); // FIXME(nox): Why are errors silenced here? - let _ = global.networking_task_source().queue( + let _ = global.remote_event_task_source().queue( task!(announce_the_event_source_connection: move || { let event_source = event_source.root(); if event_source.ready_state.get() != ReadyState::Closed { @@ -121,7 +121,7 @@ impl EventSourceContext { let global = event_source.global(); let event_source = self.event_source.clone(); // FIXME(nox): Why are errors silenced here? - let _ = global.networking_task_source().queue( + let _ = global.remote_event_task_source().queue( task!(fail_the_event_source_connection: move || { let event_source = event_source.root(); if event_source.ready_state.get() != ReadyState::Closed { @@ -145,7 +145,7 @@ impl EventSourceContext { let action_sender = self.action_sender.clone(); let global = event_source.global(); // FIXME(nox): Why are errors silenced here? - let _ = global.networking_task_source().queue( + let _ = global.remote_event_task_source().queue( task!(reestablish_the_event_source_onnection: move || { let event_source = trusted_event_source.root(); @@ -242,7 +242,7 @@ impl EventSourceContext { let event_source = self.event_source.clone(); let event = Trusted::new(&*event); // FIXME(nox): Why are errors silenced here? - let _ = global.networking_task_source().queue( + let _ = global.remote_event_task_source().queue( task!(dispatch_the_event_source_event: move || { let event_source = event_source.root(); if event_source.ready_state.get() != ReadyState::Closed { @@ -423,6 +423,7 @@ impl EventSource { self.request.borrow().clone().unwrap() } + // https://html.spec.whatwg.org/multipage/#dom-eventsource pub fn Constructor(global: &GlobalScope, url: DOMString, event_source_init: &EventSourceInit) -> Fallible> { @@ -482,8 +483,6 @@ impl EventSource { data: String::new(), last_event_id: String::new(), }; - // TODO: use the "remote event task source", and canceller. - // https://html.spec.whatwg.org/multipage/#remote-event-task-source let listener = NetworkListener { context: Arc::new(Mutex::new(context)), task_source: global.networking_task_source(), diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index 759216df27aa5..08e7b2d3d6289 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -56,6 +56,7 @@ use task_source::TaskSourceName; use task_source::file_reading::FileReadingTaskSource; use task_source::networking::NetworkingTaskSource; use task_source::performance_timeline::PerformanceTimelineTaskSource; +use task_source::remote_event::RemoteEventTaskSource; use time::{Timespec, get_time}; use timers::{IsInterval, OneshotTimerCallback, OneshotTimerHandle}; use timers::{OneshotTimers, TimerCallback}; @@ -390,7 +391,7 @@ impl GlobalScope { } /// `ScriptChan` to send messages to the networking task source of - /// this of this global scope. + /// this global scope. pub fn networking_task_source(&self) -> NetworkingTaskSource { if let Some(window) = self.downcast::() { return window.networking_task_source(); @@ -401,6 +402,18 @@ impl GlobalScope { unreachable!(); } + /// `ScriptChan` to send messages to the remote-event task source of + /// this global scope. + pub fn remote_event_task_source(&self) -> RemoteEventTaskSource { + if let Some(window) = self.downcast::() { + return window.remote_event_task_source(); + } + if let Some(worker) = self.downcast::() { + return worker.remote_event_task_source(); + } + unreachable!(); + } + /// Evaluate JS code on this global scope. pub fn evaluate_js_on_global_with_result( &self, code: &str, rval: MutableHandleValue) -> bool { diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index d0d6e49963958..ea3a92e0f379a 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -115,6 +115,7 @@ use task_source::file_reading::FileReadingTaskSource; use task_source::history_traversal::HistoryTraversalTaskSource; use task_source::networking::NetworkingTaskSource; use task_source::performance_timeline::PerformanceTimelineTaskSource; +use task_source::remote_event::RemoteEventTaskSource; use task_source::user_interaction::UserInteractionTaskSource; use time; use timers::{IsInterval, TimerCallback}; @@ -172,6 +173,8 @@ pub struct Window { file_reading_task_source: FileReadingTaskSource, #[ignore_malloc_size_of = "task sources are hard"] performance_timeline_task_source: PerformanceTimelineTaskSource, + #[ignore_malloc_size_of = "task sources are hard"] + remote_event_task_source: RemoteEventTaskSource, navigator: MutNullableDom, #[ignore_malloc_size_of = "Arc"] image_cache: Arc, @@ -358,6 +361,10 @@ impl Window { self.performance_timeline_task_source.clone() } + pub fn remote_event_task_source(&self) -> RemoteEventTaskSource { + self.remote_event_task_source.clone() + } + pub fn main_thread_script_chan(&self) -> &Sender { &self.script_chan.0 } @@ -1798,6 +1805,7 @@ impl Window { history_traversal_task_source: HistoryTraversalTaskSource, file_reading_task_source: FileReadingTaskSource, performance_timeline_task_source: PerformanceTimelineTaskSource, + remote_event_task_source: RemoteEventTaskSource, image_cache_chan: Sender, image_cache: Arc, resource_threads: ResourceThreads, @@ -1850,6 +1858,7 @@ impl Window { history_traversal_task_source, file_reading_task_source, performance_timeline_task_source, + remote_event_task_source, image_cache_chan, image_cache, navigator: Default::default(), diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs index 0f9924253aae9..431aaa6b156a1 100644 --- a/components/script/dom/workerglobalscope.rs +++ b/components/script/dom/workerglobalscope.rs @@ -46,6 +46,7 @@ use task::TaskCanceller; use task_source::file_reading::FileReadingTaskSource; use task_source::networking::NetworkingTaskSource; use task_source::performance_timeline::PerformanceTimelineTaskSource; +use task_source::remote_event::RemoteEventTaskSource; use time::precise_time_ns; use timers::{IsInterval, TimerCallback}; @@ -385,6 +386,10 @@ impl WorkerGlobalScope { PerformanceTimelineTaskSource(self.script_chan(), self.pipeline_id()) } + pub fn remote_event_task_source(&self) -> RemoteEventTaskSource { + RemoteEventTaskSource(self.script_chan(), self.pipeline_id()) + } + pub fn new_script_pair(&self) -> (Box, Box) { let dedicated = self.downcast::(); if let Some(dedicated) = dedicated { diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 7fffe13e74d16..13c5f1f7ba4c5 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -121,6 +121,7 @@ use task_source::file_reading::FileReadingTaskSource; use task_source::history_traversal::HistoryTraversalTaskSource; use task_source::networking::NetworkingTaskSource; use task_source::performance_timeline::PerformanceTimelineTaskSource; +use task_source::remote_event::RemoteEventTaskSource; use task_source::user_interaction::UserInteractionTaskSource; use time::{get_time, precise_time_ns, Tm}; use url::Position; @@ -436,6 +437,8 @@ pub struct ScriptThread { performance_timeline_task_sender: Box, + remote_event_task_sender: Box, + /// A channel to hand out to threads that need to respond to a message from the script thread. control_chan: IpcSender, @@ -850,6 +853,7 @@ impl ScriptThread { networking_task_sender: boxed_script_sender.clone(), file_reading_task_sender: boxed_script_sender.clone(), performance_timeline_task_sender: boxed_script_sender.clone(), + remote_event_task_sender: boxed_script_sender.clone(), history_traversal_task_source: HistoryTraversalTaskSource(chan), @@ -1805,6 +1809,10 @@ impl ScriptThread { FileReadingTaskSource(self.file_reading_task_sender.clone(), pipeline_id) } + pub fn remote_event_task_source(&self, pipeline_id: PipelineId) -> RemoteEventTaskSource { + RemoteEventTaskSource(self.remote_event_task_sender.clone(), pipeline_id) + } + /// Handles a request for the window title. fn handle_get_title_msg(&self, pipeline_id: PipelineId) { let document = match { self.documents.borrow().find_document(pipeline_id) } { @@ -2113,6 +2121,7 @@ impl ScriptThread { HistoryTraversalTaskSource(history_sender.clone()), self.file_reading_task_source(incomplete.pipeline_id), self.performance_timeline_task_source(incomplete.pipeline_id).clone(), + self.remote_event_task_source(incomplete.pipeline_id), self.image_cache_channel.clone(), self.image_cache.clone(), self.resource_threads.clone(), diff --git a/components/script/task_source/mod.rs b/components/script/task_source/mod.rs index cf605976b462d..23fb3e9ca8fb2 100644 --- a/components/script/task_source/mod.rs +++ b/components/script/task_source/mod.rs @@ -8,6 +8,7 @@ pub mod file_reading; pub mod history_traversal; pub mod networking; pub mod performance_timeline; +pub mod remote_event; pub mod user_interaction; use dom::globalscope::GlobalScope; @@ -26,7 +27,8 @@ pub enum TaskSourceName { HistoryTraversal, Networking, PerformanceTimeline, - UserInteraction + UserInteraction, + RemoteEvent } impl TaskSourceName { diff --git a/components/script/task_source/remote_event.rs b/components/script/task_source/remote_event.rs new file mode 100644 index 0000000000000..2d8428cddbfb6 --- /dev/null +++ b/components/script/task_source/remote_event.rs @@ -0,0 +1,36 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use msg::constellation_msg::PipelineId; +use script_runtime::{CommonScriptMsg, ScriptChan, ScriptThreadEventCategory}; +use task::{TaskCanceller, TaskOnce}; +use task_source::{TaskSource, TaskSourceName}; + +#[derive(JSTraceable)] +pub struct RemoteEventTaskSource(pub Box, pub PipelineId); + +impl Clone for RemoteEventTaskSource { + fn clone(&self) -> RemoteEventTaskSource { + RemoteEventTaskSource(self.0.clone(), self.1.clone()) + } +} + +impl TaskSource for RemoteEventTaskSource { + const NAME: TaskSourceName = TaskSourceName::RemoteEvent; + + fn queue_with_canceller( + &self, + task: T, + canceller: &TaskCanceller, + ) -> Result<(), ()> + where + T: TaskOnce + 'static, + { + self.0.send(CommonScriptMsg::Task( + ScriptThreadEventCategory::NetworkEvent, + Box::new(canceller.wrap_task(task)), + Some(self.1), + )) + } +}