diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs index 4e433477a39..43eafcc2d2e 100644 --- a/components/script/dom/bindings/global.rs +++ b/components/script/dom/bindings/global.rs @@ -30,7 +30,7 @@ use profile_traits::time; use script_runtime::{CommonScriptMsg, EnqueuedPromiseCallback, ScriptChan}; use script_runtime::{ScriptPort, maybe_take_panic_result}; use script_thread::{MainThreadScriptChan, RunnableWrapper, ScriptThread}; -use script_traits::{MsDuration, ScriptMsg as ConstellationMsg, TimerEventRequest}; +use script_traits::{MsDuration, TimerEventRequest}; use std::ffi::CString; use std::panic; use task_source::file_reading::FileReadingTaskSource; @@ -89,14 +89,6 @@ impl<'a> GlobalRef<'a> { } } - /// Get a `IpcSender` to send messages to the constellation when available. - pub fn constellation_chan(&self) -> &IpcSender { - match *self { - GlobalRef::Window(window) => window.constellation_chan(), - GlobalRef::Worker(worker) => worker.constellation_chan(), - } - } - /// Get the scheduler channel to request timer events. pub fn scheduler_chan(&self) -> &IpcSender { match *self { diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs index e4815e5f472..3872eb31272 100644 --- a/components/script/dom/canvasrenderingcontext2d.rs +++ b/components/script/dom/canvasrenderingcontext2d.rs @@ -122,7 +122,7 @@ impl CanvasRenderingContext2D { size: Size2D) -> CanvasRenderingContext2D { let (sender, receiver) = ipc::channel().unwrap(); - let constellation_chan = global.constellation_chan(); + let constellation_chan = global.as_global_scope().constellation_chan(); constellation_chan.send(ConstellationMsg::CreateCanvasPaintThread(size, sender)).unwrap(); let ipc_renderer = receiver.recv().unwrap(); CanvasRenderingContext2D { diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 7857e46ecfe..ec109e82240 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -45,6 +45,7 @@ use dom::eventdispatcher::EventStatus; use dom::eventtarget::EventTarget; use dom::focusevent::FocusEvent; use dom::forcetouchevent::ForceTouchEvent; +use dom::globalscope::GlobalScope; use dom::hashchangeevent::HashChangeEvent; use dom::htmlanchorelement::HTMLAnchorElement; use dom::htmlappletelement::HTMLAppletElement; @@ -651,7 +652,7 @@ impl Document { // https://html.spec.whatwg.org/multipage/#focus-chain if focus_type == FocusType::Element { let event = ConstellationMsg::Focus(self.window.pipeline_id()); - self.window.constellation_chan().send(event).unwrap(); + self.window.upcast::().constellation_chan().send(event).unwrap(); } } } @@ -669,7 +670,8 @@ impl Document { /// Sends this document's title to the compositor. pub fn send_title_to_compositor(&self) { let window = self.window(); - window.constellation_chan() + window.upcast::() + .constellation_chan() .send(ConstellationMsg::SetTitle(window.pipeline_id(), Some(String::from(self.Title())))) .unwrap(); @@ -723,7 +725,7 @@ impl Document { let event = ConstellationMsg::ForwardMouseButtonEvent(pipeline_id, mouse_event_type, button, child_point); - self.window.constellation_chan().send(event).unwrap(); + self.window.upcast::().constellation_chan().send(event).unwrap(); } return; } @@ -961,7 +963,7 @@ impl Document { let child_point = client_point - child_origin; let event = ConstellationMsg::ForwardMouseMoveEvent(pipeline_id, child_point); - self.window.constellation_chan().send(event).unwrap(); + self.window.upcast::().constellation_chan().send(event).unwrap(); } return; } @@ -1359,7 +1361,7 @@ impl Document { let event = ConstellationMsg::MozBrowserEvent(parent_pipeline_id, Some(self.window.pipeline_id()), event); - self.window.constellation_chan().send(event).unwrap(); + self.window.upcast::().constellation_chan().send(event).unwrap(); } } } @@ -1382,7 +1384,7 @@ impl Document { let event = ConstellationMsg::ChangeRunningAnimationsState( self.window.pipeline_id(), AnimationState::AnimationCallbacksPresent); - self.window.constellation_chan().send(event).unwrap(); + self.window.upcast::().constellation_chan().send(event).unwrap(); } ident @@ -1420,7 +1422,7 @@ impl Document { &mut animation_frame_list); let event = ConstellationMsg::ChangeRunningAnimationsState(self.window.pipeline_id(), AnimationState::NoAnimationCallbacksPresent); - self.window.constellation_chan().send(event).unwrap(); + self.window.upcast::().constellation_chan().send(event).unwrap(); } self.running_animation_callbacks.set(false); @@ -1578,7 +1580,7 @@ impl Document { pub fn notify_constellation_load(&self) { let pipeline_id = self.window.pipeline_id(); let load_event = ConstellationMsg::LoadComplete(pipeline_id); - self.window.constellation_chan().send(load_event).unwrap(); + self.window.upcast::().constellation_chan().send(load_event).unwrap(); } pub fn set_current_parser(&self, script: Option) { diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index ac8cef37c43..9f2443b85bc 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -12,6 +12,7 @@ use dom::eventtarget::EventTarget; use ipc_channel::ipc::IpcSender; use js::jsapi::{JS_GetContext, JS_GetObjectRuntime, JSContext}; use profile_traits::{mem, time}; +use script_traits::ScriptMsg as ConstellationMsg; use std::cell::Cell; use std::collections::HashMap; use std::collections::hash_map::Entry; @@ -41,13 +42,18 @@ pub struct GlobalScope { /// For sending messages to the time profiler. #[ignore_heap_size_of = "channels are hard"] time_profiler_chan: time::ProfilerChan, + + /// A handle for communicating messages to the constellation thread. + #[ignore_heap_size_of = "channels are hard"] + constellation_chan: IpcSender, } impl GlobalScope { pub fn new_inherited( devtools_chan: Option>, mem_profiler_chan: mem::ProfilerChan, - time_profiler_chan: time::ProfilerChan) + time_profiler_chan: time::ProfilerChan, + constellation_chan: IpcSender) -> Self { GlobalScope { eventtarget: EventTarget::new_inherited(), @@ -58,6 +64,7 @@ impl GlobalScope { devtools_chan: devtools_chan, mem_profiler_chan: mem_profiler_chan, time_profiler_chan: time_profiler_chan, + constellation_chan: constellation_chan, } } @@ -128,6 +135,11 @@ impl GlobalScope { pub fn time_profiler_chan(&self) -> &time::ProfilerChan { &self.time_profiler_chan } + + /// Get a sender to the constellation thread. + pub fn constellation_chan(&self) -> &IpcSender { + &self.constellation_chan + } } fn timestamp_in_ms(time: Timespec) -> u64 { diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index 9fe5789524c..23dc3951e42 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -6,8 +6,10 @@ use dom::bindings::codegen::Bindings::HistoryBinding; use dom::bindings::codegen::Bindings::HistoryBinding::HistoryMethods; use dom::bindings::codegen::Bindings::LocationBinding::LocationMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, Root}; use dom::bindings::reflector::{Reflector, reflect_dom_object}; +use dom::globalscope::GlobalScope; use dom::window::Window; use ipc_channel::ipc; use msg::constellation_msg::TraversalDirection; @@ -39,7 +41,7 @@ impl History { fn traverse_history(&self, direction: TraversalDirection) { let pipeline = self.window.pipeline_id(); let msg = ConstellationMsg::TraverseHistory(Some(pipeline), direction); - let _ = self.window.constellation_chan().send(msg); + let _ = self.window.upcast::().constellation_chan().send(msg); } } @@ -49,7 +51,7 @@ impl HistoryMethods for History { let pipeline = self.window.pipeline_id(); let (sender, recv) = ipc::channel().expect("Failed to create channel to send jsh length."); let msg = ConstellationMsg::JointSessionHistoryLength(pipeline, sender); - let _ = self.window.constellation_chan().send(msg); + let _ = self.window.upcast::().constellation_chan().send(msg); recv.recv().unwrap() } diff --git a/components/script/dom/htmlbodyelement.rs b/components/script/dom/htmlbodyelement.rs index 993d50a2a76..1cab444e871 100644 --- a/components/script/dom/htmlbodyelement.rs +++ b/components/script/dom/htmlbodyelement.rs @@ -13,6 +13,7 @@ use dom::bindings::str::DOMString; use dom::document::Document; use dom::element::{AttributeMutation, Element, RawLayoutElementHelpers}; use dom::eventtarget::EventTarget; +use dom::globalscope::GlobalScope; use dom::htmlelement::HTMLElement; use dom::node::{Node, document_from_node, window_from_node}; use dom::virtualmethods::VirtualMethods; @@ -137,7 +138,7 @@ impl VirtualMethods for HTMLBodyElement { let document = window.Document(); document.set_reflow_timeout(time::precise_time_ns() + INITIAL_REFLOW_DELAY); let event = ConstellationMsg::HeadParsed; - window.constellation_chan().send(event).unwrap(); + window.upcast::().constellation_chan().send(event).unwrap(); } fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index 2b7781dae1e..355c825429d 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -29,6 +29,7 @@ use dom::domtokenlist::DOMTokenList; use dom::element::{AttributeMutation, Element, RawLayoutElementHelpers}; use dom::event::Event; use dom::eventtarget::EventTarget; +use dom::globalscope::GlobalScope; use dom::htmlelement::HTMLElement; use dom::node::{Node, NodeDamage, UnbindContext, document_from_node, window_from_node}; use dom::urlhelper::UrlHelper; @@ -135,7 +136,8 @@ impl HTMLIFrameElement { frame_type: frame_type, replace: replace, }; - window.constellation_chan() + window.upcast::() + .constellation_chan() .send(ConstellationMsg::ScriptLoadedURLInIFrame(load_info)) .unwrap(); @@ -216,7 +218,7 @@ impl HTMLIFrameElement { let window = window_from_node(self); let window = window.r(); let msg = ConstellationMsg::SetVisible(pipeline_id, visible); - window.constellation_chan().send(msg).unwrap(); + window.upcast::().constellation_chan().send(msg).unwrap(); } } @@ -407,7 +409,7 @@ pub fn Navigate(iframe: &HTMLIFrameElement, direction: TraversalDirection) -> Er if iframe.upcast::().is_in_doc() { let window = window_from_node(iframe); let msg = ConstellationMsg::TraverseHistory(iframe.pipeline_id(), direction); - window.constellation_chan().send(msg).unwrap(); + window.upcast::().constellation_chan().send(msg).unwrap(); } Ok(()) @@ -641,7 +643,7 @@ impl VirtualMethods for HTMLIFrameElement { (Some(sender), Some(receiver)) }; let msg = ConstellationMsg::RemoveIFrame(pipeline_id, sender); - window.constellation_chan().send(msg).unwrap(); + window.upcast::().constellation_chan().send(msg).unwrap(); if let Some(receiver) = receiver { receiver.recv().unwrap() } diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index d9cda98b284..4097b885d91 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -21,6 +21,7 @@ use dom::event::{Event, EventBubbles, EventCancelable}; use dom::eventtarget::EventTarget; use dom::file::File; use dom::filelist::FileList; +use dom::globalscope::GlobalScope; use dom::htmlelement::HTMLElement; use dom::htmlfieldsetelement::HTMLFieldSetElement; use dom::htmlformelement::{FormControl, FormDatum, FormDatumValue, FormSubmitter, HTMLFormElement}; @@ -128,7 +129,7 @@ static DEFAULT_MIN_LENGTH: i32 = -1; impl HTMLInputElement { fn new_inherited(local_name: Atom, prefix: Option, document: &Document) -> HTMLInputElement { - let chan = document.window().constellation_chan().clone(); + let chan = document.window().upcast::().constellation_chan().clone(); HTMLInputElement { htmlelement: HTMLElement::new_inherited_with_state(IN_ENABLED_STATE | IN_READ_WRITE_STATE, diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs index b02aa0ad6a7..f3797469ea4 100644 --- a/components/script/dom/htmllinkelement.rs +++ b/components/script/dom/htmllinkelement.rs @@ -18,6 +18,7 @@ use dom::document::Document; use dom::domtokenlist::DOMTokenList; use dom::element::{AttributeMutation, Element, ElementCreator}; use dom::eventtarget::EventTarget; +use dom::globalscope::GlobalScope; use dom::htmlelement::HTMLElement; use dom::node::{Node, document_from_node, window_from_node}; use dom::virtualmethods::VirtualMethods; @@ -280,7 +281,7 @@ impl HTMLLinkElement { match document.base_url().join(href) { Ok(url) => { let event = ConstellationMsg::NewFavicon(url.clone()); - document.window().constellation_chan().send(event).unwrap(); + document.window().upcast::().constellation_chan().send(event).unwrap(); let mozbrowser_event = match *sizes { Some(ref sizes) => MozBrowserEvent::IconChange(rel.to_owned(), url.to_string(), sizes.to_owned()), diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index 3a4418d713d..bcdb8268c61 100644 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -15,6 +15,7 @@ use dom::document::Document; use dom::element::{AttributeMutation, Element}; use dom::element::RawLayoutElementHelpers; use dom::event::{Event, EventBubbles, EventCancelable}; +use dom::globalscope::GlobalScope; use dom::htmlelement::HTMLElement; use dom::htmlfieldsetelement::HTMLFieldSetElement; use dom::htmlformelement::{FormControl, HTMLFormElement}; @@ -99,7 +100,7 @@ impl HTMLTextAreaElement { fn new_inherited(local_name: Atom, prefix: Option, document: &Document) -> HTMLTextAreaElement { - let chan = document.window().constellation_chan().clone(); + let chan = document.window().upcast::().constellation_chan().clone(); HTMLTextAreaElement { htmlelement: HTMLElement::new_inherited_with_state(IN_ENABLED_STATE | IN_READ_WRITE_STATE, diff --git a/components/script/dom/serviceworker.rs b/components/script/dom/serviceworker.rs index cce149b5368..6f2dce2f8e0 100644 --- a/components/script/dom/serviceworker.rs +++ b/components/script/dom/serviceworker.rs @@ -89,8 +89,11 @@ impl ServiceWorkerMethods for ServiceWorker { // Step 7 let data = try!(StructuredCloneData::write(cx, message)); let msg_vec = DOMMessage(data.move_to_arraybuffer()); - let _ = self.global().r().constellation_chan().send(ScriptMsg::ForwardDOMMessage(msg_vec, - self.scope_url.clone())); + let _ = + self.global().r() + .as_global_scope() + .constellation_chan() + .send(ScriptMsg::ForwardDOMMessage(msg_vec, self.scope_url.clone())); Ok(()) } diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 4b6e8b2cefd..1b29bd47621 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -133,7 +133,7 @@ impl WebGLRenderingContext { attrs: GLContextAttributes) -> Result { let (sender, receiver) = ipc::channel().unwrap(); - let constellation_chan = global.constellation_chan(); + let constellation_chan = global.as_global_scope().constellation_chan(); constellation_chan.send(ConstellationMsg::CreateWebGLPaintThread(size, attrs, sender)) .unwrap(); let result = receiver.recv().unwrap(); diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 57aeada88a5..7bc64f58b1c 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -215,10 +215,6 @@ pub struct Window { #[ignore_heap_size_of = "channels are hard"] bluetooth_thread: IpcSender, - /// A handle for communicating messages to the constellation thread. - #[ignore_heap_size_of = "channels are hard"] - constellation_chan: IpcSender, - /// Pending scroll to fragment event, if any fragment_name: DOMRefCell>, @@ -436,7 +432,10 @@ impl WindowMethods for Window { } let (sender, receiver) = ipc::channel().unwrap(); - self.constellation_chan().send(ConstellationMsg::Alert(self.pipeline_id(), s.to_string(), sender)).unwrap(); + self.upcast::() + .constellation_chan() + .send(ConstellationMsg::Alert(self.pipeline_id(), s.to_string(), sender)) + .unwrap(); let should_display_alert_dialog = receiver.recv().unwrap(); if should_display_alert_dialog { @@ -797,7 +796,10 @@ impl WindowMethods for Window { // Step 1 //TODO determine if this operation is allowed let size = Size2D::new(x.to_u32().unwrap_or(1), y.to_u32().unwrap_or(1)); - self.constellation_chan.send(ConstellationMsg::ResizeTo(size)).unwrap() + self.upcast::() + .constellation_chan() + .send(ConstellationMsg::ResizeTo(size)) + .unwrap() } // https://drafts.csswg.org/cssom-view/#dom-window-resizeby @@ -812,7 +814,10 @@ impl WindowMethods for Window { // Step 1 //TODO determine if this operation is allowed let point = Point2D::new(x, y); - self.constellation_chan.send(ConstellationMsg::MoveTo(point)).unwrap() + self.upcast::() + .constellation_chan() + .send(ConstellationMsg::MoveTo(point)) + .unwrap() } // https://drafts.csswg.org/cssom-view/#dom-window-moveby @@ -974,7 +979,7 @@ impl Window { self.update_viewport_for_scroll(x, y); let message = ConstellationMsg::ScrollFragmentPoint(self.pipeline_id(), layer_id, point, smooth); - self.constellation_chan.send(message).unwrap(); + self.upcast::().constellation_chan().send(message).unwrap(); } pub fn update_viewport_for_scroll(&self, x: f32, y: f32) { @@ -985,7 +990,10 @@ impl Window { pub fn client_window(&self) -> (Size2D, Point2D) { let (send, recv) = ipc::channel::<(Size2D, Point2D)>().unwrap(); - self.constellation_chan.send(ConstellationMsg::GetClientWindow(send)).unwrap(); + self.upcast::() + .constellation_chan() + .send(ConstellationMsg::GetClientWindow(send)) + .unwrap(); recv.recv().unwrap_or((Size2D::zero(), Point2D::zero())) } @@ -1149,7 +1157,7 @@ impl Window { if ready_state == DocumentReadyState::Complete && !reftest_wait { let event = ConstellationMsg::SetDocumentState(self.id, DocumentState::Idle); - self.constellation_chan().send(event).unwrap(); + self.upcast::().constellation_chan().send(event).unwrap(); } } @@ -1261,7 +1269,10 @@ impl Window { let pipeline_id = self.id; let (send, recv) = ipc::channel::>().unwrap(); - self.constellation_chan.send(ConstellationMsg::GetScrollOffset(pipeline_id, layer_id, send)).unwrap(); + self.upcast::() + .constellation_chan() + .send(ConstellationMsg::GetScrollOffset(pipeline_id, layer_id, send)) + .unwrap(); recv.recv().unwrap_or(Point2D::zero()) } @@ -1376,10 +1387,6 @@ impl Window { &self.layout_chan } - pub fn constellation_chan(&self) -> &IpcSender { - &self.constellation_chan - } - pub fn scheduler_chan(&self) -> &IpcSender { &self.scheduler_chan } @@ -1586,7 +1593,8 @@ impl Window { let current_time = time::get_time(); let win = box Window { globalscope: - GlobalScope::new_inherited(devtools_chan, mem_profiler_chan, time_profiler_chan), + GlobalScope::new_inherited( + devtools_chan, mem_profiler_chan, time_profiler_chan, constellation_chan), script_chan: script_chan, dom_manipulation_task_source: dom_task_source, user_interaction_task_source: user_task_source, @@ -1613,7 +1621,6 @@ impl Window { js_runtime: DOMRefCell::new(Some(runtime.clone())), resource_threads: resource_threads, bluetooth_thread: bluetooth_thread, - constellation_chan: constellation_chan, page_clip_rect: Cell::new(max_rect()), fragment_name: DOMRefCell::new(None), resize_event: Cell::new(None), diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs index f9757a976ef..81c43c2c5fe 100644 --- a/components/script/dom/workerglobalscope.rs +++ b/components/script/dom/workerglobalscope.rs @@ -39,7 +39,6 @@ use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, maybe_take_panic_r use script_runtime::{ScriptThreadEventCategory, PromiseJobQueue, EnqueuedPromiseCallback}; use script_thread::{Runnable, RunnableWrapper}; use script_traits::{MsDuration, TimerEvent, TimerEventId, TimerEventRequest, TimerSource}; -use script_traits::ScriptMsg as ConstellationMsg; use script_traits::WorkerGlobalScopeInit; use std::cell::Cell; use std::default::Default; @@ -59,13 +58,14 @@ pub fn prepare_workerscope_init(global: GlobalRef, let to_devtools_sender = global_scope.devtools_chan().cloned(); let mem_profiler_chan = global_scope.mem_profiler_chan().clone(); let time_profiler_chan = global_scope.time_profiler_chan().clone(); + let constellation_chan = global_scope.constellation_chan().clone(); let init = WorkerGlobalScopeInit { resource_threads: global.resource_threads(), mem_profiler_chan: mem_profiler_chan, to_devtools_sender: to_devtools_sender, time_profiler_chan: time_profiler_chan, from_devtools_sender: devtools_sender, - constellation_chan: global.constellation_chan().clone(), + constellation_chan: constellation_chan, scheduler_chan: global.scheduler_chan().clone(), worker_id: worker_id, pipeline_id: global.pipeline_id(), @@ -102,9 +102,6 @@ pub struct WorkerGlobalScope { /// `IpcSender` doesn't exist from_devtools_receiver: Receiver, - #[ignore_heap_size_of = "Defined in std"] - constellation_chan: IpcSender, - #[ignore_heap_size_of = "Defined in std"] scheduler_chan: IpcSender, @@ -125,7 +122,10 @@ impl WorkerGlobalScope { WorkerGlobalScope { globalscope: GlobalScope::new_inherited( - init.to_devtools_sender, init.mem_profiler_chan, init.time_profiler_chan), + init.to_devtools_sender, + init.mem_profiler_chan, + init.time_profiler_chan, + init.constellation_chan), worker_id: init.worker_id, pipeline_id: init.pipeline_id, worker_url: worker_url, @@ -137,7 +137,6 @@ impl WorkerGlobalScope { timers: OneshotTimers::new(timer_event_chan, init.scheduler_chan.clone()), from_devtools_sender: init.from_devtools_sender, from_devtools_receiver: from_devtools_receiver, - constellation_chan: init.constellation_chan, scheduler_chan: init.scheduler_chan, promise_job_queue: PromiseJobQueue::new(), in_error_reporting_mode: Default::default(), @@ -152,10 +151,6 @@ impl WorkerGlobalScope { &self.from_devtools_receiver } - pub fn constellation_chan(&self) -> &IpcSender { - &self.constellation_chan - } - pub fn scheduler_chan(&self) -> &IpcSender { &self.scheduler_chan }