diff options
author | Patrick Walton <pcwalton@mimiga.net> | 2015-07-10 11:16:27 -0700 |
---|---|---|
committer | Patrick Walton <pcwalton@mimiga.net> | 2015-07-18 12:43:08 -0700 |
commit | b6485a9eafacc29661aa9d0e3cdcd477eefdb66f (patch) | |
tree | f35644c31699e771b6b2f646831264e6ae6c2087 /components/script | |
parent | a0cf597946446c427c54da363fe989ff68db4270 (diff) | |
download | servo-b6485a9eafacc29661aa9d0e3cdcd477eefdb66f.tar.gz servo-b6485a9eafacc29661aa9d0e3cdcd477eefdb66f.zip |
compositing: Make the constellation messages serializable.
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/Cargo.toml | 10 | ||||
-rw-r--r-- | components/script/clipboard_provider.rs | 3 | ||||
-rw-r--r-- | components/script/dom/bindings/trace.rs | 9 | ||||
-rw-r--r-- | components/script/dom/window.rs | 7 | ||||
-rw-r--r-- | components/script/lib.rs | 1 | ||||
-rw-r--r-- | components/script/webdriver_handlers.rs | 39 |
6 files changed, 50 insertions, 19 deletions
diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index 0731d06b1be..a06eabe8875 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -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 = "*" diff --git a/components/script/clipboard_provider.rs b/components/script/clipboard_provider.rs index af67919125b..facdf4aca14 100644 --- a/components/script/clipboard_provider.rs +++ b/components/script/clipboard_provider.rs @@ -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() } diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index 5ed5ed0bb52..f7f8c527d9a 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -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) { diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 845f7ea7521..9eca84edac4 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -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; } diff --git a/components/script/lib.rs b/components/script/lib.rs index 80390b3a429..c57c0de7998 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -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; diff --git a/components/script/webdriver_handlers.rs b/components/script/webdriver_handlers.rs index c724b1b7348..591e38eb52b 100644 --- a/components/script/webdriver_handlers.rs +++ b/components/script/webdriver_handlers.rs @@ -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(); |