Make task queue API usable from non-main threads.

This commit is contained in:
Josh Matthews 2016-07-14 13:05:01 -04:00
parent 0e4865ea1a
commit 2aef518ce6
9 changed files with 42 additions and 21 deletions

View file

@ -5,6 +5,7 @@
use dom::attr::Attr;
use dom::bindings::codegen::Bindings::HTMLDetailsElementBinding;
use dom::bindings::codegen::Bindings::HTMLDetailsElementBinding::HTMLDetailsElementMethods;
use dom::bindings::global::GlobalRef;
use dom::bindings::inheritance::Castable;
use dom::bindings::js::Root;
use dom::bindings::refcounted::Trusted;
@ -78,7 +79,7 @@ impl VirtualMethods for HTMLDetailsElement {
element: details,
toggle_number: counter
};
let _ = task_source.queue(runnable, window.r());
let _ = task_source.queue(runnable, GlobalRef::Window(&window));
}
}
}

View file

@ -12,6 +12,7 @@ use dom::bindings::codegen::Bindings::HTMLFormElementBinding::HTMLFormElementMet
use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods;
use dom::bindings::codegen::Bindings::HTMLTextAreaElementBinding::HTMLTextAreaElementMethods;
use dom::bindings::conversions::DerivedFrom;
use dom::bindings::global::GlobalRef;
use dom::bindings::inheritance::{Castable, ElementTypeId, HTMLElementTypeId, NodeTypeId};
use dom::bindings::js::{JS, MutNullableHeap, Root};
use dom::bindings::refcounted::Trusted;
@ -484,7 +485,7 @@ impl HTMLFormElement {
};
// Step 3
window.dom_manipulation_task_source().queue(nav, window).unwrap();
window.dom_manipulation_task_source().queue(nav, GlobalRef::Window(window)).unwrap();
}
/// Interactively validate the constraints of form elements

View file

@ -184,7 +184,7 @@ impl HTMLImageElement {
src: src.into(),
};
let task = window.dom_manipulation_task_source();
let _ = task.queue(runnable, window);
let _ = task.queue(runnable, GlobalRef::Window(window));
}
}
}

View file

@ -241,7 +241,7 @@ impl HTMLMediaElement {
elem: Trusted::new(self),
};
let win = window_from_node(self);
let _ = win.dom_manipulation_task_source().queue(task, win.r());
let _ = win.dom_manipulation_task_source().queue(task, GlobalRef::Window(&win));
}
// https://html.spec.whatwg.org/multipage/#internal-pause-steps step 2.2
@ -265,13 +265,13 @@ impl HTMLMediaElement {
elem: Trusted::new(self),
};
let win = window_from_node(self);
let _ = win.dom_manipulation_task_source().queue(task, win.r());
let _ = win.dom_manipulation_task_source().queue(task, GlobalRef::Window(&win));
}
fn queue_fire_simple_event(&self, type_: &'static str) {
let win = window_from_node(self);
let task = box FireSimpleEventTask::new(self, type_);
let _ = win.dom_manipulation_task_source().queue(task, win.r());
let _ = win.dom_manipulation_task_source().queue(task, GlobalRef::Window(&win));
}
fn fire_simple_event(&self, type_: &str) {
@ -498,7 +498,8 @@ impl HTMLMediaElement {
fn queue_dedicated_media_source_failure_steps(&self) {
let window = window_from_node(self);
let _ = window.dom_manipulation_task_source().queue(box DedicatedMediaSourceFailureTask::new(self), window.r());
let _ = window.dom_manipulation_task_source().queue(box DedicatedMediaSourceFailureTask::new(self),
GlobalRef::Window(&window));
}
// https://html.spec.whatwg.org/multipage/#dedicated-media-source-failure-steps

View file

@ -161,7 +161,8 @@ impl Storage {
let window = global_ref.as_window();
let task_source = window.dom_manipulation_task_source();
let trusted_storage = Trusted::new(self);
task_source.queue(box StorageEventRunnable::new(trusted_storage, key, old_value, new_value), window).unwrap();
task_source.queue(box StorageEventRunnable::new(trusted_storage, key, old_value, new_value),
global_ref).unwrap();
}
}

View file

@ -1227,7 +1227,7 @@ impl ScriptThread {
// https://html.spec.whatwg.org/multipage/#the-end step 7
let handler = box DocumentProgressHandler::new(Trusted::new(doc));
self.dom_manipulation_task_source.queue(handler, doc.window()).unwrap();
self.dom_manipulation_task_source.queue(handler, GlobalRef::Window(doc.window())).unwrap();
self.constellation_chan.send(ConstellationMsg::LoadComplete(pipeline)).unwrap();
}

View file

@ -2,11 +2,12 @@
* 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 dom::bindings::global::GlobalRef;
use dom::bindings::refcounted::Trusted;
use dom::event::{EventBubbles, EventCancelable, EventRunnable, SimpleEventRunnable};
use dom::eventtarget::EventTarget;
use dom::window::Window;
use script_thread::{MainThreadScriptMsg, Runnable, ScriptThread};
use script_thread::{MainThreadScriptMsg, Runnable, RunnableWrapper, ScriptThread};
use std::result::Result;
use std::sync::mpsc::Sender;
use string_cache::Atom;
@ -16,8 +17,12 @@ use task_source::TaskSource;
pub struct DOMManipulationTaskSource(pub Sender<MainThreadScriptMsg>);
impl TaskSource for DOMManipulationTaskSource {
fn queue<T: Runnable + Send + 'static>(&self, msg: Box<T>, window: &Window) -> Result<(), ()> {
let msg = DOMManipulationTask(window.get_runnable_wrapper().wrap_runnable(msg));
fn queue_with_wrapper<T>(&self,
msg: Box<T>,
wrapper: &RunnableWrapper)
-> Result<(), ()>
where T: Runnable + Send + 'static {
let msg = DOMManipulationTask(wrapper.wrap_runnable(msg));
self.0.send(MainThreadScriptMsg::DOMManipulation(msg)).map_err(|_| ())
}
}
@ -36,7 +41,7 @@ impl DOMManipulationTaskSource {
bubbles: bubbles,
cancelable: cancelable,
};
let _ = self.queue(runnable, window);
let _ = self.queue(runnable, GlobalRef::Window(window));
}
pub fn queue_simple_event(&self, target: &EventTarget, name: Atom, window: &Window) {
@ -45,7 +50,7 @@ impl DOMManipulationTaskSource {
target: target,
name: name,
};
let _ = self.queue(runnable, window);
let _ = self.queue(runnable, GlobalRef::Window(window));
}
}

View file

@ -8,10 +8,17 @@ pub mod history_traversal;
pub mod networking;
pub mod user_interaction;
use dom::window::Window;
use script_thread::Runnable;
use dom::bindings::global::GlobalRef;
use script_thread::{Runnable, RunnableWrapper};
use std::result::Result;
pub trait TaskSource {
fn queue<T: Runnable + Send + 'static>(&self, msg: Box<T>, window: &Window) -> Result<(), ()>;
fn queue_with_wrapper<T>(&self,
msg: Box<T>,
wrapper: &RunnableWrapper)
-> Result<(), ()>
where T: Runnable + Send + 'static;
fn queue<T: Runnable + Send + 'static>(&self, msg: Box<T>, global: GlobalRef) -> Result<(), ()> {
self.queue_with_wrapper(msg, &global.get_runnable_wrapper())
}
}

View file

@ -2,11 +2,12 @@
* 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 dom::bindings::global::GlobalRef;
use dom::bindings::refcounted::Trusted;
use dom::event::{EventBubbles, EventCancelable, EventRunnable};
use dom::eventtarget::EventTarget;
use dom::window::Window;
use script_thread::{MainThreadScriptMsg, Runnable, ScriptThread};
use script_thread::{MainThreadScriptMsg, Runnable, RunnableWrapper, ScriptThread};
use std::result::Result;
use std::sync::mpsc::Sender;
use string_cache::Atom;
@ -16,8 +17,12 @@ use task_source::TaskSource;
pub struct UserInteractionTaskSource(pub Sender<MainThreadScriptMsg>);
impl TaskSource for UserInteractionTaskSource {
fn queue<T: Runnable + Send + 'static>(&self, msg: Box<T>, window: &Window) -> Result<(), ()> {
let msg = UserInteractionTask(window.get_runnable_wrapper().wrap_runnable(msg));
fn queue_with_wrapper<T>(&self,
msg: Box<T>,
wrapper: &RunnableWrapper)
-> Result<(), ()>
where T: Runnable + Send + 'static {
let msg = UserInteractionTask(wrapper.wrap_runnable(msg));
self.0.send(MainThreadScriptMsg::UserInteraction(msg)).map_err(|_| ())
}
}
@ -36,7 +41,7 @@ impl UserInteractionTaskSource {
bubbles: bubbles,
cancelable: cancelable,
};
let _ = self.queue(runnable, window);
let _ = self.queue(runnable, GlobalRef::Window(window));
}
}