servo: Merge #10285 - Use serde in devtools (from nox:devtools-serde); r=Ms2ger

Source-Repo: https://github.com/servo/servo
Source-Revision: 3c00aff5468e8ac1bc88b9fc01aa6091f9552d95
This commit is contained in:
Anthony Ramine 2016-03-31 18:07:13 +05:01
Родитель 63c293056b
Коммит 12fc784f37
23 изменённых файлов: 245 добавлений и 233 удалений

Просмотреть файл

@ -26,7 +26,6 @@ git = "https://github.com/servo/ipc-channel"
[dependencies]
hyper = { version = "0.8", features = [ "serde-serialization" ] }
log = "0.3.5"
rustc-serialize = "0.3"
serde = "0.7"
serde_json = "0.7"
serde_macros = "0.7"

Просмотреть файл

@ -5,10 +5,10 @@
/// General actor system infrastructure.
use devtools_traits::PreciseTime;
use rustc_serialize::json;
use serde_json::Value;
use std::any::Any;
use std::cell::{Cell, RefCell};
use std::collections::HashMap;
use std::collections::{BTreeMap, HashMap};
use std::mem::replace;
use std::net::TcpStream;
use std::sync::{Arc, Mutex};
@ -26,7 +26,7 @@ pub trait Actor: Any + ActorAsAny {
fn handle_message(&self,
registry: &ActorRegistry,
msg_type: &str,
msg: &json::Object,
msg: &BTreeMap<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()>;
fn name(&self) -> String;
}
@ -150,7 +150,7 @@ impl ActorRegistry {
/// Attempt to process a message as directed by its `to` property. If the actor is not
/// found or does not indicate that it knew how to process the message, ignore the failure.
pub fn handle_message(&mut self,
msg: &json::Object,
msg: &BTreeMap<String, Value>,
stream: &mut TcpStream)
-> Result<(), ()> {
let to = msg.get("to").unwrap().as_string().unwrap();

Просмотреть файл

@ -16,30 +16,30 @@ use devtools_traits::{CONSOLE_API, CachedConsoleMessageTypes, DevtoolScriptContr
use ipc_channel::ipc::{self, IpcSender};
use msg::constellation_msg::PipelineId;
use protocol::JsonPacketStream;
use rustc_serialize::json::{self, Json, ToJson};
use serde_json::{self, Value};
use std::cell::RefCell;
use std::collections::BTreeMap;
use std::net::TcpStream;
trait EncodableConsoleMessage {
fn encode(&self) -> json::EncodeResult<String>;
fn encode(&self) -> serde_json::Result<String>;
}
impl EncodableConsoleMessage for CachedConsoleMessage {
fn encode(&self) -> json::EncodeResult<String> {
fn encode(&self) -> serde_json::Result<String> {
match *self {
CachedConsoleMessage::PageError(ref a) => json::encode(a),
CachedConsoleMessage::ConsoleAPI(ref a) => json::encode(a),
CachedConsoleMessage::PageError(ref a) => serde_json::to_string(a),
CachedConsoleMessage::ConsoleAPI(ref a) => serde_json::to_string(a),
}
}
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct StartedListenersTraits {
customNetworkRequest: bool,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct StartedListenersReply {
from: String,
nativeConsoleAPI: bool,
@ -47,37 +47,37 @@ struct StartedListenersReply {
traits: StartedListenersTraits,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct GetCachedMessagesReply {
from: String,
messages: Vec<json::Object>,
messages: Vec<BTreeMap<String, Value>>,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct StopListenersReply {
from: String,
stoppedListeners: Vec<String>,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct AutocompleteReply {
from: String,
matches: Vec<String>,
matchProp: String,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct EvaluateJSReply {
from: String,
input: String,
result: Json,
result: Value,
timestamp: u64,
exception: Json,
exception: Value,
exceptionMessage: String,
helperResult: Json,
helperResult: Value,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct SetPreferencesReply {
from: String,
updated: Vec<String>,
@ -98,7 +98,7 @@ impl Actor for ConsoleActor {
fn handle_message(&self,
registry: &ActorRegistry,
msg_type: &str,
msg: &json::Object,
msg: &BTreeMap<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"getCachedMessages" => {
@ -118,7 +118,7 @@ impl Actor for ConsoleActor {
self.pipeline, message_types, chan)).unwrap();
let messages = try!(port.recv().map_err(|_| ())).into_iter().map(|message| {
let json_string = message.encode().unwrap();
let json = Json::from_str(&json_string).unwrap();
let json = serde_json::from_str::<Value>(&json_string).unwrap();
json.as_object().unwrap().to_owned()
}).collect();
@ -183,49 +183,49 @@ impl Actor for ConsoleActor {
let result = match try!(port.recv().map_err(|_| ())) {
VoidValue => {
let mut m = BTreeMap::new();
m.insert("type".to_owned(), "undefined".to_owned().to_json());
Json::Object(m)
m.insert("type".to_owned(), serde_json::to_value("undefined"));
Value::Object(m)
}
NullValue => {
let mut m = BTreeMap::new();
m.insert("type".to_owned(), "null".to_owned().to_json());
Json::Object(m)
m.insert("type".to_owned(), serde_json::to_value("null"));
Value::Object(m)
}
BooleanValue(val) => val.to_json(),
BooleanValue(val) => Value::Bool(val),
NumberValue(val) => {
if val.is_nan() {
let mut m = BTreeMap::new();
m.insert("type".to_owned(), "NaN".to_owned().to_json());
Json::Object(m)
m.insert("type".to_owned(), serde_json::to_value("NaN"));
Value::Object(m)
} else if val.is_infinite() {
let mut m = BTreeMap::new();
if val < 0. {
m.insert("type".to_owned(), "-Infinity".to_owned().to_json());
m.insert("type".to_owned(), serde_json::to_value("-Infinity"));
} else {
m.insert("type".to_owned(), "Infinity".to_owned().to_json());
m.insert("type".to_owned(), serde_json::to_value("Infinity"));
}
Json::Object(m)
Value::Object(m)
} else if val == 0. && val.is_sign_negative() {
let mut m = BTreeMap::new();
m.insert("type".to_owned(), "-0".to_owned().to_json());
Json::Object(m)
m.insert("type".to_owned(), serde_json::to_value("-0"));
Value::Object(m)
} else {
val.to_json()
serde_json::to_value(&val)
}
}
StringValue(s) => s.to_json(),
StringValue(s) => Value::String(s),
ActorValue { class, uuid } => {
//TODO: make initial ActorValue message include these properties?
let mut m = BTreeMap::new();
let actor = ObjectActor::new(registry, uuid);
m.insert("type".to_owned(), "object".to_owned().to_json());
m.insert("class".to_owned(), class.to_json());
m.insert("actor".to_owned(), actor.to_json());
m.insert("extensible".to_owned(), true.to_json());
m.insert("frozen".to_owned(), false.to_json());
m.insert("sealed".to_owned(), false.to_json());
Json::Object(m)
m.insert("type".to_owned(), serde_json::to_value("object"));
m.insert("class".to_owned(), serde_json::to_value(&class));
m.insert("actor".to_owned(), serde_json::to_value(&actor));
m.insert("extensible".to_owned(), Value::Bool(true));
m.insert("frozen".to_owned(), Value::Bool(false));
m.insert("sealed".to_owned(), Value::Bool(false));
Value::Object(m)
}
};
@ -235,9 +235,9 @@ impl Actor for ConsoleActor {
input: input,
result: result,
timestamp: 0,
exception: Json::Object(BTreeMap::new()),
exception: Value::Object(BTreeMap::new()),
exceptionMessage: "".to_owned(),
helperResult: Json::Object(BTreeMap::new()),
helperResult: Value::Object(BTreeMap::new()),
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed

Просмотреть файл

@ -7,7 +7,8 @@ use actors::timeline::HighResolutionStamp;
use devtools_traits::DevtoolScriptControlMsg;
use ipc_channel::ipc::IpcSender;
use msg::constellation_msg::PipelineId;
use rustc_serialize::json;
use serde_json::Value;
use std::collections::BTreeMap;
use std::mem;
use std::net::TcpStream;
use time::precise_time_ns;
@ -30,7 +31,7 @@ impl Actor for FramerateActor {
fn handle_message(&self,
_registry: &ActorRegistry,
_msg_type: &str,
_msg: &json::Object,
_msg: &BTreeMap<String, Value>,
_stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(ActorMessageStatus::Ignored)
}

Просмотреть файл

@ -12,8 +12,7 @@ use devtools_traits::{ComputedNodeLayout, DevtoolScriptControlMsg, NodeInfo};
use ipc_channel::ipc::{self, IpcSender};
use msg::constellation_msg::PipelineId;
use protocol::JsonPacketStream;
use rustc_serialize::json::{self, Json};
use serde_json;
use serde_json::{self, Value};
use std::cell::RefCell;
use std::collections::BTreeMap;
use std::net::TcpStream;
@ -27,13 +26,13 @@ pub struct InspectorActor {
pub pipeline: PipelineId,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct GetHighlighterReply {
highligter: HighlighterMsg, // sic.
from: String,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct HighlighterMsg {
actor: String,
}
@ -48,12 +47,12 @@ pub struct NodeActor {
pipeline: PipelineId,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct ShowBoxModelReply {
from: String,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct HideBoxModelReply {
from: String,
}
@ -66,7 +65,7 @@ impl Actor for HighlighterActor {
fn handle_message(&self,
_registry: &ActorRegistry,
msg_type: &str,
_msg: &json::Object,
_msg: &BTreeMap<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"showBoxModel" => {
@ -90,7 +89,7 @@ impl Actor for HighlighterActor {
}
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct ModifyAttributeReply {
from: String,
}
@ -103,14 +102,14 @@ impl Actor for NodeActor {
fn handle_message(&self,
registry: &ActorRegistry,
msg_type: &str,
msg: &json::Object,
msg: &BTreeMap<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"modifyAttributes" => {
let target = msg.get("to").unwrap().as_string().unwrap();
let mods = msg.get("modifications").unwrap().as_array().unwrap();
let modifications = mods.iter().map(|json_mod| {
json::decode(&json_mod.to_string()).unwrap()
serde_json::from_str(&serde_json::to_string(json_mod).unwrap()).unwrap()
}).collect();
self.script_chan.send(ModifyAttribute(self.pipeline,
@ -129,26 +128,26 @@ impl Actor for NodeActor {
}
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct GetWalkerReply {
from: String,
walker: WalkerMsg,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct WalkerMsg {
actor: String,
root: NodeActorMsg,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct AttrMsg {
namespace: String,
name: String,
value: String,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct NodeActorMsg {
actor: String,
baseURI: String,
@ -245,23 +244,23 @@ struct WalkerActor {
pipeline: PipelineId,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct QuerySelectorReply {
from: String,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct DocumentElementReply {
from: String,
node: NodeActorMsg,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct ClearPseudoclassesReply {
from: String,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct ChildrenReply {
hasFirst: bool,
hasLast: bool,
@ -277,7 +276,7 @@ impl Actor for WalkerActor {
fn handle_message(&self,
registry: &ActorRegistry,
msg_type: &str,
msg: &json::Object,
msg: &BTreeMap<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"querySelector" => {
@ -336,13 +335,13 @@ impl Actor for WalkerActor {
}
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct GetPageStyleReply {
from: String,
pageStyle: PageStyleMsg,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct PageStyleMsg {
actor: String,
}
@ -353,7 +352,7 @@ struct PageStyleActor {
pipeline: PipelineId,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct GetAppliedReply {
entries: Vec<AppliedEntry>,
rules: Vec<AppliedRule>,
@ -361,24 +360,25 @@ struct GetAppliedReply {
from: String,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct GetComputedReply {
computed: Vec<u32>, //XXX all css props
from: String,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct AppliedEntry {
rule: String,
pseudoElement: Json,
pseudoElement: Value,
isSystem: bool,
matchedSelectors: Vec<String>,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct AppliedRule {
actor: String,
__type__: u32,
#[serde(rename = "type")]
type_: String,
href: String,
cssText: String,
line: u32,
@ -386,7 +386,7 @@ struct AppliedRule {
parentStyleSheet: String,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct AppliedSheet {
actor: String,
href: String,
@ -451,7 +451,7 @@ impl Actor for PageStyleActor {
fn handle_message(&self,
registry: &ActorRegistry,
msg_type: &str,
msg: &json::Object,
msg: &BTreeMap<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"getApplied" => {
@ -493,7 +493,7 @@ impl Actor for PageStyleActor {
} = rx.recv().unwrap();
let auto_margins = msg.get("autoMargins")
.and_then(&Json::as_boolean).unwrap_or(false);
.and_then(&Value::as_boolean).unwrap_or(false);
// http://mxr.mozilla.org/mozilla-central/source/toolkit/devtools/server/actors/styles.js
let msg = GetLayoutReply {
@ -528,8 +528,8 @@ impl Actor for PageStyleActor {
width: width,
height: height,
};
let msg = &serde_json::to_string(&msg).unwrap();
let msg = Json::from_str(msg).unwrap();
let msg = serde_json::to_string(&msg).unwrap();
let msg = serde_json::from_str::<Value>(&msg).unwrap();
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
@ -547,7 +547,7 @@ impl Actor for InspectorActor {
fn handle_message(&self,
registry: &ActorRegistry,
msg_type: &str,
_msg: &json::Object,
_msg: &BTreeMap<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"getWalker" => {

Просмотреть файл

@ -3,10 +3,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use actor::{Actor, ActorMessageStatus, ActorRegistry};
use rustc_serialize::json;
use serde_json::Value;
use std::collections::BTreeMap;
use std::net::TcpStream;
#[derive(RustcEncodable)]
#[derive(Serialize)]
pub struct TimelineMemoryReply {
jsObjectSize: u64,
jsStringSize: u64,
@ -31,7 +32,7 @@ impl Actor for MemoryActor {
fn handle_message(&self,
_registry: &ActorRegistry,
_msg_type: &str,
_msg: &json::Object,
_msg: &BTreeMap<String, Value>,
_stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(ActorMessageStatus::Ignored)
}

Просмотреть файл

@ -16,7 +16,8 @@ use hyper::header::{ContentType, Cookie};
use hyper::http::RawStatus;
use hyper::method::Method;
use protocol::JsonPacketStream;
use rustc_serialize::json;
use serde_json::Value;
use std::collections::BTreeMap;
use std::net::TcpStream;
use time;
use time::Tm;
@ -41,7 +42,7 @@ pub struct NetworkEventActor {
response: HttpResponse,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
pub struct EventActor {
pub actor: String,
pub url: String,
@ -51,12 +52,12 @@ pub struct EventActor {
pub private: bool
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
pub struct ResponseCookiesMsg {
pub cookies: u32,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
pub struct ResponseStartMsg {
pub httpVersion: String,
pub remoteAddress: String,
@ -67,7 +68,7 @@ pub struct ResponseStartMsg {
pub discardResponseBody: bool,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
pub struct ResponseContentMsg {
pub mimeType: String,
pub contentSize: u32,
@ -76,19 +77,19 @@ pub struct ResponseContentMsg {
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
pub struct ResponseHeadersMsg {
pub headers: u32,
pub headersSize: u32,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
pub struct RequestCookiesMsg {
pub cookies: u32,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct GetRequestHeadersReply {
from: String,
headers: Vec<String>,
@ -96,7 +97,7 @@ struct GetRequestHeadersReply {
rawHeaders: String
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct GetResponseHeadersReply {
from: String,
headers: Vec<String>,
@ -104,33 +105,33 @@ struct GetResponseHeadersReply {
rawHeaders: String
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct GetResponseContentReply {
from: String,
content: Option<Vec<u8>>,
contentDiscarded: bool,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct GetRequestPostDataReply {
from: String,
postData: Option<Vec<u8>>,
postDataDiscarded: bool
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct GetRequestCookiesReply {
from: String,
cookies: Vec<u8>
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct GetResponseCookiesReply {
from: String,
cookies: Vec<u8>
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct Timings {
blocked: u32,
dns: u32,
@ -140,14 +141,14 @@ struct Timings {
receive: u32,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct GetEventTimingsReply {
from: String,
timings: Timings,
totalTime: u32,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct GetSecurityInfoReply {
from: String,
seuritInfo: String,
@ -162,7 +163,7 @@ impl Actor for NetworkEventActor {
fn handle_message(&self,
_registry: &ActorRegistry,
msg_type: &str,
_msg: &json::Object,
_msg: &BTreeMap<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"getRequestHeaders" => {

Просмотреть файл

@ -3,7 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use actor::{Actor, ActorMessageStatus, ActorRegistry};
use rustc_serialize::json;
use serde_json::Value;
use std::collections::BTreeMap;
use std::net::TcpStream;
pub struct ObjectActor {
@ -18,7 +19,7 @@ impl Actor for ObjectActor {
fn handle_message(&self,
_: &ActorRegistry,
_: &str,
_: &json::Object,
_: &BTreeMap<String, Value>,
_: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(ActorMessageStatus::Ignored)
}

Просмотреть файл

@ -4,14 +4,15 @@
use actor::{Actor, ActorMessageStatus, ActorRegistry};
use protocol::JsonPacketStream;
use rustc_serialize::json;
use serde_json::Value;
use std::collections::BTreeMap;
use std::net::TcpStream;
pub struct PerformanceActor {
name: String,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct PerformanceFeatures {
withMarkers: bool,
withMemory: bool,
@ -20,12 +21,12 @@ struct PerformanceFeatures {
withJITOptimizations: bool,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct PerformanceTraits {
features: PerformanceFeatures,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct ConnectReply {
from: String,
traits: PerformanceTraits,
@ -39,7 +40,7 @@ impl Actor for PerformanceActor {
fn handle_message(&self,
_registry: &ActorRegistry,
msg_type: &str,
_msg: &json::Object,
_msg: &BTreeMap<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"connect" => {

Просмотреть файл

@ -3,7 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use actor::{Actor, ActorMessageStatus, ActorRegistry};
use rustc_serialize::json;
use serde_json::Value;
use std::collections::BTreeMap;
use std::net::TcpStream;
pub struct ProfilerActor {
@ -18,7 +19,7 @@ impl Actor for ProfilerActor {
fn handle_message(&self,
_registry: &ActorRegistry,
_msg_type: &str,
_msg: &json::Object,
_msg: &BTreeMap<String, Value>,
_stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(ActorMessageStatus::Ignored)
}

Просмотреть файл

@ -10,33 +10,34 @@
use actor::{Actor, ActorMessageStatus, ActorRegistry};
use actors::tab::{TabActor, TabActorMsg};
use protocol::JsonPacketStream;
use rustc_serialize::json;
use serde_json::Value;
use std::collections::BTreeMap;
use std::net::TcpStream;
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct ActorTraits {
sources: bool,
highlightable: bool,
customHighlighters: Vec<String>,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct ListAddonsReply {
from: String,
addons: Vec<AddonMsg>,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
enum AddonMsg {}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct ListTabsReply {
from: String,
selected: u32,
tabs: Vec<TabActorMsg>,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
pub struct RootActorMsg {
from: String,
applicationType: String,
@ -55,7 +56,7 @@ impl Actor for RootActor {
fn handle_message(&self,
registry: &ActorRegistry,
msg_type: &str,
_msg: &json::Object,
_msg: &BTreeMap<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"listAddons" => {

Просмотреть файл

@ -11,40 +11,43 @@ use actor::{Actor, ActorMessageStatus, ActorRegistry};
use actors::console::ConsoleActor;
use devtools_traits::DevtoolScriptControlMsg::WantsLiveNotifications;
use protocol::JsonPacketStream;
use rustc_serialize::json;
use serde_json::Value;
use std::collections::BTreeMap;
use std::net::TcpStream;
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct TabTraits;
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct TabAttachedReply {
from: String,
__type__: String,
#[serde(rename = "type")]
type_: String,
threadActor: String,
cacheDisabled: bool,
javascriptEnabled: bool,
traits: TabTraits,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct TabDetachedReply {
from: String,
__type__: String,
#[serde(rename = "type")]
type_: String,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct ReconfigureReply {
from: String
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct ListFramesReply {
from: String,
frames: Vec<FrameMsg>,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct FrameMsg {
id: u32,
url: String,
@ -52,7 +55,7 @@ struct FrameMsg {
parentID: u32,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
pub struct TabActorMsg {
actor: String,
title: String,
@ -85,7 +88,7 @@ impl Actor for TabActor {
fn handle_message(&self,
registry: &ActorRegistry,
msg_type: &str,
_msg: &json::Object,
_msg: &BTreeMap<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"reconfigure" => {
@ -98,7 +101,7 @@ impl Actor for TabActor {
"attach" => {
let msg = TabAttachedReply {
from: self.name(),
__type__: "tabAttached".to_owned(),
type_: "tabAttached".to_owned(),
threadActor: self.thread.clone(),
cacheDisabled: false,
javascriptEnabled: true,
@ -117,7 +120,7 @@ impl Actor for TabActor {
"detach" => {
let msg = TabDetachedReply {
from: self.name(),
__type__: "detached".to_owned(),
type_: "detached".to_owned(),
};
let console_actor = registry.find::<ConsoleActor>(&self.console);
console_actor.streams.borrow_mut().pop();

Просмотреть файл

@ -4,33 +4,37 @@
use actor::{Actor, ActorMessageStatus, ActorRegistry};
use protocol::JsonPacketStream;
use rustc_serialize::json;
use serde_json::Value;
use std::collections::BTreeMap;
use std::net::TcpStream;
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct ThreadAttachedReply {
from: String,
__type__: String,
#[serde(rename = "type")]
type_: String,
actor: String,
poppedFrames: Vec<PoppedFrameMsg>,
why: WhyMsg,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
enum PoppedFrameMsg {}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct WhyMsg {
__type__: String,
#[serde(rename = "type")]
type_: String,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct ThreadResumedReply {
from: String,
__type__: String,
#[serde(rename = "type")]
type_: String,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct ReconfigureReply {
from: String
}
@ -55,16 +59,16 @@ impl Actor for ThreadActor {
fn handle_message(&self,
registry: &ActorRegistry,
msg_type: &str,
_msg: &json::Object,
_msg: &BTreeMap<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"attach" => {
let msg = ThreadAttachedReply {
from: self.name(),
__type__: "paused".to_owned(),
type_: "paused".to_owned(),
actor: registry.new_name("pause"),
poppedFrames: vec![],
why: WhyMsg { __type__: "attached".to_owned() },
why: WhyMsg { type_: "attached".to_owned() },
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
@ -73,7 +77,7 @@ impl Actor for ThreadActor {
"resume" => {
let msg = ThreadResumedReply {
from: self.name(),
__type__: "resumed".to_owned(),
type_: "resumed".to_owned(),
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed

Просмотреть файл

@ -11,8 +11,10 @@ use devtools_traits::{PreciseTime, TimelineMarker, TimelineMarkerType};
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use msg::constellation_msg::PipelineId;
use protocol::JsonPacketStream;
use rustc_serialize::{Encodable, Encoder, json};
use serde::{Serialize, Serializer};
use serde_json::Value;
use std::cell::RefCell;
use std::collections::BTreeMap;
use std::net::TcpStream;
use std::sync::{Arc, Mutex};
use std::thread;
@ -41,25 +43,25 @@ struct Emitter {
memory_actor: Option<String>,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct IsRecordingReply {
from: String,
value: bool
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct StartReply {
from: String,
value: HighResolutionStamp,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct StopReply {
from: String,
value: HighResolutionStamp,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct TimelineMarkerReply {
name: String,
start: HighResolutionStamp,
@ -68,25 +70,28 @@ struct TimelineMarkerReply {
endStack: Option<Vec<()>>,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct MarkersEmitterReply {
__type__: String,
#[serde(rename = "type")]
type_: String,
markers: Vec<TimelineMarkerReply>,
from: String,
endTime: HighResolutionStamp,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct MemoryEmitterReply {
__type__: String,
#[serde(rename = "type")]
type_: String,
from: String,
delta: HighResolutionStamp,
measurement: TimelineMemoryReply,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct FramerateEmitterReply {
__type__: String,
#[serde(rename = "type")]
type_: String,
from: String,
delta: HighResolutionStamp,
timestamps: Vec<HighResolutionStamp>,
@ -110,9 +115,9 @@ impl HighResolutionStamp {
}
}
impl Encodable for HighResolutionStamp {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
self.0.encode(s)
impl Serialize for HighResolutionStamp {
fn serialize<S: Serializer>(&self, s: &mut S) -> Result<(), S::Error> {
self.0.serialize(s)
}
}
@ -172,7 +177,7 @@ impl Actor for TimelineActor {
fn handle_message(&self,
registry: &ActorRegistry,
msg_type: &str,
msg: &json::Object,
msg: &BTreeMap<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"start" => {
@ -290,7 +295,7 @@ impl Emitter {
fn send(&mut self, markers: Vec<TimelineMarkerReply>) -> () {
let end_time = PreciseTime::now();
let reply = MarkersEmitterReply {
__type__: "markers".to_owned(),
type_: "markers".to_owned(),
markers: markers,
from: self.from.clone(),
endTime: HighResolutionStamp::new(self.start_stamp, end_time),
@ -302,7 +307,7 @@ impl Emitter {
let registry = lock.as_mut().unwrap();
let framerate_actor = registry.find_mut::<FramerateActor>(actor_name);
let framerateReply = FramerateEmitterReply {
__type__: "framerate".to_owned(),
type_: "framerate".to_owned(),
from: framerate_actor.name(),
delta: HighResolutionStamp::new(self.start_stamp, end_time),
timestamps: framerate_actor.take_pending_ticks(),
@ -314,7 +319,7 @@ impl Emitter {
let registry = self.registry.lock().unwrap();
let memory_actor = registry.find::<MemoryActor>(actor_name);
let memoryReply = MemoryEmitterReply {
__type__: "memory".to_owned(),
type_: "memory".to_owned(),
from: memory_actor.name(),
delta: HighResolutionStamp::new(self.start_stamp, end_time),
measurement: memory_actor.measure(),

Просмотреть файл

@ -4,7 +4,8 @@
use actor::{Actor, ActorMessageStatus, ActorRegistry};
use devtools_traits::WorkerId;
use rustc_serialize::json;
use serde_json::Value;
use std::collections::BTreeMap;
use std::net::TcpStream;
pub struct WorkerActor {
@ -20,7 +21,7 @@ impl Actor for WorkerActor {
fn handle_message(&self,
_: &ActorRegistry,
_: &str,
_: &json::Object,
_: &BTreeMap<String, Value>,
_: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(ActorMessageStatus::Processed)
}

Просмотреть файл

@ -26,7 +26,6 @@ extern crate ipc_channel;
#[macro_use]
extern crate log;
extern crate msg;
extern crate rustc_serialize;
extern crate serde;
extern crate serde_json;
extern crate time;
@ -80,14 +79,15 @@ mod actors {
}
mod protocol;
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct ConsoleAPICall {
from: String,
__type__: String,
#[serde(rename = "type")]
type_: String,
message: ConsoleMsg,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct ConsoleMsg {
level: String,
timeStamp: u64,
@ -97,65 +97,73 @@ struct ConsoleMsg {
columnNumber: usize,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct NetworkEventMsg {
from: String,
__type__: String,
#[serde(rename = "type")]
type_: String,
eventActor: EventActor,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct ResponseStartUpdateMsg {
from: String,
__type__: String,
#[serde(rename = "type")]
type_: String,
updateType: String,
response: ResponseStartMsg,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct ResponseContentUpdateMsg {
from: String,
__type__: String,
#[serde(rename = "type")]
type_: String,
updateType: String,
responseContent: ResponseContentMsg,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct ResponseCookiesUpdateMsg {
from: String,
__type__: String,
#[serde(rename = "type")]
type_: String,
updateType: String,
responseCookies: ResponseCookiesMsg,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct ResponseHeadersUpdateMsg {
from: String,
__type__: String,
#[serde(rename = "type")]
type_: String,
updateType: String,
responseHeaders: ResponseHeadersMsg,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct RequestCookiesUpdateMsg {
from: String,
__type__: String,
#[serde(rename = "type")]
type_: String,
updateType: String,
requestcookies: RequestCookiesMsg,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct EventTimingsUpdateMsg {
from: String,
__type__: String,
#[serde(rename = "type")]
type_: String,
updateType: String,
totalTime: u32,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct SecurityInfoUpdateMsg {
from: String,
__type__: String,
#[serde(rename = "type")]
type_: String,
updateType: String,
securityState: String,
}
@ -329,7 +337,7 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
let console_actor = actors.find::<ConsoleActor>(&console_actor_name);
let msg = ConsoleAPICall {
from: console_actor.name.clone(),
__type__: "consoleAPICall".to_owned(),
type_: "consoleAPICall".to_owned(),
message: ConsoleMsg {
level: match console_message.logLevel {
LogLevel::Debug => "debug",
@ -397,7 +405,7 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
//Send a networkEvent message to the client
let msg = NetworkEventMsg {
from: console_actor_name,
__type__: "networkEvent".to_owned(),
type_: "networkEvent".to_owned(),
eventActor: actor.event_actor(),
};
for stream in &mut connections {
@ -411,7 +419,7 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
let msg7 = RequestCookiesUpdateMsg {
from: netevent_actor_name.clone(),
__type__: "networkEventUpdate".to_owned(),
type_: "networkEventUpdate".to_owned(),
updateType: "requestCookies".to_owned(),
requestcookies: actor.request_cookies(),
};
@ -422,7 +430,7 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
//Send a networkEventUpdate (responseStart) to the client
let msg = ResponseStartUpdateMsg {
from: netevent_actor_name.clone(),
__type__: "networkEventUpdate".to_owned(),
type_: "networkEventUpdate".to_owned(),
updateType: "responseStart".to_owned(),
response: actor.response_start()
};
@ -432,7 +440,7 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
}
let msg2 = EventTimingsUpdateMsg {
from: netevent_actor_name.clone(),
__type__: "networkEventUpdate".to_owned(),
type_: "networkEventUpdate".to_owned(),
updateType: "eventTimings".to_owned(),
totalTime: 0
};
@ -443,7 +451,7 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
let msg3 = SecurityInfoUpdateMsg {
from: netevent_actor_name.clone(),
__type__: "networkEventUpdate".to_owned(),
type_: "networkEventUpdate".to_owned(),
updateType: "securityInfo".to_owned(),
securityState: "".to_owned(),
};
@ -454,7 +462,7 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
let msg4 = ResponseContentUpdateMsg {
from: netevent_actor_name.clone(),
__type__: "networkEventUpdate".to_owned(),
type_: "networkEventUpdate".to_owned(),
updateType: "responseContent".to_owned(),
responseContent: actor.response_content(),
};
@ -465,7 +473,7 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
let msg5 = ResponseCookiesUpdateMsg {
from: netevent_actor_name.clone(),
__type__: "networkEventUpdate".to_owned(),
type_: "networkEventUpdate".to_owned(),
updateType: "responseCookies".to_owned(),
responseCookies: actor.response_cookies(),
};
@ -476,7 +484,7 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
let msg6 = ResponseHeadersUpdateMsg {
from: netevent_actor_name.clone(),
__type__: "networkEventUpdate".to_owned(),
type_: "networkEventUpdate".to_owned(),
updateType: "responseHeaders".to_owned(),
responseHeaders: actor.response_headers(),
};

Просмотреть файл

@ -6,26 +6,25 @@
//! [JSON packets]
//! (https://wiki.mozilla.org/Remote_Debugging_Protocol_Stream_Transport#JSON_Packets).
use rustc_serialize::json::Json;
use rustc_serialize::json::ParserError::{IoError, SyntaxError};
use rustc_serialize::{Encodable, json};
use serde::Serialize;
use serde_json::{self, Value};
use std::error::Error;
use std::io::{Read, Write};
use std::net::TcpStream;
pub trait JsonPacketStream {
fn write_json_packet<T: Encodable>(&mut self, obj: &T);
fn read_json_packet(&mut self) -> Result<Option<Json>, String>;
fn write_json_packet<T: Serialize>(&mut self, obj: &T);
fn read_json_packet(&mut self) -> Result<Option<Value>, String>;
}
impl JsonPacketStream for TcpStream {
fn write_json_packet<T: Encodable>(&mut self, obj: &T) {
let s = json::encode(obj).unwrap().replace("__type__", "type");
fn write_json_packet<T: Serialize>(&mut self, obj: &T) {
let s = serde_json::to_string(obj).unwrap();
println!("<- {}", s);
write!(self, "{}:{}", s.len(), s).unwrap();
}
fn read_json_packet(&mut self) -> Result<Option<Json>, String> {
fn read_json_packet(&mut self) -> Result<Option<Value>, String> {
// https://wiki.mozilla.org/Remote_Debugging_Protocol_Stream_Transport
// In short, each JSON packet is [ascii length]:[JSON data of given length]
let mut buffer = vec!();
@ -50,11 +49,18 @@ impl JsonPacketStream for TcpStream {
let mut packet = String::new();
self.take(packet_len).read_to_string(&mut packet).unwrap();
println!("{}", packet);
return match Json::from_str(&packet) {
return match serde_json::from_str(&packet) {
Ok(json) => Ok(Some(json)),
Err(err) => match err {
IoError(ioerr) => return Err(ioerr.description().to_owned()),
SyntaxError(_, l, c) => return Err(format!("syntax at {}:{}", l, c)),
serde_json::Error::Io(ioerr) => {
return Err(ioerr.description().to_owned())
},
serde_json::Error::Syntax(_, l, c) => {
return Err(format!("syntax at {}:{}", l, c))
},
serde_json::Error::FromUtf8(e) => {
return Err(e.description().to_owned())
},
},
};
},

Просмотреть файл

@ -25,7 +25,6 @@ heapsize = "0.3.0"
heapsize_plugin = "0.1.2"
hyper = { version = "0.8", features = [ "serde-serialization" ] }
time = "0.1"
rustc-serialize = "0.3"
bitflags = "0.3"
serde = "0.7"
serde_macros = "0.7"

Просмотреть файл

@ -21,7 +21,6 @@ extern crate heapsize;
extern crate hyper;
extern crate ipc_channel;
extern crate msg;
extern crate rustc_serialize;
extern crate serde;
extern crate time;
extern crate url;
@ -32,7 +31,6 @@ use hyper::http::RawStatus;
use hyper::method::Method;
use ipc_channel::ipc::IpcSender;
use msg::constellation_msg::PipelineId;
use rustc_serialize::{Decodable, Decoder};
use std::net::TcpStream;
use time::Duration;
use time::Tm;
@ -218,26 +216,12 @@ pub enum DevtoolScriptControlMsg {
RequestAnimationFrame(PipelineId, String),
}
#[derive(RustcEncodable, Deserialize, Serialize)]
#[derive(Deserialize, Serialize)]
pub struct Modification {
pub attributeName: String,
pub newValue: Option<String>,
}
impl Decodable for Modification {
fn decode<D: Decoder>(d: &mut D) -> Result<Modification, D::Error> {
d.read_struct("Modification", 2, |d|
Ok(Modification {
attributeName: try!(d.read_struct_field("attributeName", 0, Decodable::decode)),
newValue: match d.read_struct_field("newValue", 1, Decodable::decode) {
Ok(opt) => opt,
Err(_) => None
}
})
)
}
}
#[derive(Clone, Deserialize, Serialize)]
pub enum LogLevel {
Log,
@ -264,9 +248,10 @@ bitflags! {
}
}
#[derive(RustcEncodable, Deserialize, Serialize)]
#[derive(Deserialize, Serialize)]
pub struct PageError {
pub _type: String,
#[serde(rename = "type")]
pub type_: String,
pub errorMessage: String,
pub sourceName: String,
pub lineText: String,
@ -281,9 +266,10 @@ pub struct PageError {
pub private: bool,
}
#[derive(RustcEncodable, Deserialize, Serialize)]
#[derive(Deserialize, Serialize)]
pub struct ConsoleAPI {
pub _type: String,
#[serde(rename = "type")]
pub type_: String,
pub level: String,
pub filename: String,
pub lineNumber: u32,

Просмотреть файл

@ -167,7 +167,7 @@ pub fn handle_get_cached_messages(_pipeline_id: PipelineId,
// TODO: make script error reporter pass all reported errors
// to devtools and cache them for returning here.
let msg = PageError {
_type: "PageError".to_owned(),
type_: "PageError".to_owned(),
errorMessage: "page error test".to_owned(),
sourceName: String::new(),
lineText: String::new(),
@ -186,7 +186,7 @@ pub fn handle_get_cached_messages(_pipeline_id: PipelineId,
if message_types.contains(CONSOLE_API) {
// TODO: do for real
let msg = ConsoleAPI {
_type: "ConsoleAPI".to_owned(),
type_: "ConsoleAPI".to_owned(),
level: "error".to_owned(),
filename: "http://localhost/~mihai/mozilla/test.html".to_owned(),
lineNumber: 0,

2
servo/components/servo/Cargo.lock сгенерированный
Просмотреть файл

@ -412,7 +412,6 @@ dependencies = [
"log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
"plugins 0.0.1",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -431,7 +430,6 @@ dependencies = [
"ipc-channel 0.2.1 (git+https://github.com/servo/ipc-channel)",
"msg 0.0.1",
"plugins 0.0.1",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",

2
servo/ports/cef/Cargo.lock сгенерированный
Просмотреть файл

@ -381,7 +381,6 @@ dependencies = [
"log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
"plugins 0.0.1",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -400,7 +399,6 @@ dependencies = [
"ipc-channel 0.2.1 (git+https://github.com/servo/ipc-channel)",
"msg 0.0.1",
"plugins 0.0.1",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",

2
servo/ports/gonk/Cargo.lock сгенерированный
Просмотреть файл

@ -374,7 +374,6 @@ dependencies = [
"log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
"plugins 0.0.1",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -393,7 +392,6 @@ dependencies = [
"ipc-channel 0.2.1 (git+https://github.com/servo/ipc-channel)",
"msg 0.0.1",
"plugins 0.0.1",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",