introduce ScriptToConstellationChan

This commit is contained in:
Paul Rouget 2017-06-20 09:17:15 +02:00
parent bb3ac8f266
commit 817de15735

View file

@ -45,6 +45,7 @@ use gfx_traits::Epoch;
use heapsize::HeapSizeOf; use heapsize::HeapSizeOf;
use hyper::header::Headers; use hyper::header::Headers;
use hyper::method::Method; use hyper::method::Method;
use ipc_channel::{Error as IpcError};
use ipc_channel::ipc::{IpcReceiver, IpcSender}; use ipc_channel::ipc::{IpcReceiver, IpcSender};
use libc::c_void; use libc::c_void;
use msg::constellation_msg::{BrowsingContextId, TopLevelBrowsingContextId, FrameType, Key, KeyModifiers, KeyState}; 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. /// A port on which messages sent by the constellation to script can be received.
pub control_port: IpcReceiver<ConstellationControlMsg>, pub control_port: IpcReceiver<ConstellationControlMsg>,
/// A channel on which messages can be sent to the constellation from script. /// 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. /// A sender for the layout thread to communicate to the constellation.
pub layout_to_constellation_chan: IpcSender<LayoutMsg>, pub layout_to_constellation_chan: IpcSender<LayoutMsg>,
/// A channel to schedule timer events. /// A channel to schedule timer events.
@ -780,7 +781,7 @@ pub struct WorkerGlobalScopeInit {
/// From devtools sender /// From devtools sender
pub from_devtools_sender: Option<IpcSender<DevtoolScriptControlMsg>>, pub from_devtools_sender: Option<IpcSender<DevtoolScriptControlMsg>>,
/// Messages to send to constellation /// Messages to send to constellation
pub constellation_chan: IpcSender<ScriptMsg>, pub script_to_constellation_chan: ScriptToConstellationChan,
/// Message to send to the scheduler /// Message to send to the scheduler
pub scheduler_chan: IpcSender<TimerSchedulerMsg>, pub scheduler_chan: IpcSender<TimerSchedulerMsg>,
/// The worker id /// The worker id
@ -843,3 +844,19 @@ pub struct DrawAPaintImageResult {
/// Drawing the image might have requested loading some image URLs. /// Drawing the image might have requested loading some image URLs.
pub missing_image_urls: Vec<ServoUrl>, 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))
}
}