compositing: Make the constellation messages serializable.

This commit is contained in:
Patrick Walton 2015-07-10 11:16:27 -07:00
parent a0cf597946
commit b6485a9eaf
32 changed files with 316 additions and 229 deletions

View file

@ -21,14 +21,21 @@ git = "https://github.com/servo/rust-layers"
[dependencies.png]
git = "https://github.com/servo/rust-png"
features = [ "serde-serialization" ]
[dependencies.hyper]
version = "0.6"
features = [ "serde-serialization" ]
[dependencies.url]
version = "0.2.36"
features = [ "serde_serialization" ]
[dependencies.ipc-channel]
git = "https://github.com/pcwalton/ipc-channel"
[dependencies]
url = "0.2.35"
bitflags = "*"
hyper = "0.6"
rustc-serialize = "0.3.4"
euclid = "0.1"
serde = "*"

View file

@ -6,13 +6,15 @@
//! reduce coupling between these two components.
use compositor_msg::Epoch;
use euclid::rect::Rect;
use euclid::size::TypedSize2D;
use euclid::scale_factor::ScaleFactor;
use hyper::header::Headers;
use hyper::method::Method;
use ipc_channel::ipc::IpcSender;
use layers::geometry::DevicePixel;
use png;
use png::Image;
use util::cursor::Cursor;
use util::geometry::{PagePx, ViewportPx};
use std::collections::HashMap;
@ -31,20 +33,20 @@ impl ConstellationChan {
}
}
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
#[derive(PartialEq, Eq, Copy, Clone, Debug, Deserialize, Serialize)]
pub enum IFrameSandboxState {
IFrameSandboxed,
IFrameUnsandboxed
}
// We pass this info to various tasks, so it lives in a separate, cloneable struct.
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Deserialize, Serialize)]
pub struct Failure {
pub pipeline_id: PipelineId,
pub parent_info: Option<(PipelineId, SubpageId)>,
}
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Deserialize, Serialize)]
pub struct WindowSizeData {
/// The size of the initial layout viewport, before parsing an
/// http://www.w3.org/TR/css-device-adapt/#initial-viewport
@ -209,6 +211,7 @@ pub enum FocusType {
}
/// Messages from the compositor and script to the constellation.
#[derive(Deserialize, Serialize)]
pub enum Msg {
Exit,
Failure(Failure),
@ -234,14 +237,14 @@ pub enum Msg {
TickAnimation(PipelineId),
/// Request that the constellation send the current pipeline id for the provided frame
/// id, or for the root frame if this is None, over a provided channel
GetPipeline(Option<FrameId>, Sender<Option<PipelineId>>),
GetPipeline(Option<FrameId>, IpcSender<Option<PipelineId>>),
/// Request that the constellation send the FrameId corresponding to the document
/// with the provided parent pipeline id and subpage id
GetFrame(PipelineId, SubpageId, Sender<Option<FrameId>>),
GetFrame(PipelineId, SubpageId, IpcSender<Option<FrameId>>),
/// Notifies the constellation that this frame has received focus.
Focus(PipelineId),
/// Requests that the constellation retrieve the current contents of the clipboard
GetClipboardContents(Sender<String>),
GetClipboardContents(IpcSender<String>),
/// Dispatch a webdriver command
WebDriverCommand(WebDriverCommandMsg),
/// Notifies the constellation that the viewport has been constrained in some manner
@ -256,7 +259,7 @@ pub enum Msg {
HeadParsed,
}
#[derive(Clone, Eq, PartialEq)]
#[derive(Clone, Eq, PartialEq, Deserialize, Serialize)]
pub enum AnimationState {
AnimationsPresent,
AnimationCallbacksPresent,
@ -265,6 +268,7 @@ pub enum AnimationState {
}
// https://developer.mozilla.org/en-US/docs/Web/API/Using_the_Browser_API#Events
#[derive(Deserialize, Serialize)]
pub enum MozBrowserEvent {
/// Sent when the scroll position within a browser <iframe> changes.
AsyncScroll,
@ -329,16 +333,17 @@ impl MozBrowserEvent {
}
}
#[derive(Deserialize, Serialize)]
pub enum WebDriverCommandMsg {
LoadUrl(PipelineId, LoadData, Sender<LoadStatus>),
LoadUrl(PipelineId, LoadData, IpcSender<LoadStatus>),
ScriptCommand(PipelineId, WebDriverScriptCommand),
TakeScreenshot(PipelineId, Sender<Option<png::Image>>)
TakeScreenshot(PipelineId, IpcSender<Option<Image>>)
}
/// Similar to net::resource_task::LoadData
/// can be passed to LoadUrl to load a page with GET/POST
/// parameters or headers
#[derive(Clone)]
#[derive(Clone, Deserialize, Serialize)]
pub struct LoadData {
pub url: Url,
pub method: Method,
@ -357,16 +362,16 @@ impl LoadData {
}
}
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug)]
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug, Deserialize, Serialize)]
pub enum NavigationDirection {
Forward,
Back,
}
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug)]
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug, Deserialize, Serialize)]
pub struct FrameId(pub u32);
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug)]
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug, Deserialize, Serialize)]
pub struct WorkerId(pub u32);
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug, Deserialize, Serialize)]

View file

@ -2,23 +2,25 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use rustc_serialize::json::{Json, ToJson};
use constellation_msg::{PipelineId, SubpageId};
use std::sync::mpsc::Sender;
use ipc_channel::ipc::IpcSender;
use rustc_serialize::json::{Json, ToJson};
#[derive(Deserialize, Serialize)]
pub enum WebDriverScriptCommand {
ExecuteScript(String, Sender<WebDriverJSResult>),
ExecuteAsyncScript(String, Sender<WebDriverJSResult>),
FindElementCSS(String, Sender<Result<Option<String>, ()>>),
FindElementsCSS(String, Sender<Result<Vec<String>, ()>>),
GetActiveElement(Sender<Option<String>>),
GetElementTagName(String, Sender<Result<String, ()>>),
GetElementText(String, Sender<Result<String, ()>>),
GetFrameId(WebDriverFrameId, Sender<Result<Option<(PipelineId, SubpageId)>, ()>>),
GetTitle(Sender<String>)
ExecuteScript(String, IpcSender<WebDriverJSResult>),
ExecuteAsyncScript(String, IpcSender<WebDriverJSResult>),
FindElementCSS(String, IpcSender<Result<Option<String>, ()>>),
FindElementsCSS(String, IpcSender<Result<Vec<String>, ()>>),
GetActiveElement(IpcSender<Option<String>>),
GetElementTagName(String, IpcSender<Result<String, ()>>),
GetElementText(String, IpcSender<Result<String, ()>>),
GetFrameId(WebDriverFrameId, IpcSender<Result<Option<(PipelineId, SubpageId)>, ()>>),
GetTitle(IpcSender<String>)
}
#[derive(Deserialize, Serialize)]
pub enum WebDriverJSValue {
Undefined,
Null,
@ -28,6 +30,7 @@ pub enum WebDriverJSValue {
// TODO: Object and WebElement
}
#[derive(Deserialize, Serialize)]
pub enum WebDriverJSError {
Timeout,
UnknownType
@ -35,6 +38,7 @@ pub enum WebDriverJSError {
pub type WebDriverJSResult = Result<WebDriverJSValue, WebDriverJSError>;
#[derive(Deserialize, Serialize)]
pub enum WebDriverFrameId {
Short(u16),
Element(String),
@ -53,6 +57,7 @@ impl ToJson for WebDriverJSValue {
}
}
#[derive(Deserialize, Serialize)]
pub enum LoadStatus {
LoadComplete,
LoadTimeout