Format components devtools and devtools_traits #21373

This commit is contained in:
kingdido999 2018-09-02 20:29:47 +08:00
parent b211e45bb0
commit ad822b74c7
17 changed files with 669 additions and 461 deletions

View file

@ -94,32 +94,48 @@ impl Actor for ConsoleActor {
self.name.clone()
}
fn handle_message(&self,
registry: &ActorRegistry,
msg_type: &str,
msg: &Map<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
fn handle_message(
&self,
registry: &ActorRegistry,
msg_type: &str,
msg: &Map<String, Value>,
stream: &mut TcpStream,
) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"getCachedMessages" => {
let str_types = msg.get("messageTypes").unwrap().as_array().unwrap().into_iter().map(|json_type| {
json_type.as_str().unwrap()
});
let str_types = msg
.get("messageTypes")
.unwrap()
.as_array()
.unwrap()
.into_iter()
.map(|json_type| json_type.as_str().unwrap());
let mut message_types = CachedConsoleMessageTypes::empty();
for str_type in str_types {
match str_type {
"PageError" => message_types.insert(CachedConsoleMessageTypes::PAGE_ERROR),
"ConsoleAPI" => message_types.insert(CachedConsoleMessageTypes::CONSOLE_API),
"ConsoleAPI" => {
message_types.insert(CachedConsoleMessageTypes::CONSOLE_API)
},
s => debug!("unrecognized message type requested: \"{}\"", s),
};
};
}
let (chan, port) = ipc::channel().unwrap();
self.script_chan.send(DevtoolScriptControlMsg::GetCachedMessages(
self.pipeline, message_types, chan)).unwrap();
let messages = port.recv().map_err(|_| ())?.into_iter().map(|message| {
let json_string = message.encode().unwrap();
let json = serde_json::from_str::<Value>(&json_string).unwrap();
json.as_object().unwrap().to_owned()
}).collect();
self.script_chan
.send(DevtoolScriptControlMsg::GetCachedMessages(
self.pipeline,
message_types,
chan,
)).unwrap();
let messages = port
.recv()
.map_err(|_| ())?
.into_iter()
.map(|message| {
let json_string = message.encode().unwrap();
let json = serde_json::from_str::<Value>(&json_string).unwrap();
json.as_object().unwrap().to_owned()
}).collect();
let msg = GetCachedMessagesReply {
from: self.name(),
@ -127,56 +143,60 @@ impl Actor for ConsoleActor {
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
"startListeners" => {
//TODO: actually implement listener filters that support starting/stopping
let msg = StartedListenersReply {
from: self.name(),
nativeConsoleAPI: true,
startedListeners:
vec!("PageError".to_owned(), "ConsoleAPI".to_owned()),
startedListeners: vec!["PageError".to_owned(), "ConsoleAPI".to_owned()],
traits: StartedListenersTraits {
customNetworkRequest: true,
}
},
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
"stopListeners" => {
//TODO: actually implement listener filters that support starting/stopping
let msg = StopListenersReply {
from: self.name(),
stoppedListeners: msg.get("listeners")
.unwrap()
.as_array()
.unwrap_or(&vec!())
.iter()
.map(|listener| listener.as_str().unwrap().to_owned())
.collect(),
stoppedListeners: msg
.get("listeners")
.unwrap()
.as_array()
.unwrap_or(&vec![])
.iter()
.map(|listener| listener.as_str().unwrap().to_owned())
.collect(),
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
//TODO: implement autocompletion like onAutocomplete in
// http://mxr.mozilla.org/mozilla-central/source/toolkit/devtools/server/actors/webconsole.js
"autocomplete" => {
let msg = AutocompleteReply {
from: self.name(),
matches: vec!(),
matches: vec![],
matchProp: "".to_owned(),
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
"evaluateJS" => {
let input = msg.get("text").unwrap().as_str().unwrap().to_owned();
let (chan, port) = ipc::channel().unwrap();
self.script_chan.send(DevtoolScriptControlMsg::EvaluateJS(
self.pipeline, input.clone(), chan)).unwrap();
self.script_chan
.send(DevtoolScriptControlMsg::EvaluateJS(
self.pipeline,
input.clone(),
chan,
)).unwrap();
//TODO: extract conversion into protocol module or some other useful place
let result = match port.recv().map_err(|_| ())? {
@ -184,12 +204,12 @@ impl Actor for ConsoleActor {
let mut m = Map::new();
m.insert("type".to_owned(), Value::String("undefined".to_owned()));
Value::Object(m)
}
},
NullValue => {
let mut m = Map::new();
m.insert("type".to_owned(), Value::String("null".to_owned()));
Value::Object(m)
}
},
BooleanValue(val) => Value::Bool(val),
NumberValue(val) => {
if val.is_nan() {
@ -211,7 +231,7 @@ impl Actor for ConsoleActor {
} else {
Value::Number(Number::from_f64(val).unwrap())
}
}
},
StringValue(s) => Value::String(s),
ActorValue { class, uuid } => {
//TODO: make initial ActorValue message include these properties?
@ -225,7 +245,7 @@ impl Actor for ConsoleActor {
m.insert("frozen".to_owned(), Value::Bool(false));
m.insert("sealed".to_owned(), Value::Bool(false));
Value::Object(m)
}
},
};
//TODO: catch and return exception values from JS evaluation
@ -240,7 +260,7 @@ impl Actor for ConsoleActor {
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
"setPreferences" => {
let msg = SetPreferencesReply {
@ -249,9 +269,9 @@ impl Actor for ConsoleActor {
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
_ => ActorMessageStatus::Ignored
_ => ActorMessageStatus::Ignored,
})
}
}

View file

@ -26,21 +26,24 @@ impl Actor for FramerateActor {
self.name.clone()
}
fn handle_message(&self,
_registry: &ActorRegistry,
_msg_type: &str,
_msg: &Map<String, Value>,
_stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
fn handle_message(
&self,
_registry: &ActorRegistry,
_msg_type: &str,
_msg: &Map<String, Value>,
_stream: &mut TcpStream,
) -> Result<ActorMessageStatus, ()> {
Ok(ActorMessageStatus::Ignored)
}
}
impl FramerateActor {
/// return name of actor
pub fn create(registry: &ActorRegistry,
pipeline_id: PipelineId,
script_sender: IpcSender<DevtoolScriptControlMsg>) -> String {
pub fn create(
registry: &ActorRegistry,
pipeline_id: PipelineId,
script_sender: IpcSender<DevtoolScriptControlMsg>,
) -> String {
let actor_name = registry.new_name("framerate");
let mut actor = FramerateActor {
name: actor_name.clone(),
@ -60,8 +63,7 @@ impl FramerateActor {
self.ticks.push(HighResolutionStamp::wrap(tick));
if self.is_recording {
let msg = DevtoolScriptControlMsg::RequestAnimationFrame(self.pipeline,
self.name());
let msg = DevtoolScriptControlMsg::RequestAnimationFrame(self.pipeline, self.name());
self.script_sender.send(msg).unwrap();
}
}
@ -78,8 +80,7 @@ impl FramerateActor {
self.start_time = Some(precise_time_ns());
self.is_recording = true;
let msg = DevtoolScriptControlMsg::RequestAnimationFrame(self.pipeline,
self.name());
let msg = DevtoolScriptControlMsg::RequestAnimationFrame(self.pipeline, self.name());
self.script_sender.send(msg).unwrap();
}
@ -90,7 +91,6 @@ impl FramerateActor {
self.is_recording = false;
self.start_time = None;
}
}
impl Drop for FramerateActor {

View file

@ -61,27 +61,25 @@ impl Actor for HighlighterActor {
self.name.clone()
}
fn handle_message(&self,
_registry: &ActorRegistry,
msg_type: &str,
_msg: &Map<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
fn handle_message(
&self,
_registry: &ActorRegistry,
msg_type: &str,
_msg: &Map<String, Value>,
stream: &mut TcpStream,
) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"showBoxModel" => {
let msg = ShowBoxModelReply {
from: self.name(),
};
let msg = ShowBoxModelReply { from: self.name() };
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
"hideBoxModel" => {
let msg = HideBoxModelReply {
from: self.name(),
};
let msg = HideBoxModelReply { from: self.name() };
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
_ => ActorMessageStatus::Ignored,
})
@ -98,29 +96,33 @@ impl Actor for NodeActor {
self.name.clone()
}
fn handle_message(&self,
registry: &ActorRegistry,
msg_type: &str,
msg: &Map<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
fn handle_message(
&self,
registry: &ActorRegistry,
msg_type: &str,
msg: &Map<String, Value>,
stream: &mut TcpStream,
) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"modifyAttributes" => {
let target = msg.get("to").unwrap().as_str().unwrap();
let mods = msg.get("modifications").unwrap().as_array().unwrap();
let modifications = mods.iter().map(|json_mod| {
serde_json::from_str(&serde_json::to_string(json_mod).unwrap()).unwrap()
}).collect();
let modifications = mods
.iter()
.map(|json_mod| {
serde_json::from_str(&serde_json::to_string(json_mod).unwrap()).unwrap()
}).collect();
self.script_chan.send(ModifyAttribute(self.pipeline,
registry.actor_to_script(target.to_owned()),
modifications))
.unwrap();
let reply = ModifyAttributeReply {
from: self.name(),
};
self.script_chan
.send(ModifyAttribute(
self.pipeline,
registry.actor_to_script(target.to_owned()),
modifications,
)).unwrap();
let reply = ModifyAttributeReply { from: self.name() };
stream.write_json_packet(&reply);
ActorMessageStatus::Processed
}
},
_ => ActorMessageStatus::Ignored,
})
@ -175,19 +177,23 @@ struct NodeActorMsg {
}
trait NodeInfoToProtocol {
fn encode(self,
actors: &ActorRegistry,
display: bool,
script_chan: IpcSender<DevtoolScriptControlMsg>,
pipeline: PipelineId) -> NodeActorMsg;
fn encode(
self,
actors: &ActorRegistry,
display: bool,
script_chan: IpcSender<DevtoolScriptControlMsg>,
pipeline: PipelineId,
) -> NodeActorMsg;
}
impl NodeInfoToProtocol for NodeInfo {
fn encode(self,
actors: &ActorRegistry,
display: bool,
script_chan: IpcSender<DevtoolScriptControlMsg>,
pipeline: PipelineId) -> NodeActorMsg {
fn encode(
self,
actors: &ActorRegistry,
display: bool,
script_chan: IpcSender<DevtoolScriptControlMsg>,
pipeline: PipelineId,
) -> NodeActorMsg {
let actor_name = if !actors.script_actor_registered(self.uniqueId.clone()) {
let name = actors.new_name("node");
let node_actor = NodeActor {
@ -215,15 +221,16 @@ impl NodeInfoToProtocol for NodeInfo {
publicId: self.publicId,
systemId: self.systemId,
attrs: self.attrs.into_iter().map(|attr| {
AttrMsg {
attrs: self
.attrs
.into_iter()
.map(|attr| AttrMsg {
namespace: attr.namespace,
name: attr.name,
value: attr.value,
}
}).collect(),
}).collect(),
pseudoClassLocks: vec!(), //TODO get this data from script
pseudoClassLocks: vec![], //TODO get this data from script
isDisplayed: display,
@ -272,25 +279,28 @@ impl Actor for WalkerActor {
self.name.clone()
}
fn handle_message(&self,
registry: &ActorRegistry,
msg_type: &str,
msg: &Map<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
fn handle_message(
&self,
registry: &ActorRegistry,
msg_type: &str,
msg: &Map<String, Value>,
stream: &mut TcpStream,
) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"querySelector" => {
let msg = QuerySelectorReply {
from: self.name(),
};
let msg = QuerySelectorReply { from: self.name() };
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
"documentElement" => {
let (tx, rx) = ipc::channel().unwrap();
self.script_chan.send(GetDocumentElement(self.pipeline, tx)).unwrap();
self.script_chan
.send(GetDocumentElement(self.pipeline, tx))
.unwrap();
let doc_elem_info = rx.recv().unwrap().ok_or(())?;
let node = doc_elem_info.encode(registry, true, self.script_chan.clone(), self.pipeline);
let node =
doc_elem_info.encode(registry, true, self.script_chan.clone(), self.pipeline);
let msg = DocumentElementReply {
from: self.name(),
@ -298,36 +308,38 @@ impl Actor for WalkerActor {
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
"clearPseudoClassLocks" => {
let msg = ClearPseudoclassesReply {
from: self.name(),
};
let msg = ClearPseudoclassesReply { from: self.name() };
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
"children" => {
let target = msg.get("node").unwrap().as_str().unwrap();
let (tx, rx) = ipc::channel().unwrap();
self.script_chan.send(GetChildren(self.pipeline,
registry.actor_to_script(target.to_owned()),
tx))
.unwrap();
self.script_chan
.send(GetChildren(
self.pipeline,
registry.actor_to_script(target.to_owned()),
tx,
)).unwrap();
let children = rx.recv().unwrap().ok_or(())?;
let msg = ChildrenReply {
hasFirst: true,
hasLast: true,
nodes: children.into_iter().map(|child| {
child.encode(registry, true, self.script_chan.clone(), self.pipeline)
}).collect(),
nodes: children
.into_iter()
.map(|child| {
child.encode(registry, true, self.script_chan.clone(), self.pipeline)
}).collect(),
from: self.name(),
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
_ => ActorMessageStatus::Ignored,
})
@ -447,52 +459,72 @@ impl Actor for PageStyleActor {
self.name.clone()
}
fn handle_message(&self,
registry: &ActorRegistry,
msg_type: &str,
msg: &Map<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
fn handle_message(
&self,
registry: &ActorRegistry,
msg_type: &str,
msg: &Map<String, Value>,
stream: &mut TcpStream,
) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"getApplied" => {
//TODO: query script for relevant applied styles to node (msg.node)
let msg = GetAppliedReply {
entries: vec!(),
rules: vec!(),
sheets: vec!(),
entries: vec![],
rules: vec![],
sheets: vec![],
from: self.name(),
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
"getComputed" => {
//TODO: query script for relevant computed styles on node (msg.node)
let msg = GetComputedReply {
computed: vec!(),
computed: vec![],
from: self.name(),
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
//TODO: query script for box layout properties of node (msg.node)
"getLayout" => {
let target = msg.get("node").unwrap().as_str().unwrap();
let (tx, rx) = ipc::channel().unwrap();
self.script_chan.send(GetLayout(self.pipeline,
registry.actor_to_script(target.to_owned()),
tx))
.unwrap();
self.script_chan
.send(GetLayout(
self.pipeline,
registry.actor_to_script(target.to_owned()),
tx,
)).unwrap();
let ComputedNodeLayout {
display, position, zIndex, boxSizing,
autoMargins, marginTop, marginRight, marginBottom, marginLeft,
borderTopWidth, borderRightWidth, borderBottomWidth, borderLeftWidth,
paddingTop, paddingRight, paddingBottom, paddingLeft,
width, height,
display,
position,
zIndex,
boxSizing,
autoMargins,
marginTop,
marginRight,
marginBottom,
marginLeft,
borderTopWidth,
borderRightWidth,
borderBottomWidth,
borderLeftWidth,
paddingTop,
paddingRight,
paddingBottom,
paddingLeft,
width,
height,
} = rx.recv().unwrap().ok_or(())?;
let auto_margins = msg.get("autoMargins")
.and_then(&Value::as_bool).unwrap_or(false);
let auto_margins = msg
.get("autoMargins")
.and_then(&Value::as_bool)
.unwrap_or(false);
// http://mxr.mozilla.org/mozilla-central/source/toolkit/devtools/server/actors/styles.js
let msg = GetLayoutReply {
@ -504,10 +536,18 @@ impl Actor for PageStyleActor {
autoMargins: if auto_margins {
let mut m = Map::new();
let auto = serde_json::value::Value::String("auto".to_owned());
if autoMargins.top { m.insert("top".to_owned(), auto.clone()); }
if autoMargins.right { m.insert("right".to_owned(), auto.clone()); }
if autoMargins.bottom { m.insert("bottom".to_owned(), auto.clone()); }
if autoMargins.left { m.insert("left".to_owned(), auto.clone()); }
if autoMargins.top {
m.insert("top".to_owned(), auto.clone());
}
if autoMargins.right {
m.insert("right".to_owned(), auto.clone());
}
if autoMargins.bottom {
m.insert("bottom".to_owned(), auto.clone());
}
if autoMargins.left {
m.insert("left".to_owned(), auto.clone());
}
serde_json::value::Value::Object(m)
} else {
serde_json::value::Value::Null
@ -531,7 +571,7 @@ impl Actor for PageStyleActor {
let msg = serde_json::from_str::<Value>(&msg).unwrap();
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
_ => ActorMessageStatus::Ignored,
})
@ -543,11 +583,13 @@ impl Actor for InspectorActor {
self.name.clone()
}
fn handle_message(&self,
registry: &ActorRegistry,
msg_type: &str,
_msg: &Map<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
fn handle_message(
&self,
registry: &ActorRegistry,
msg_type: &str,
_msg: &Map<String, Value>,
stream: &mut TcpStream,
) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"getWalker" => {
if self.walker.borrow().is_none() {
@ -562,21 +604,24 @@ impl Actor for InspectorActor {
}
let (tx, rx) = ipc::channel().unwrap();
self.script_chan.send(GetRootNode(self.pipeline, tx)).unwrap();
self.script_chan
.send(GetRootNode(self.pipeline, tx))
.unwrap();
let root_info = rx.recv().unwrap().ok_or(())?;
let node = root_info.encode(registry, false, self.script_chan.clone(), self.pipeline);
let node =
root_info.encode(registry, false, self.script_chan.clone(), self.pipeline);
let msg = GetWalkerReply {
from: self.name(),
walker: WalkerMsg {
actor: self.walker.borrow().clone().unwrap(),
root: node,
}
},
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
"getPageStyle" => {
if self.pageStyle.borrow().is_none() {
@ -598,7 +643,7 @@ impl Actor for InspectorActor {
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
//TODO: this is an old message; try adding highlightable to the root traits instead
// and support getHighlighter instead
@ -621,7 +666,7 @@ impl Actor for InspectorActor {
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
_ => ActorMessageStatus::Ignored,
})

View file

@ -28,11 +28,13 @@ impl Actor for MemoryActor {
self.name.clone()
}
fn handle_message(&self,
_registry: &ActorRegistry,
_msg_type: &str,
_msg: &Map<String, Value>,
_stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
fn handle_message(
&self,
_registry: &ActorRegistry,
_msg_type: &str,
_msg: &Map<String, Value>,
_stream: &mut TcpStream,
) -> Result<ActorMessageStatus, ()> {
Ok(ActorMessageStatus::Ignored)
}
}
@ -42,7 +44,7 @@ impl MemoryActor {
pub fn create(registry: &ActorRegistry) -> String {
let actor_name = registry.new_name("memory");
let actor = MemoryActor {
name: actor_name.clone()
name: actor_name.clone(),
};
registry.register_later(Box::new(actor));

View file

@ -34,7 +34,7 @@ struct HttpRequest {
struct HttpResponse {
headers: Option<Headers>,
status: Option<RawStatus>,
body: Option<Vec<u8>>
body: Option<Vec<u8>>,
}
pub struct NetworkEventActor {
@ -52,7 +52,7 @@ pub struct EventActor {
pub startedDateTime: String,
pub timeStamp: i64,
pub isXHR: bool,
pub private: bool
pub private: bool,
}
#[derive(Serialize)]
@ -79,14 +79,12 @@ pub struct ResponseContentMsg {
pub discardResponseBody: bool,
}
#[derive(Serialize)]
pub struct ResponseHeadersMsg {
pub headers: usize,
pub headersSize: usize,
}
#[derive(Serialize)]
pub struct RequestCookiesMsg {
pub cookies: usize,
@ -103,7 +101,7 @@ struct GetRequestHeadersReply {
from: String,
headers: Vec<Header>,
headerSize: usize,
rawHeaders: String
rawHeaders: String,
}
#[derive(Serialize)]
@ -117,7 +115,7 @@ struct GetResponseHeadersReply {
from: String,
headers: Vec<Header>,
headerSize: usize,
rawHeaders: String
rawHeaders: String,
}
#[derive(Serialize)]
@ -131,19 +129,19 @@ struct GetResponseContentReply {
struct GetRequestPostDataReply {
from: String,
postData: Option<Vec<u8>>,
postDataDiscarded: bool
postDataDiscarded: bool,
}
#[derive(Serialize)]
struct GetRequestCookiesReply {
from: String,
cookies: Vec<u8>
cookies: Vec<u8>,
}
#[derive(Serialize)]
struct GetResponseCookiesReply {
from: String,
cookies: Vec<u8>
cookies: Vec<u8>,
}
#[derive(Serialize)]
@ -179,11 +177,13 @@ impl Actor for NetworkEventActor {
self.name.clone()
}
fn handle_message(&self,
_registry: &ActorRegistry,
msg_type: &str,
_msg: &Map<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
fn handle_message(
&self,
_registry: &ActorRegistry,
msg_type: &str,
_msg: &Map<String, Value>,
stream: &mut TcpStream,
) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"getRequestHeaders" => {
let mut headers = Vec::new();
@ -194,7 +194,10 @@ impl Actor for NetworkEventActor {
let value = item.value_string();
rawHeadersString = rawHeadersString + name + ":" + &value + "\r\n";
headersSize += name.len() + value.len();
headers.push(Header { name: name.to_owned(), value: value.to_owned() });
headers.push(Header {
name: name.to_owned(),
value: value.to_owned(),
});
}
let msg = GetRequestHeadersReply {
from: self.name(),
@ -204,7 +207,7 @@ impl Actor for NetworkEventActor {
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
"getRequestCookies" => {
let mut cookies = Vec::new();
if let Some(req_cookies) = self.request.headers.get_raw("Cookie") {
@ -221,7 +224,7 @@ impl Actor for NetworkEventActor {
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
"getRequestPostData" => {
let msg = GetRequestPostDataReply {
from: self.name(),
@ -230,7 +233,7 @@ impl Actor for NetworkEventActor {
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
"getResponseHeaders" => {
if let Some(ref response_headers) = self.response.headers {
let mut headers = vec![];
@ -258,7 +261,7 @@ impl Actor for NetworkEventActor {
stream.write_json_packet(&msg);
}
ActorMessageStatus::Processed
}
},
"getResponseCookies" => {
let mut cookies = Vec::new();
if let Some(res_cookies) = self.request.headers.get_raw("set-cookie") {
@ -275,7 +278,7 @@ impl Actor for NetworkEventActor {
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
"getResponseContent" => {
let msg = GetResponseContentReply {
from: self.name(),
@ -284,7 +287,7 @@ impl Actor for NetworkEventActor {
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
"getEventTimings" => {
// TODO: This is a fake timings msg
let timingsObj = Timings {
@ -304,19 +307,19 @@ impl Actor for NetworkEventActor {
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
"getSecurityInfo" => {
// TODO: Send the correct values for securityInfo.
let msg = GetSecurityInfoReply {
from: self.name(),
securityInfo: SecurityInfo {
state: "insecure".to_owned()
state: "insecure".to_owned(),
},
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
_ => ActorMessageStatus::Ignored
},
_ => ActorMessageStatus::Ignored,
})
}
}
@ -382,8 +385,13 @@ impl NetworkEventActor {
// TODO: Send the correct values for all these fields.
let hSizeOption = self.response.headers.as_ref().map(|headers| headers.len());
let hSize = hSizeOption.unwrap_or(0);
let (status_code, status_message) = self.response.status.as_ref().
map_or((0, "".to_owned()), |&RawStatus(ref code, ref text)| (*code, text.clone().into_owned()));
let (status_code, status_message) = self
.response
.status
.as_ref()
.map_or((0, "".to_owned()), |&RawStatus(ref code, ref text)| {
(*code, text.clone().into_owned())
});
// TODO: Send the correct values for remoteAddress and remotePort and http_version.
ResponseStartMsg {
httpVersion: "HTTP/1.1".to_owned(),
@ -392,7 +400,7 @@ impl NetworkEventActor {
status: status_code.to_string(),
statusText: status_message,
headersSize: hSize,
discardResponseBody: false
discardResponseBody: false,
}
}
@ -401,7 +409,7 @@ impl NetworkEventActor {
if let Some(ref headers) = self.response.headers {
mString = match headers.get() {
Some(&ContentType(ref mime)) => mime.to_string(),
None => "".to_owned()
None => "".to_owned(),
};
}
// TODO: Set correct values when response's body is sent to the devtools in http_loader.
@ -418,7 +426,7 @@ impl NetworkEventActor {
if let Some(ref headers) = self.response.headers {
cookies_size = match headers.get() {
Some(&Cookie(ref cookie)) => cookie.len(),
None => 0
None => 0,
};
}
ResponseCookiesMsg {
@ -431,10 +439,9 @@ impl NetworkEventActor {
let mut headers_byte_count = 0;
if let Some(ref headers) = self.response.headers {
headers_size = headers.len();
for item in headers.iter() {
for item in headers.iter() {
headers_byte_count += item.name().len() + item.value_string().len();
}
}
ResponseHeadersMsg {
headers: headers_size,
@ -443,10 +450,11 @@ impl NetworkEventActor {
}
pub fn request_headers(&self) -> RequestHeadersMsg {
let size = self.request
.headers
.iter()
.fold(0, |acc, h| acc + h.name().len() + h.value_string().len());
let size = self
.request
.headers
.iter()
.fold(0, |acc, h| acc + h.name().len() + h.value_string().len());
RequestHeadersMsg {
headers: self.request.headers.len(),
headersSize: size,
@ -456,7 +464,7 @@ impl NetworkEventActor {
pub fn request_cookies(&self) -> RequestCookiesMsg {
let cookies_size = match self.request.headers.get() {
Some(&Cookie(ref cookie)) => cookie.len(),
None => 0
None => 0,
};
RequestCookiesMsg {
cookies: cookies_size,

View file

@ -15,11 +15,13 @@ impl Actor for ObjectActor {
fn name(&self) -> String {
self.name.clone()
}
fn handle_message(&self,
_: &ActorRegistry,
_: &str,
_: &Map<String, Value>,
_: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
fn handle_message(
&self,
_: &ActorRegistry,
_: &str,
_: &Map<String, Value>,
_: &mut TcpStream,
) -> Result<ActorMessageStatus, ()> {
Ok(ActorMessageStatus::Ignored)
}
}

View file

@ -51,11 +51,13 @@ impl Actor for PerformanceActor {
self.name.clone()
}
fn handle_message(&self,
_registry: &ActorRegistry,
msg_type: &str,
_msg: &Map<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
fn handle_message(
&self,
_registry: &ActorRegistry,
msg_type: &str,
_msg: &Map<String, Value>,
stream: &mut TcpStream,
) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"connect" => {
let msg = ConnectReply {
@ -79,11 +81,11 @@ impl Actor for PerformanceActor {
value: SuccessMsg {
success: true,
errors: vec![],
}
},
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
_ => ActorMessageStatus::Ignored,
})
}
@ -91,28 +93,34 @@ impl Actor for PerformanceActor {
impl PerformanceActor {
pub fn new(name: String) -> PerformanceActor {
PerformanceActor {
name: name,
}
PerformanceActor { name: name }
}
pub fn description() -> ActorDescription {
ActorDescription {
category: "actor",
typeName: "performance",
methods: vec![
Method {
name: "canCurrentlyRecord",
request: Value::Object(vec![
("type".to_owned(), Value::String("canCurrentlyRecord".to_owned())),
].into_iter().collect()),
response: Value::Object(vec![
("value".to_owned(), Value::Object(vec![
("_retval".to_owned(), Value::String("json".to_owned())),
].into_iter().collect())),
].into_iter().collect()),
},
],
methods: vec![Method {
name: "canCurrentlyRecord",
request: Value::Object(
vec![(
"type".to_owned(),
Value::String("canCurrentlyRecord".to_owned()),
)].into_iter()
.collect(),
),
response: Value::Object(
vec![(
"value".to_owned(),
Value::Object(
vec![("_retval".to_owned(), Value::String("json".to_owned()))]
.into_iter()
.collect(),
),
)].into_iter()
.collect(),
),
}],
}
}
}

View file

@ -15,19 +15,19 @@ impl Actor for ProfilerActor {
self.name.clone()
}
fn handle_message(&self,
_registry: &ActorRegistry,
_msg_type: &str,
_msg: &Map<String, Value>,
_stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
fn handle_message(
&self,
_registry: &ActorRegistry,
_msg_type: &str,
_msg: &Map<String, Value>,
_stream: &mut TcpStream,
) -> Result<ActorMessageStatus, ()> {
Ok(ActorMessageStatus::Ignored)
}
}
impl ProfilerActor {
pub fn new(name: String) -> ProfilerActor {
ProfilerActor {
name: name,
}
ProfilerActor { name: name }
}
}

View file

@ -6,7 +6,6 @@
/// (http://mxr.mozilla.org/mozilla-central/source/toolkit/devtools/server/actors/root.js).
/// Connection point for all new remote devtools interactions, providing lists of know actors
/// that perform more specific actions (tabs, addons, browser chrome, etc.)
use actor::{Actor, ActorMessageStatus, ActorRegistry};
use actors::performance::PerformanceActor;
use actors::tab::{TabActor, TabActorMsg};
@ -65,11 +64,13 @@ impl Actor for RootActor {
"root".to_owned()
}
fn handle_message(&self,
registry: &ActorRegistry,
msg_type: &str,
_msg: &Map<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
fn handle_message(
&self,
registry: &ActorRegistry,
msg_type: &str,
_msg: &Map<String, Value>,
stream: &mut TcpStream,
) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"listAddons" => {
let actor = ListAddonsReply {
@ -78,20 +79,22 @@ impl Actor for RootActor {
};
stream.write_json_packet(&actor);
ActorMessageStatus::Processed
}
},
//https://wiki.mozilla.org/Remote_Debugging_Protocol#Listing_Browser_Tabs
"listTabs" => {
let actor = ListTabsReply {
from: "root".to_owned(),
selected: 0,
tabs: self.tabs.iter().map(|tab| {
registry.find::<TabActor>(tab).encodable()
}).collect()
tabs: self
.tabs
.iter()
.map(|tab| registry.find::<TabActor>(tab).encodable())
.collect(),
};
stream.write_json_packet(&actor);
ActorMessageStatus::Processed
}
},
"protocolDescription" => {
let msg = ProtocolDescriptionReply {
@ -102,9 +105,9 @@ impl Actor for RootActor {
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
_ => ActorMessageStatus::Ignored
_ => ActorMessageStatus::Ignored,
})
}
}
@ -118,7 +121,7 @@ impl RootActor {
sources: true,
highlightable: true,
customHighlighters: true,
networkMonitor: true
networkMonitor: true,
},
}
}

View file

@ -37,7 +37,7 @@ struct TabDetachedReply {
#[derive(Serialize)]
struct ReconfigureReply {
from: String
from: String,
}
#[derive(Serialize)]
@ -84,25 +84,28 @@ impl Actor for TabActor {
self.name.clone()
}
fn handle_message(&self,
registry: &ActorRegistry,
msg_type: &str,
msg: &Map<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
fn handle_message(
&self,
registry: &ActorRegistry,
msg_type: &str,
msg: &Map<String, Value>,
stream: &mut TcpStream,
) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"reconfigure" => {
if let Some(options) = msg.get("options").and_then(|o| o.as_object()) {
if let Some(val) = options.get("performReload") {
if val.as_bool().unwrap_or(false) {
let console_actor = registry.find::<ConsoleActor>(&self.console);
let _ = console_actor.script_chan.send(
DevtoolScriptControlMsg::Reload(console_actor.pipeline));
let _ = console_actor
.script_chan
.send(DevtoolScriptControlMsg::Reload(console_actor.pipeline));
}
}
}
stream.write_json_packet(&ReconfigureReply { from: self.name() });
ActorMessageStatus::Processed
}
},
// https://wiki.mozilla.org/Remote_Debugging_Protocol#Listing_Browser_Tabs
// (see "To attach to a _tabActor_")
@ -116,12 +119,17 @@ impl Actor for TabActor {
traits: TabTraits,
};
let console_actor = registry.find::<ConsoleActor>(&self.console);
console_actor.streams.borrow_mut().push(stream.try_clone().unwrap());
console_actor
.streams
.borrow_mut()
.push(stream.try_clone().unwrap());
stream.write_json_packet(&msg);
console_actor.script_chan.send(
WantsLiveNotifications(console_actor.pipeline, true)).unwrap();
console_actor
.script_chan
.send(WantsLiveNotifications(console_actor.pipeline, true))
.unwrap();
ActorMessageStatus::Processed
}
},
//FIXME: The current implementation won't work for multiple connections. Need to ensure 105
// that the correct stream is removed.
@ -133,21 +141,23 @@ impl Actor for TabActor {
let console_actor = registry.find::<ConsoleActor>(&self.console);
console_actor.streams.borrow_mut().pop();
stream.write_json_packet(&msg);
console_actor.script_chan.send(
WantsLiveNotifications(console_actor.pipeline, false)).unwrap();
console_actor
.script_chan
.send(WantsLiveNotifications(console_actor.pipeline, false))
.unwrap();
ActorMessageStatus::Processed
}
},
"listFrames" => {
let msg = ListFramesReply {
from: self.name(),
frames: vec!(),
frames: vec![],
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
_ => ActorMessageStatus::Ignored
_ => ActorMessageStatus::Ignored,
})
}
}

View file

@ -35,7 +35,7 @@ struct ThreadResumedReply {
#[derive(Serialize)]
struct ReconfigureReply {
from: String
from: String,
}
#[derive(Serialize)]
@ -53,9 +53,7 @@ pub struct ThreadActor {
impl ThreadActor {
pub fn new(name: String) -> ThreadActor {
ThreadActor {
name: name,
}
ThreadActor { name: name }
}
}
@ -64,11 +62,13 @@ impl Actor for ThreadActor {
self.name.clone()
}
fn handle_message(&self,
registry: &ActorRegistry,
msg_type: &str,
_msg: &Map<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
fn handle_message(
&self,
registry: &ActorRegistry,
msg_type: &str,
_msg: &Map<String, Value>,
stream: &mut TcpStream,
) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"attach" => {
let msg = ThreadAttachedReply {
@ -76,7 +76,9 @@ impl Actor for ThreadActor {
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
@ -94,7 +96,7 @@ impl Actor for ThreadActor {
"reconfigure" => {
stream.write_json_packet(&ReconfigureReply { from: self.name() });
ActorMessageStatus::Processed
}
},
"sources" => {
let msg = SourcesReply {
@ -103,7 +105,7 @@ impl Actor for ThreadActor {
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
_ => ActorMessageStatus::Ignored,
})

View file

@ -44,7 +44,7 @@ struct Emitter {
#[derive(Serialize)]
struct IsRecordingReply {
from: String,
value: bool
value: bool,
}
#[derive(Serialize)]
@ -103,8 +103,10 @@ pub struct HighResolutionStamp(f64);
impl HighResolutionStamp {
pub fn new(start_stamp: PreciseTime, time: PreciseTime) -> HighResolutionStamp {
let duration = start_stamp.to(time).num_microseconds()
.expect("Too big duration in microseconds");
let duration = start_stamp
.to(time)
.num_microseconds()
.expect("Too big duration in microseconds");
HighResolutionStamp(duration as f64 / 1000 as f64)
}
@ -122,11 +124,12 @@ impl Serialize for HighResolutionStamp {
static DEFAULT_TIMELINE_DATA_PULL_TIMEOUT: u64 = 200; //ms
impl TimelineActor {
pub fn new(name: String,
pipeline: PipelineId,
script_sender: IpcSender<DevtoolScriptControlMsg>) -> TimelineActor {
let marker_types = vec!(TimelineMarkerType::Reflow,
TimelineMarkerType::DOMEvent);
pub fn new(
name: String,
pipeline: PipelineId,
script_sender: IpcSender<DevtoolScriptControlMsg>,
) -> TimelineActor {
let marker_types = vec![TimelineMarkerType::Reflow, TimelineMarkerType::DOMEvent];
TimelineActor {
name: name,
@ -141,15 +144,20 @@ impl TimelineActor {
}
}
fn pull_timeline_data(&self, receiver: IpcReceiver<Option<TimelineMarker>>, mut emitter: Emitter) {
fn pull_timeline_data(
&self,
receiver: IpcReceiver<Option<TimelineMarker>>,
mut emitter: Emitter,
) {
let is_recording = self.is_recording.clone();
if !*is_recording.lock().unwrap() {
return;
}
thread::Builder::new().name("PullTimelineMarkers".to_owned()).spawn(move || {
loop {
thread::Builder::new()
.name("PullTimelineMarkers".to_owned())
.spawn(move || loop {
if !*is_recording.lock().unwrap() {
break;
}
@ -161,8 +169,7 @@ impl TimelineActor {
emitter.send(markers);
thread::sleep(Duration::from_millis(DEFAULT_TIMELINE_DATA_PULL_TIMEOUT));
}
}).expect("Thread spawning failed");
}).expect("Thread spawning failed");
}
}
@ -171,19 +178,24 @@ impl Actor for TimelineActor {
self.name.clone()
}
fn handle_message(&self,
registry: &ActorRegistry,
msg_type: &str,
msg: &Map<String, Value>,
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
fn handle_message(
&self,
registry: &ActorRegistry,
msg_type: &str,
msg: &Map<String, Value>,
stream: &mut TcpStream,
) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"start" => {
**self.is_recording.lock().as_mut().unwrap() = true;
let (tx, rx) = ipc::channel::<Option<TimelineMarker>>().unwrap();
self.script_sender.send(SetTimelineMarkers(self.pipeline,
self.marker_types.clone(),
tx)).unwrap();
self.script_sender
.send(SetTimelineMarkers(
self.pipeline,
self.marker_types.clone(),
tx,
)).unwrap();
*self.stream.borrow_mut() = stream.try_clone().ok();
@ -198,18 +210,22 @@ impl Actor for TimelineActor {
if let Some(with_ticks) = msg.get("withTicks") {
if let Some(true) = with_ticks.as_bool() {
let framerate_actor = Some(FramerateActor::create(
registry,
self.pipeline.clone(),
self.script_sender.clone()));
registry,
self.pipeline.clone(),
self.script_sender.clone(),
));
*self.framerate_actor.borrow_mut() = framerate_actor;
}
}
let emitter = Emitter::new(self.name(), registry.shareable(),
registry.start_stamp(),
stream.try_clone().unwrap(),
self.memory_actor.borrow().clone(),
self.framerate_actor.borrow().clone());
let emitter = Emitter::new(
self.name(),
registry.shareable(),
registry.start_stamp(),
stream.try_clone().unwrap(),
self.memory_actor.borrow().clone(),
self.framerate_actor.borrow().clone(),
);
self.pull_timeline_data(rx, emitter);
@ -219,7 +235,7 @@ impl Actor for TimelineActor {
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
"stop" => {
let msg = StopReply {
@ -228,7 +244,11 @@ impl Actor for TimelineActor {
};
stream.write_json_packet(&msg);
self.script_sender.send(DropTimelineMarkers(self.pipeline, self.marker_types.clone())).unwrap();
self.script_sender
.send(DropTimelineMarkers(
self.pipeline,
self.marker_types.clone(),
)).unwrap();
if let Some(ref actor_name) = *self.framerate_actor.borrow() {
registry.drop_actor_later(actor_name.clone());
@ -241,32 +261,32 @@ impl Actor for TimelineActor {
**self.is_recording.lock().as_mut().unwrap() = false;
self.stream.borrow_mut().take();
ActorMessageStatus::Processed
}
},
"isRecording" => {
let msg = IsRecordingReply {
from: self.name(),
value: self.is_recording.lock().unwrap().clone()
value: self.is_recording.lock().unwrap().clone(),
};
stream.write_json_packet(&msg);
ActorMessageStatus::Processed
}
},
_ => {
ActorMessageStatus::Ignored
}
_ => ActorMessageStatus::Ignored,
})
}
}
impl Emitter {
pub fn new(name: String,
registry: Arc<Mutex<ActorRegistry>>,
start_stamp: PreciseTime,
stream: TcpStream,
memory_actor_name: Option<String>,
framerate_actor_name: Option<String>) -> Emitter {
pub fn new(
name: String,
registry: Arc<Mutex<ActorRegistry>>,
start_stamp: PreciseTime,
stream: TcpStream,
memory_actor_name: Option<String>,
framerate_actor_name: Option<String>,
) -> Emitter {
Emitter {
from: name,
stream: stream,

View file

@ -17,11 +17,13 @@ impl Actor for WorkerActor {
fn name(&self) -> String {
self.name.clone()
}
fn handle_message(&self,
_: &ActorRegistry,
_: &str,
_: &Map<String, Value>,
_: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
fn handle_message(
&self,
_: &ActorRegistry,
_: &str,
_: &Map<String, Value>,
_: &mut TcpStream,
) -> Result<ActorMessageStatus, ()> {
Ok(ActorMessageStatus::Processed)
}
}