aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/script_thread.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/script_thread.rs')
-rw-r--r--components/script/script_thread.rs56
1 files changed, 34 insertions, 22 deletions
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs
index 96555524c5d..aeed396fbb1 100644
--- a/components/script/script_thread.rs
+++ b/components/script/script_thread.rs
@@ -58,15 +58,14 @@ use hyper::mime::{Mime, SubLevel, TopLevel};
use ipc_channel::ipc::{self, IpcSender};
use ipc_channel::router::ROUTER;
use js::glue::GetWindowProxyClass;
-use js::jsapi::{DOMProxyShadowsResult, HandleId, HandleObject, RootedValue};
+use js::jsapi::{DOMProxyShadowsResult, HandleId, HandleObject};
use js::jsapi::{JSAutoCompartment, JSContext, JS_SetWrapObjectCallbacks};
use js::jsapi::{JSTracer, SetWindowProxyClass};
use js::jsval::UndefinedValue;
use js::rust::Runtime;
use mem::heap_size_of_self_and_children;
use msg::constellation_msg::{FrameType, LoadData, PanicMsg, PipelineId, PipelineNamespace};
-use msg::constellation_msg::{SubpageId, WindowSizeData, WindowSizeType};
-use msg::webdriver_msg::WebDriverScriptCommand;
+use msg::constellation_msg::{SubpageId, WindowSizeType};
use net_traits::LoadData as NetLoadData;
use net_traits::bluetooth_thread::BluetoothMethodMsg;
use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheResult, ImageCacheThread};
@@ -83,11 +82,12 @@ use script_runtime::{CommonScriptMsg, ScriptChan, ScriptThreadEventCategory};
use script_runtime::{ScriptPort, StackRootTLS, new_rt_and_cx, get_reports};
use script_traits::CompositorEvent::{KeyEvent, MouseButtonEvent, MouseMoveEvent, ResizeEvent};
use script_traits::CompositorEvent::{TouchEvent, TouchpadPressureEvent};
+use script_traits::webdriver_msg::WebDriverScriptCommand;
use script_traits::{CompositorEvent, ConstellationControlMsg, EventResult};
use script_traits::{InitialScriptState, MouseButton, MouseEventType, MozBrowserEvent};
use script_traits::{NewLayoutInfo, ScriptMsg as ConstellationMsg};
use script_traits::{ScriptThreadFactory, TimerEvent, TimerEventRequest, TimerSource};
-use script_traits::{TouchEventType, TouchId, UntrustedNodeAddress};
+use script_traits::{TouchEventType, TouchId, UntrustedNodeAddress, WindowSizeData};
use std::borrow::ToOwned;
use std::cell::Cell;
use std::collections::{HashMap, HashSet};
@@ -174,10 +174,10 @@ pub struct RunnableWrapper {
}
impl RunnableWrapper {
- pub fn wrap_runnable<T: Runnable + Send + 'static>(&self, runnable: T) -> Box<Runnable + Send> {
+ pub fn wrap_runnable<T: Runnable + Send + 'static>(&self, runnable: Box<T>) -> Box<Runnable + Send> {
box CancellableRunnable {
cancelled: self.cancelled.clone(),
- inner: box runnable,
+ inner: runnable,
}
}
}
@@ -189,8 +189,14 @@ pub struct CancellableRunnable<T: Runnable + Send> {
}
impl<T: Runnable + Send> Runnable for CancellableRunnable<T> {
+ fn name(&self) -> &'static str { self.inner.name() }
+
fn is_cancelled(&self) -> bool {
- self.cancelled.load(Ordering::Relaxed)
+ self.cancelled.load(Ordering::SeqCst)
+ }
+
+ fn main_thread_handler(self: Box<CancellableRunnable<T>>, script_thread: &ScriptThread) {
+ self.inner.main_thread_handler(script_thread);
}
fn handler(self: Box<CancellableRunnable<T>>) {
@@ -200,11 +206,9 @@ impl<T: Runnable + Send> Runnable for CancellableRunnable<T> {
pub trait Runnable {
fn is_cancelled(&self) -> bool { false }
- fn handler(self: Box<Self>);
-}
-
-pub trait MainThreadRunnable {
- fn handler(self: Box<Self>, script_thread: &ScriptThread);
+ fn name(&self) -> &'static str { "generic runnable" }
+ fn handler(self: Box<Self>) {}
+ fn main_thread_handler(self: Box<Self>, _script_thread: &ScriptThread) { self.handler(); }
}
enum MixedMessage {
@@ -571,6 +575,8 @@ impl ScriptThread {
// Ask the router to proxy IPC messages from the control port to us.
let control_port = ROUTER.route_ipc_receiver_to_new_mpsc_receiver(state.control_port);
+ let boxed_script_sender = MainThreadScriptChan(chan.clone()).clone();
+
ScriptThread {
browsing_context: MutNullableHeap::new(None),
incomplete_loads: DOMRefCell::new(vec!()),
@@ -591,8 +597,8 @@ impl ScriptThread {
dom_manipulation_task_source: DOMManipulationTaskSource(chan.clone()),
user_interaction_task_source: UserInteractionTaskSource(chan.clone()),
networking_task_source: NetworkingTaskSource(chan.clone()),
- history_traversal_task_source: HistoryTraversalTaskSource(chan.clone()),
- file_reading_task_source: FileReadingTaskSource(chan),
+ history_traversal_task_source: HistoryTraversalTaskSource(chan),
+ file_reading_task_source: FileReadingTaskSource(boxed_script_sender),
control_chan: state.control_chan,
control_port: control_port,
@@ -984,7 +990,7 @@ impl ScriptThread {
MainThreadScriptMsg::DOMManipulation(task) =>
task.handle_task(self),
MainThreadScriptMsg::UserInteraction(task) =>
- task.handle_task(),
+ task.handle_task(self),
}
}
@@ -1223,7 +1229,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(DOMManipulationTask::DocumentProgress(handler)).unwrap();
+ self.dom_manipulation_task_source.queue(handler, GlobalRef::Window(doc.window())).unwrap();
self.constellation_chan.send(ConstellationMsg::LoadComplete(pipeline)).unwrap();
}
@@ -1581,7 +1587,6 @@ impl ScriptThread {
let UserInteractionTaskSource(ref user_sender) = self.user_interaction_task_source;
let NetworkingTaskSource(ref network_sender) = self.networking_task_source;
let HistoryTraversalTaskSource(ref history_sender) = self.history_traversal_task_source;
- let FileReadingTaskSource(ref file_sender) = self.file_reading_task_source;
let (ipc_timer_event_chan, ipc_timer_event_port) = ipc::channel().unwrap();
ROUTER.route_ipc_receiver_to_mpsc_sender(ipc_timer_event_port,
@@ -1594,7 +1599,7 @@ impl ScriptThread {
UserInteractionTaskSource(user_sender.clone()),
NetworkingTaskSource(network_sender.clone()),
HistoryTraversalTaskSource(history_sender.clone()),
- FileReadingTaskSource(file_sender.clone()),
+ self.file_reading_task_source.clone(),
self.image_cache_channel.clone(),
self.custom_message_chan.clone(),
self.image_cache_thread.clone(),
@@ -1706,6 +1711,11 @@ impl ScriptThread {
_ => IsHTMLDocument::HTMLDocument,
};
+ let referrer = match metadata.referrer {
+ Some(ref referrer) => Some(referrer.clone().into_string()),
+ None => None,
+ };
+
let document = Document::new(window.r(),
Some(&browsing_context),
Some(final_url.clone()),
@@ -1713,7 +1723,8 @@ impl ScriptThread {
content_type,
last_modified,
DocumentSource::FromParser,
- loader);
+ loader,
+ referrer);
if using_new_context {
browsing_context.init(&document);
} else {
@@ -1747,7 +1758,7 @@ impl ScriptThread {
// Script source is ready to be evaluated (11.)
unsafe {
let _ac = JSAutoCompartment::new(self.get_cx(), window.reflector().get_jsobject().get());
- let mut jsval = RootedValue::new(self.get_cx(), UndefinedValue());
+ rooted!(in(self.get_cx()) let mut jsval = UndefinedValue());
window.evaluate_js_on_global_with_result(&script_source, jsval.handle_mut());
let strval = DOMString::from_jsval(self.get_cx(),
jsval.handle(),
@@ -1937,12 +1948,12 @@ impl ScriptThread {
document.r().handle_touchpad_pressure_event(self.js_runtime.rt(), point, pressure, phase);
}
- KeyEvent(key, state, modifiers) => {
+ KeyEvent(ch, key, state, modifiers) => {
let document = match self.root_browsing_context().find(pipeline_id) {
Some(browsing_context) => browsing_context.active_document(),
None => return warn!("Message sent to closed pipeline {}.", pipeline_id),
};
- document.dispatch_key_event(key, state, modifiers, &self.constellation_chan);
+ document.dispatch_key_event(ch, key, state, modifiers, &self.constellation_chan);
}
}
}
@@ -2057,6 +2068,7 @@ impl ScriptThread {
let listener = NetworkListener {
context: context,
script_chan: self.chan.clone(),
+ wrapper: None,
};
ROUTER.add_route(action_receiver.to_opaque(), box move |message| {
listener.notify_action(message.to().unwrap());