diff --git a/components/script_traits/lib.rs b/components/script_traits/lib.rs index 5d1b555df987..ec08b205c314 100644 --- a/components/script_traits/lib.rs +++ b/components/script_traits/lib.rs @@ -45,6 +45,7 @@ use gfx_traits::Epoch; use heapsize::HeapSizeOf; use hyper::header::Headers; use hyper::method::Method; +use ipc_channel::{Error as IpcError}; use ipc_channel::ipc::{IpcReceiver, IpcSender}; use libc::c_void; use msg::constellation_msg::{BrowsingContextId, TopLevelBrowsingContextId, FrameType, Key, KeyModifiers, KeyState}; @@ -500,7 +501,7 @@ pub struct InitialScriptState { /// A port on which messages sent by the constellation to script can be received. pub control_port: IpcReceiver, /// A channel on which messages can be sent to the constellation from script. - pub constellation_chan: IpcSender, + pub script_to_constellation_chan: ScriptToConstellationChan, /// A sender for the layout thread to communicate to the constellation. pub layout_to_constellation_chan: IpcSender, /// A channel to schedule timer events. @@ -780,7 +781,7 @@ pub struct WorkerGlobalScopeInit { /// From devtools sender pub from_devtools_sender: Option>, /// Messages to send to constellation - pub constellation_chan: IpcSender, + pub script_to_constellation_chan: ScriptToConstellationChan, /// Message to send to the scheduler pub scheduler_chan: IpcSender, /// The worker id @@ -843,3 +844,19 @@ pub struct DrawAPaintImageResult { /// Drawing the image might have requested loading some image URLs. pub missing_image_urls: Vec, } + +/// A Script to Constellation channel. +#[derive(Deserialize, Serialize, Clone)] +pub struct ScriptToConstellationChan { + /// Sender for communicating with constellation thread. + pub sender: IpcSender<(PipelineId, ScriptMsg)>, + /// Used to identify the origin of the message. + pub pipeline_id: PipelineId, +} + +impl ScriptToConstellationChan { + /// Send ScriptMsg and attach the pipeline_id to the message. + pub fn send(&self, msg: ScriptMsg) -> Result<(), IpcError> { + self.sender.send((self.pipeline_id, msg)) + } +}