diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index 93581d9f8841..b09ce15560a7 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -732,6 +732,7 @@ impl Constellation layout_to_constellation_chan: self.layout_sender.clone(), scheduler_chan: self.scheduler_chan.clone(), compositor_proxy: self.compositor_proxy.clone(), + embedder_proxy: self.embedder_proxy.clone(), devtools_chan: self.devtools_chan.clone(), bluetooth_thread: self.bluetooth_thread.clone(), swmanager_thread: self.swmanager_sender.clone(), diff --git a/components/constellation/pipeline.rs b/components/constellation/pipeline.rs index 548ef249cdc6..3b4ca2dbcfc9 100644 --- a/components/constellation/pipeline.rs +++ b/components/constellation/pipeline.rs @@ -5,7 +5,7 @@ use bluetooth_traits::BluetoothRequest; use canvas_traits::webgl::WebGLPipeline; use compositing::CompositionPipeline; -use compositing::CompositorProxy; +use compositing::compositor_thread::{CompositorProxy, EmbedderProxy}; use compositing::compositor_thread::Msg as CompositorMsg; use devtools_traits::{DevtoolsControlMsg, ScriptToDevtoolsControlMsg}; use euclid::{TypedSize2D, TypedScale}; @@ -127,6 +127,9 @@ pub struct InitialPipelineState { /// A channel to schedule timer events. pub scheduler_chan: IpcSender, + + /// A channel to the embedder. + pub embedder_proxy: EmbedderProxy, /// A channel to the compositor. pub compositor_proxy: CompositorProxy, @@ -257,6 +260,7 @@ impl Pipeline { browsing_context_id: state.browsing_context_id, top_level_browsing_context_id: state.top_level_browsing_context_id, parent_info: state.parent_info, + embedder_proxy: state.embedder_proxy, script_to_constellation_chan: state.script_to_constellation_chan.clone(), scheduler_chan: state.scheduler_chan, devtools_chan: script_to_devtools_chan, @@ -447,6 +451,7 @@ pub struct UnprivilegedPipelineContent { top_level_browsing_context_id: TopLevelBrowsingContextId, browsing_context_id: BrowsingContextId, parent_info: Option, + embedder_proxy: EmbedderProxy, script_to_constellation_chan: ScriptToConstellationChan, layout_to_constellation_chan: IpcSender, scheduler_chan: IpcSender, @@ -493,6 +498,7 @@ impl UnprivilegedPipelineContent { parent_info: self.parent_info, control_chan: self.script_chan.clone(), control_port: self.script_port, + embedder_proxy: self.embedder_proxy, script_to_constellation_chan: self.script_to_constellation_chan.clone(), layout_to_constellation_chan: self.layout_to_constellation_chan.clone(), scheduler_chan: self.scheduler_chan, diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index 29c06ce7a173..1e430c150954 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -41,7 +41,8 @@ use net_traits::{CoreResourceThread, ResourceThreads, IpcSend}; use profile_traits::{mem, time}; use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort}; use script_thread::{MainThreadScriptChan, ScriptThread}; -use script_traits::{MsDuration, ScriptToConstellationChan, TimerEvent}; +use script_traits::{MsDuration, TimerEvent}; +use script_traits::{ScriptToConstellationChan, ScriptToEmbedderChan}; use script_traits::{TimerEventId, TimerSchedulerMsg, TimerSource}; use servo_url::{MutableOrigin, ServoUrl}; use std::cell::Cell; @@ -97,7 +98,11 @@ pub struct GlobalScope { /// For sending messages to the time profiler. #[ignore_malloc_size_of = "channels are hard"] time_profiler_chan: time::ProfilerChan, - + + /// A handle for communicating messages to the embedder. + #[ignore_malloc_size_of = "channels are hard"] + script_to_embedder_chan: ScriptToEmbedderChan, + /// A handle for communicating messages to the constellation thread. #[ignore_malloc_size_of = "channels are hard"] script_to_constellation_chan: ScriptToConstellationChan, @@ -137,6 +142,7 @@ impl GlobalScope { devtools_chan: Option>, mem_profiler_chan: mem::ProfilerChan, time_profiler_chan: time::ProfilerChan, + script_to_embedder_chan: ScriptToEmbedderChan, script_to_constellation_chan: ScriptToConstellationChan, scheduler_chan: IpcSender, resource_threads: ResourceThreads, @@ -154,6 +160,7 @@ impl GlobalScope { devtools_chan, mem_profiler_chan, time_profiler_chan, + script_to_embedder_chan, script_to_constellation_chan, scheduler_chan: scheduler_chan.clone(), in_error_reporting_mode: Default::default(), @@ -269,7 +276,12 @@ impl GlobalScope { pub fn time_profiler_chan(&self) -> &time::ProfilerChan { &self.time_profiler_chan } - + + /// Get a sender to the constellation thread. + pub fn script_to_embedder_chan(&self) -> &ScriptToEmbedderChan { + &self.script_to_embedder_chan + } + /// Get a sender to the constellation thread. pub fn script_to_constellation_chan(&self) -> &ScriptToConstellationChan { &self.script_to_constellation_chan diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 3a672291e8d1..292a54406109 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -76,7 +76,8 @@ use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, ScriptThreadEventC use script_thread::{ImageCacheMsg, MainThreadScriptChan, MainThreadScriptMsg}; use script_thread::{ScriptThread, SendableMainThreadScriptChan}; use script_traits::{ConstellationControlMsg, DocumentState, LoadData}; -use script_traits::{ScriptToConstellationChan, ScriptMsg, ScrollState, TimerEvent, TimerEventId}; +use script_traits::{ScriptToConstellationChan, ScriptToEmbedderChan}; +use script_traits::{ScriptMsg, ScrollState, TimerEvent, TimerEventId}; use script_traits::{TimerSchedulerMsg, UntrustedNodeAddress, WindowSizeData, WindowSizeType}; use script_traits::webdriver_msg::{WebDriverJSError, WebDriverJSResult}; use selectors::attr::CaseSensitivity; @@ -1762,6 +1763,7 @@ impl Window { mem_profiler_chan: MemProfilerChan, time_profiler_chan: TimeProfilerChan, devtools_chan: Option>, + embedder_chan: ScriptToEmbedderChan, constellation_chan: ScriptToConstellationChan, control_chan: IpcSender, scheduler_chan: IpcSender, @@ -1793,6 +1795,7 @@ impl Window { devtools_chan, mem_profiler_chan, time_profiler_chan, + embedder_chan, constellation_chan, scheduler_chan, resource_threads, diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 4e89ba4ceff4..bdad47b290eb 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -21,6 +21,7 @@ extern crate itertools; use bluetooth_traits::BluetoothRequest; use canvas_traits::webgl::WebGLPipeline; +use compositing::compositor_thread::{EmbedderMsg, EmbedderProxy}; use devtools; use devtools_traits::{DevtoolScriptControlMsg, DevtoolsPageInfo}; use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId}; @@ -93,7 +94,8 @@ use script_traits::{DiscardBrowsingContext, DocumentActivity, EventResult}; use script_traits::{InitialScriptState, JsEvalResult, LayoutMsg, LoadData}; use script_traits::{MouseButton, MouseEventType, NewLayoutInfo}; use script_traits::{ProgressiveWebMetricType, Painter, ScriptMsg, ScriptThreadFactory}; -use script_traits::{ScriptToConstellationChan, TimerEvent, TimerSchedulerMsg}; +use script_traits::{ScriptToConstellationChan, ScriptToEmbedderChan}; +use script_traits::{TimerEvent, TimerSchedulerMsg}; use script_traits::{TimerSource, TouchEventType, TouchId, UntrustedNodeAddress}; use script_traits::{UpdatePipelineIdReason, WindowSizeData, WindowSizeType}; use script_traits::CompositorEvent::{KeyEvent, MouseButtonEvent, MouseMoveEvent, ResizeEvent, TouchEvent}; @@ -848,6 +850,7 @@ impl ScriptThread { control_chan: state.control_chan, control_port: control_port, + embedder_proxy: state.embedder_proxy, script_sender: state.script_to_constellation_chan.sender.clone(), time_profiler_chan: state.time_profiler_chan.clone(), mem_profiler_chan: state.mem_profiler_chan, @@ -2099,6 +2102,11 @@ impl ScriptThread { sender: self.script_sender.clone(), pipeline_id: incomplete.pipeline_id, }; + + let script_to_embedder_chan = ScriptToEmbedderChan { + sender: self.embedder_proxy.clone(), + top_level_browsing_context_id: incomplete.top_level_browsing_context_id, + }; // Create the window and document objects. let window = Window::new( @@ -2117,6 +2125,7 @@ impl ScriptThread { self.mem_profiler_chan.clone(), self.time_profiler_chan.clone(), self.devtools_chan.clone(), + script_to_embedder_chan, script_to_constellation_chan, self.control_chan.clone(), self.scheduler_chan.clone(), diff --git a/components/script_traits/lib.rs b/components/script_traits/lib.rs index 272cfe3cedbe..d56b99ff8797 100644 --- a/components/script_traits/lib.rs +++ b/components/script_traits/lib.rs @@ -11,6 +11,7 @@ extern crate bluetooth_traits; extern crate canvas_traits; +extern crate compositing; extern crate cookie as cookie_rs; extern crate devtools_traits; extern crate euclid; @@ -40,6 +41,7 @@ pub mod webdriver_msg; use bluetooth_traits::BluetoothRequest; use canvas_traits::webgl::WebGLPipeline; +use compositing::compositor_thread::{EmbedderMsg, EmbedderProxy}; use devtools_traits::{DevtoolScriptControlMsg, ScriptToDevtoolsControlMsg, WorkerId}; use euclid::{Length, Point2D, Vector2D, Rect, TypedSize2D, TypedScale}; use gfx_traits::Epoch; @@ -521,6 +523,8 @@ pub struct InitialScriptState { pub control_chan: IpcSender, /// A port on which messages sent by the constellation to script can be received. pub control_port: IpcReceiver, + /// A channel to the embedder. + pub embedder_proxy: EmbedderProxy, /// A channel on which messages can be sent to the constellation from script. pub script_to_constellation_chan: ScriptToConstellationChan, /// A sender for the layout thread to communicate to the constellation. @@ -807,3 +811,19 @@ impl ScriptToConstellationChan { self.sender.send((self.pipeline_id, msg)) } } + +/// A Script to Embedder channel. +#[derive(Clone, Deserialize, Serialize)] +pub struct ScriptToEmbedderChan { + /// Sender for communicating with constellation thread. + pub proxy: EmbedderProxy, + /// The top level ancestor browsing context. + pub top_level_browsing_context_id: TopLevelBrowsingContextId, +} + +impl ScriptToEmbedderChan { + /// Send ScriptMsg and attach the pipeline_id to the message. + pub fn send(&self, msg: EmbedderMsg) { + self.proxy.send((self.top_level_browsing_context_id, msg)) + } +}