Skip to content

Commit

Permalink
introduce ScriptToConstellationChan
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrouget committed Aug 12, 2017
1 parent bb3ac8f commit 817de15
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions components/script_traits/lib.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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<ConstellationControlMsg>,
/// A channel on which messages can be sent to the constellation from script.
pub constellation_chan: IpcSender<ScriptMsg>,
pub script_to_constellation_chan: ScriptToConstellationChan,
/// A sender for the layout thread to communicate to the constellation.
pub layout_to_constellation_chan: IpcSender<LayoutMsg>,
/// A channel to schedule timer events.
Expand Down Expand Up @@ -780,7 +781,7 @@ pub struct WorkerGlobalScopeInit {
/// From devtools sender
pub from_devtools_sender: Option<IpcSender<DevtoolScriptControlMsg>>,
/// Messages to send to constellation
pub constellation_chan: IpcSender<ScriptMsg>,
pub script_to_constellation_chan: ScriptToConstellationChan,
/// Message to send to the scheduler
pub scheduler_chan: IpcSender<TimerSchedulerMsg>,
/// The worker id
Expand Down Expand Up @@ -843,3 +844,19 @@ pub struct DrawAPaintImageResult {
/// Drawing the image might have requested loading some image URLs.
pub missing_image_urls: Vec<ServoUrl>,
}

/// 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))
}
}

0 comments on commit 817de15

Please sign in to comment.