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

@ -52,8 +52,8 @@ git = "https://github.com/servo/rust-selectors"
git = "https://github.com/servo/rust-mozjs"
[dependencies.url]
version = "0.2.33"
features = ["query_encoding"]
version = "0.2.36"
features = ["query_encoding", "serde_serialization"]
[dependencies.offscreen_gl_context]
git = "https://github.com/ecoal95/rust-offscreen-rendering-context"
@ -61,6 +61,10 @@ git = "https://github.com/ecoal95/rust-offscreen-rendering-context"
[dependencies.ipc-channel]
git = "https://github.com/pcwalton/ipc-channel"
[dependencies.hyper]
version = "0.6"
features = [ "serde-serialization" ]
[dependencies]
log = "*"
encoding = "0.2"
@ -69,7 +73,6 @@ time = "0.1.12"
bitflags = "*"
rustc-serialize = "*"
libc = "*"
hyper = "0.6"
cssparser = "0.3.1"
unicase = "0.1"
num = "0.1.24"
@ -82,3 +85,4 @@ string_cache_plugin = "0.1"
euclid = "0.1"
tendril = "0.1.1"
rand = "0.3"
serde = "*"

View file

@ -5,6 +5,7 @@
use msg::constellation_msg::ConstellationChan;
use msg::constellation_msg::Msg as ConstellationMsg;
use ipc_channel::ipc;
use std::borrow::ToOwned;
use std::sync::mpsc::channel;
@ -17,7 +18,7 @@ pub trait ClipboardProvider {
impl ClipboardProvider for ConstellationChan {
fn clipboard_contents(&mut self) -> String {
let (tx, rx) = channel();
let (tx, rx) = ipc::channel().unwrap();
self.0.send(ConstellationMsg::GetClipboardContents(tx)).unwrap();
rx.recv().unwrap()
}

View file

@ -45,6 +45,7 @@ use euclid::size::Size2D;
use html5ever::tree_builder::QuirksMode;
use hyper::header::Headers;
use hyper::method::Method;
use ipc_channel::ipc::IpcSender;
use js::jsapi::{JSObject, JSTracer, JSGCTraceKind, JS_CallValueTracer, JS_CallObjectTracer, GCTraceKindToAscii, Heap};
use js::jsapi::JS_CallUnbarrieredObjectTracer;
use js::jsval::JSVal;
@ -61,6 +62,7 @@ use msg::compositor_msg::ScriptListener;
use msg::constellation_msg::ConstellationChan;
use net_traits::image::base::Image;
use profile_traits::mem::ProfilerChan;
use serde::Serialize;
use util::str::{LengthOrPercentageOrAuto};
use std::cell::{Cell, UnsafeCell, RefCell};
use std::collections::{HashMap, HashSet};
@ -344,6 +346,13 @@ impl JSTraceable for Box<LayoutRPC+'static> {
}
}
impl<T> JSTraceable for IpcSender<T> where T: Serialize {
#[inline]
fn trace(&self, _: *mut JSTracer) {
// Do nothing
}
}
impl JSTraceable for () {
#[inline]
fn trace(&self, _trc: *mut JSTracer) {

View file

@ -51,6 +51,7 @@ use util::opts;
use util::str::{DOMString,HTML_SPACE_CHARACTERS};
use euclid::{Point2D, Rect, Size2D};
use ipc_channel::ipc::IpcSender;
use js::jsapi::{Evaluate2, MutableHandleValue};
use js::jsapi::{JSContext, HandleValue};
use js::jsapi::{JS_GC, JS_GetRuntime, JSAutoCompartment, JSAutoRequest};
@ -185,7 +186,7 @@ pub struct Window {
pending_reflow_count: Cell<u32>,
/// A channel for communicating results of async scripts back to the webdriver server
webdriver_script_chan: RefCell<Option<Sender<WebDriverJSResult>>>,
webdriver_script_chan: RefCell<Option<IpcSender<WebDriverJSResult>>>,
/// The current state of the window object
current_state: Cell<WindowState>,
@ -562,7 +563,7 @@ pub trait WindowHelpers {
fn emit_timeline_marker(self, marker: TimelineMarker);
fn set_devtools_timeline_marker(self, marker: TimelineMarkerType, reply: Sender<TimelineMarker>);
fn drop_devtools_timeline_markers(self);
fn set_webdriver_script_chan(self, chan: Option<Sender<WebDriverJSResult>>);
fn set_webdriver_script_chan(self, chan: Option<IpcSender<WebDriverJSResult>>);
fn is_alive(self) -> bool;
fn parent(self) -> Option<Root<Window>>;
}
@ -945,7 +946,7 @@ impl<'a> WindowHelpers for &'a Window {
*self.devtools_marker_sender.borrow_mut() = None;
}
fn set_webdriver_script_chan(self, chan: Option<Sender<WebDriverJSResult>>) {
fn set_webdriver_script_chan(self, chan: Option<IpcSender<WebDriverJSResult>>) {
*self.webdriver_script_chan.borrow_mut() = chan;
}

View file

@ -53,6 +53,7 @@ extern crate net_traits;
extern crate num;
extern crate rustc_serialize;
extern crate rustc_unicode;
extern crate serde;
extern crate time;
extern crate canvas;
extern crate canvas_traits;

View file

@ -22,8 +22,8 @@ use script_task::get_page;
use js::jsapi::{RootedValue, HandleValue};
use js::jsval::UndefinedValue;
use ipc_channel::ipc::IpcSender;
use std::rc::Rc;
use std::sync::mpsc::Sender;
fn find_node_by_unique_id(page: &Rc<Page>, pipeline: PipelineId, node_id: String) -> Option<Root<Node>> {
let page = get_page(&*page, pipeline);
@ -58,7 +58,10 @@ pub fn jsval_to_webdriver(cx: *mut JSContext, val: HandleValue) -> WebDriverJSRe
}
}
pub fn handle_execute_script(page: &Rc<Page>, pipeline: PipelineId, eval: String, reply: Sender<WebDriverJSResult>) {
pub fn handle_execute_script(page: &Rc<Page>,
pipeline: PipelineId,
eval: String,
reply: IpcSender<WebDriverJSResult>) {
let page = get_page(&*page, pipeline);
let window = page.window();
let cx = window.r().get_cx();
@ -68,8 +71,10 @@ pub fn handle_execute_script(page: &Rc<Page>, pipeline: PipelineId, eval: String
reply.send(jsval_to_webdriver(cx, rval.handle())).unwrap();
}
pub fn handle_execute_async_script(page: &Rc<Page>, pipeline: PipelineId, eval: String,
reply: Sender<WebDriverJSResult>) {
pub fn handle_execute_async_script(page: &Rc<Page>,
pipeline: PipelineId,
eval: String,
reply: IpcSender<WebDriverJSResult>) {
let page = get_page(&*page, pipeline);
let window = page.window();
let cx = window.r().get_cx();
@ -81,7 +86,7 @@ pub fn handle_execute_async_script(page: &Rc<Page>, pipeline: PipelineId, eval:
pub fn handle_get_frame_id(page: &Rc<Page>,
pipeline: PipelineId,
webdriver_frame_id: WebDriverFrameId,
reply: Sender<Result<Option<(PipelineId, SubpageId)>, ()>>) {
reply: IpcSender<Result<Option<(PipelineId, SubpageId)>, ()>>) {
let window = match webdriver_frame_id {
WebDriverFrameId::Short(_) => {
// This isn't supported yet
@ -109,7 +114,7 @@ pub fn handle_get_frame_id(page: &Rc<Page>,
}
pub fn handle_find_element_css(page: &Rc<Page>, _pipeline: PipelineId, selector: String,
reply: Sender<Result<Option<String>, ()>>) {
reply: IpcSender<Result<Option<String>, ()>>) {
reply.send(match page.document().r().QuerySelector(selector.clone()) {
Ok(node) => {
let result = node.map(|x| NodeCast::from_ref(x.r()).get_unique_id());
@ -119,8 +124,10 @@ pub fn handle_find_element_css(page: &Rc<Page>, _pipeline: PipelineId, selector:
}).unwrap();
}
pub fn handle_find_elements_css(page: &Rc<Page>, _pipeline: PipelineId, selector: String,
reply: Sender<Result<Vec<String>, ()>>) {
pub fn handle_find_elements_css(page: &Rc<Page>,
_pipeline: PipelineId,
selector: String,
reply: IpcSender<Result<Vec<String>, ()>>) {
reply.send(match page.document().r().QuerySelectorAll(selector.clone()) {
Ok(ref nodes) => {
let mut result = Vec::with_capacity(nodes.r().Length() as usize);
@ -137,16 +144,21 @@ pub fn handle_find_elements_css(page: &Rc<Page>, _pipeline: PipelineId, selector
}).unwrap();
}
pub fn handle_get_active_element(page: &Rc<Page>, _pipeline: PipelineId, reply: Sender<Option<String>>) {
pub fn handle_get_active_element(page: &Rc<Page>,
_pipeline: PipelineId,
reply: IpcSender<Option<String>>) {
reply.send(page.document().r().GetActiveElement().map(
|elem| NodeCast::from_ref(elem.r()).get_unique_id())).unwrap();
}
pub fn handle_get_title(page: &Rc<Page>, _pipeline: PipelineId, reply: Sender<String>) {
pub fn handle_get_title(page: &Rc<Page>, _pipeline: PipelineId, reply: IpcSender<String>) {
reply.send(page.document().r().Title()).unwrap();
}
pub fn handle_get_text(page: &Rc<Page>, pipeline: PipelineId, node_id: String, reply: Sender<Result<String, ()>>) {
pub fn handle_get_text(page: &Rc<Page>,
pipeline: PipelineId,
node_id: String,
reply: IpcSender<Result<String, ()>>) {
reply.send(match find_node_by_unique_id(&*page, pipeline, node_id) {
Some(ref node) => {
Ok(node.r().GetTextContent().unwrap_or("".to_owned()))
@ -155,7 +167,10 @@ pub fn handle_get_text(page: &Rc<Page>, pipeline: PipelineId, node_id: String, r
}).unwrap();
}
pub fn handle_get_name(page: &Rc<Page>, pipeline: PipelineId, node_id: String, reply: Sender<Result<String, ()>>) {
pub fn handle_get_name(page: &Rc<Page>,
pipeline: PipelineId,
node_id: String,
reply: IpcSender<Result<String, ()>>) {
reply.send(match find_node_by_unique_id(&*page, pipeline, node_id) {
Some(node) => {
let element = ElementCast::to_ref(node.r()).unwrap();