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.rs126
1 files changed, 55 insertions, 71 deletions
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs
index 330eebafdfe..5f83a467076 100644
--- a/components/script/script_thread.rs
+++ b/components/script/script_thread.rs
@@ -33,7 +33,7 @@ use dom::bindings::refcounted::{LiveDOMReferences, Trusted};
use dom::bindings::str::DOMString;
use dom::bindings::trace::JSTraceable;
use dom::bindings::utils::WRAP_CALLBACKS;
-use dom::browsingcontext::{BrowsingContext, IterableContext};
+use dom::browsingcontext::BrowsingContext;
use dom::document::{Document, DocumentProgressHandler, DocumentSource, FocusType, IsHTMLDocument};
use dom::element::Element;
use dom::event::{Event, EventBubbles, EventCancelable};
@@ -57,8 +57,7 @@ use js::jsapi::{DOMProxyShadowsResult, HandleId, HandleObject, RootedValue};
use js::jsapi::{JSContext, JS_SetWrapObjectCallbacks, JSTracer, SetWindowProxyClass};
use js::jsval::UndefinedValue;
use js::rust::Runtime;
-use layout_interface::{ReflowQueryType};
-use layout_interface::{self, LayoutChan, NewLayoutThreadInfo, ScriptLayoutChan};
+use layout_interface::{self, NewLayoutThreadInfo, ReflowQueryType};
use mem::heap_size_of_self_and_children;
use msg::constellation_msg::{LoadData, PanicMsg, PipelineId, PipelineNamespace};
use msg::constellation_msg::{SubpageId, WindowSizeData, WindowSizeType};
@@ -79,15 +78,15 @@ 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::{CompositorEvent, ConstellationControlMsg, EventResult};
-use script_traits::{InitialScriptState, MouseButton, MouseEventType, MozBrowserEvent, NewLayoutInfo};
-use script_traits::{LayoutMsg, OpaqueScriptLayoutChannel, ScriptMsg as ConstellationMsg};
-use script_traits::{ScriptThreadFactory, ScriptToCompositorMsg, TimerEvent, TimerEventRequest, TimerSource};
+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};
-use std::any::Any;
use std::borrow::ToOwned;
use std::cell::{Cell, RefCell};
use std::collections::HashSet;
use std::option::Option;
+use std::ptr;
use std::rc::Rc;
use std::result::Result;
use std::sync::atomic::{Ordering, AtomicBool};
@@ -132,7 +131,7 @@ struct InProgressLoad {
/// The current window size associated with this pipeline.
window_size: Option<WindowSizeData>,
/// Channel to the layout thread associated with this pipeline.
- layout_chan: LayoutChan,
+ layout_chan: Sender<layout_interface::Msg>,
/// The current viewport clipping rectangle applying to this pipeline, if any.
clip_rect: Option<Rect<f32>>,
/// Window is frozen (navigated away while loading for example).
@@ -145,7 +144,7 @@ impl InProgressLoad {
/// Create a new InProgressLoad object.
fn new(id: PipelineId,
parent_info: Option<(PipelineId, SubpageId)>,
- layout_chan: LayoutChan,
+ layout_chan: Sender<layout_interface::Msg>,
window_size: Option<WindowSizeData>,
url: Url) -> InProgressLoad {
InProgressLoad {
@@ -348,12 +347,6 @@ pub struct ScriptThread {
/// For communicating load url messages to the constellation
constellation_chan: IpcSender<ConstellationMsg>,
- /// For communicating layout messages to the constellation
- layout_to_constellation_chan: IpcSender<LayoutMsg>,
-
- /// A handle to the compositor for communicating ready state messages.
- compositor: IpcSender<ScriptToCompositorMsg>,
-
/// The port on which we receive messages from the image cache
image_cache_port: Receiver<ImageCacheResult>,
@@ -428,22 +421,16 @@ impl<'a> Drop for ScriptMemoryFailsafe<'a> {
}
impl ScriptThreadFactory for ScriptThread {
- fn create_layout_channel() -> OpaqueScriptLayoutChannel {
- let (chan, port) = channel();
- ScriptLayoutChan::new(chan, port)
- }
-
- fn clone_layout_channel(pair: &OpaqueScriptLayoutChannel)
- -> Box<Any + Send> {
- box pair.sender() as Box<Any + Send>
- }
+ type Message = layout_interface::Msg;
fn create(state: InitialScriptState,
- layout_chan: &OpaqueScriptLayoutChannel,
- load_data: LoadData) {
+ load_data: LoadData)
+ -> (Sender<layout_interface::Msg>, Receiver<layout_interface::Msg>) {
let panic_chan = state.panic_chan.clone();
let (script_chan, script_port) = channel();
- let layout_chan = LayoutChan(layout_chan.sender());
+
+ let (sender, receiver) = channel();
+ let layout_chan = sender.clone();
let pipeline_id = state.id;
thread::spawn_named_with_send_on_panic(format!("ScriptThread {:?}", state.id),
thread_state::SCRIPT,
@@ -456,8 +443,8 @@ impl ScriptThreadFactory for ScriptThread {
let mem_profiler_chan = state.mem_profiler_chan.clone();
let window_size = state.window_size;
let script_thread = ScriptThread::new(state,
- script_port,
- script_chan.clone());
+ script_port,
+ script_chan.clone());
SCRIPT_THREAD_ROOT.with(|root| {
*root.borrow_mut() = Some(&script_thread as *const _);
@@ -472,13 +459,14 @@ impl ScriptThreadFactory for ScriptThread {
let reporter_name = format!("script-reporter-{}", id);
mem_profiler_chan.run_with_memory_reporting(|| {
script_thread.start();
- let _ = script_thread.compositor.send(ScriptToCompositorMsg::Exited);
let _ = script_thread.content_process_shutdown_chan.send(());
}, reporter_name, script_chan, CommonScriptMsg::CollectReports);
// This must always be the very last operation performed before the thread completes
failsafe.neuter();
}, Some(pipeline_id), panic_chan);
+
+ (sender, receiver)
}
}
@@ -531,7 +519,7 @@ impl ScriptThread {
port: Receiver<MainThreadScriptMsg>,
chan: Sender<MainThreadScriptMsg>)
-> ScriptThread {
- let runtime = unsafe { new_rt_and_cx() };
+ let runtime = unsafe { new_rt_and_cx(ptr::null_mut()) };
unsafe {
JS_SetWrapObjectCallbacks(runtime.rt(),
@@ -581,8 +569,6 @@ impl ScriptThread {
control_chan: state.control_chan,
control_port: control_port,
constellation_chan: state.constellation_chan,
- layout_to_constellation_chan: state.layout_to_constellation_chan,
- compositor: state.compositor,
time_profiler_chan: state.time_profiler_chan,
mem_profiler_chan: state.mem_profiler_chan,
panic_chan: state.panic_chan,
@@ -1099,13 +1085,13 @@ impl ScriptThread {
paint_chan,
panic_chan,
pipeline_port,
+ layout_to_constellation_chan,
layout_shutdown_chan,
content_process_shutdown_chan,
} = new_layout_info;
- let layout_pair = ScriptThread::create_layout_channel();
- let layout_chan = LayoutChan(*ScriptThread::clone_layout_channel(
- &layout_pair).downcast::<Sender<layout_interface::Msg>>().unwrap());
+ let layout_pair = channel();
+ let layout_chan = layout_pair.0.clone();
let layout_creation_info = NewLayoutThreadInfo {
id: new_pipeline_id,
@@ -1113,7 +1099,7 @@ impl ScriptThread {
is_parent: false,
layout_pair: layout_pair,
pipeline_port: pipeline_port,
- constellation_chan: self.layout_to_constellation_chan.clone(),
+ constellation_chan: layout_to_constellation_chan,
panic_chan: panic_chan,
paint_chan: paint_chan,
script_chan: self.control_chan.clone(),
@@ -1130,7 +1116,6 @@ impl ScriptThread {
// Tell layout to actually spawn the thread.
parent_window.layout_chan()
- .0
.send(layout_interface::Msg::CreateLayoutThread(layout_creation_info))
.unwrap();
@@ -1307,8 +1292,8 @@ impl ScriptThread {
// TODO(tkuehn): currently there is only one window,
// so this can afford to be naive and just shut down the
- // compositor. In the future it'll need to be smarter.
- self.compositor.send(ScriptToCompositorMsg::Exit).unwrap();
+ // constellation. In the future it'll need to be smarter.
+ self.constellation_chan.send(ConstellationMsg::Exit).unwrap();
}
/// We have received notification that the response associated with a load has completed.
@@ -1355,7 +1340,7 @@ impl ScriptThread {
// Tell the layout thread to begin shutting down, and wait until it
// processed this message.
let (response_chan, response_port) = channel();
- let LayoutChan(chan) = load.layout_chan;
+ let chan = &load.layout_chan;
if chan.send(layout_interface::Msg::PrepareToExit(response_chan)).is_ok() {
debug!("shutting down layout for page {:?}", id);
response_port.recv().unwrap();
@@ -1414,8 +1399,9 @@ impl ScriptThread {
let final_url = metadata.final_url.clone();
{
// send the final url to the layout thread.
- let LayoutChan(ref chan) = incomplete.layout_chan;
- chan.send(layout_interface::Msg::SetFinalUrl(final_url.clone())).unwrap();
+ incomplete.layout_chan
+ .send(layout_interface::Msg::SetFinalUrl(final_url.clone()))
+ .unwrap();
// update the pipeline url
self.constellation_chan
@@ -1465,7 +1451,6 @@ impl ScriptThread {
FileReadingTaskSource(file_sender.clone()),
self.image_cache_channel.clone(),
self.custom_message_chan.clone(),
- self.compositor.clone(),
self.image_cache_thread.clone(),
self.resource_threads.clone(),
self.bluetooth_thread.clone(),
@@ -1688,8 +1673,11 @@ impl ScriptThread {
let point = Point2D::new(rect.origin.x.to_nearest_px() as f32,
rect.origin.y.to_nearest_px() as f32);
- self.compositor.send(ScriptToCompositorMsg::ScrollFragmentPoint(
- pipeline_id, LayerId::null(), point, false)).unwrap();
+ let message = ConstellationMsg::ScrollFragmentPoint(pipeline_id,
+ LayerId::null(),
+ point,
+ false);
+ self.constellation_chan.send(message).unwrap();
}
/// Reflows non-incrementally, rebuilding the entire layout tree in the process.
@@ -1774,16 +1762,14 @@ impl ScriptThread {
let handled = self.handle_touch_event(pipeline_id, event_type, identifier, point);
match event_type {
TouchEventType::Down => {
- if handled {
+ let result = if handled {
// TODO: Wait to see if preventDefault is called on the first touchmove event.
- self.compositor
- .send(ScriptToCompositorMsg::TouchEventProcessed(
- EventResult::DefaultAllowed)).unwrap();
+ EventResult::DefaultAllowed
} else {
- self.compositor
- .send(ScriptToCompositorMsg::TouchEventProcessed(
- EventResult::DefaultPrevented)).unwrap();
- }
+ EventResult::DefaultPrevented
+ };
+ let message = ConstellationMsg::TouchEventProcessed(result);
+ self.constellation_chan.send(message).unwrap();
}
_ => {
// TODO: Calling preventDefault on a touchup event should prevent clicks.
@@ -1800,7 +1786,7 @@ impl ScriptThread {
KeyEvent(key, state, modifiers) => {
let context = get_browsing_context(&self.root_browsing_context(), pipeline_id);
let document = context.active_document();
- document.dispatch_key_event(key, state, modifiers, &self.compositor);
+ document.dispatch_key_event(key, state, modifiers, &self.constellation_chan);
}
}
}
@@ -1971,29 +1957,27 @@ impl ScriptThread {
fn handle_css_error_reporting(&self, pipeline_id: PipelineId, filename: String,
line: usize, column: usize, msg: String) {
+ let sender = match self.devtools_chan {
+ Some(ref sender) => sender,
+ None => return,
+ };
+
let parent_context = self.root_browsing_context();
let context = match parent_context.find(pipeline_id) {
Some(context) => context,
None => return,
};
- let document = context.active_document();
- let css_error = CSSError {
- filename: filename,
- line: line,
- column: column,
- msg: msg
- };
-
- document.report_css_error(css_error.clone());
let window = context.active_window();
-
if window.live_devtools_updates() {
- if let Some(ref chan) = self.devtools_chan {
- chan.send(ScriptToDevtoolsControlMsg::ReportCSSError(
- pipeline_id,
- css_error)).unwrap();
- }
+ let css_error = CSSError {
+ filename: filename,
+ line: line,
+ column: column,
+ msg: msg
+ };
+ let message = ScriptToDevtoolsControlMsg::ReportCSSError(pipeline_id, css_error);
+ sender.send(message).unwrap();
}
}
}
@@ -2015,7 +1999,7 @@ fn shut_down_layout(context_tree: &BrowsingContext) {
// processed this message.
let (response_chan, response_port) = channel();
let window = context.active_window();
- let LayoutChan(chan) = window.layout_chan().clone();
+ let chan = window.layout_chan().clone();
if chan.send(layout_interface::Msg::PrepareToExit(response_chan)).is_ok() {
channels.push(chan);
response_port.recv().unwrap();