Implemented GetCachedMessages

This commit is contained in:
Tamir Duberstein 2015-05-23 15:27:37 -04:00
parent be6c251e4c
commit b5f74eb54c
6 changed files with 102 additions and 88 deletions

View file

@ -12,7 +12,7 @@ use protocol::JsonPacketStream;
use devtools_traits::EvaluateJSReply::{NullValue, VoidValue, NumberValue};
use devtools_traits::EvaluateJSReply::{StringValue, BooleanValue, ActorValue};
use devtools_traits::DevtoolScriptControlMsg;
use devtools_traits::{CachedConsoleMessageTypes, DevtoolScriptControlMsg, PAGE_ERROR, CONSOLE_API};
use msg::constellation_msg::PipelineId;
use collections::BTreeMap;
@ -34,46 +34,6 @@ struct StartedListenersReply {
traits: StartedListenersTraits,
}
#[derive(RustcEncodable)]
#[allow(dead_code)]
struct ConsoleAPIMessage {
_type: String, //FIXME: should this be __type__ instead?
}
#[derive(RustcEncodable)]
#[allow(dead_code)]
struct PageErrorMessage {
_type: String, //FIXME: should this be __type__ instead?
errorMessage: String,
sourceName: String,
lineText: String,
lineNumber: u32,
columnNumber: u32,
category: String,
timeStamp: u64,
warning: bool,
error: bool,
exception: bool,
strict: bool,
private: bool,
}
#[derive(RustcEncodable)]
#[allow(dead_code)]
struct LogMessage {
_type: String, //FIXME: should this be __type__ instead?
timeStamp: u64,
message: String,
}
#[derive(RustcEncodable)]
#[allow(dead_code)]
enum ConsoleMessageType {
ConsoleAPIType(ConsoleAPIMessage),
PageErrorType(PageErrorMessage),
LogMessageType(LogMessage),
}
#[derive(RustcEncodable)]
struct GetCachedMessagesReply {
from: String,
@ -123,54 +83,23 @@ impl Actor for ConsoleActor {
stream: &mut TcpStream) -> Result<bool, ()> {
Ok(match msg_type {
"getCachedMessages" => {
let types = msg.get(&"messageTypes".to_string()).unwrap().as_array().unwrap();
let /*mut*/ messages = vec!();
for msg_type in types.iter() {
let msg_type = msg_type.as_string().unwrap();
match &*msg_type {
"ConsoleAPI" => {
//TODO: figure out all consoleapi properties from FFOX source
}
"PageError" => {
//TODO: make script error reporter pass all reported errors
// to devtools and cache them for returning here.
/*let message = PageErrorMessage {
_type: msg_type.to_string(),
sourceName: "".to_string(),
lineText: "".to_string(),
lineNumber: 0,
columnNumber: 0,
category: "".to_string(),
warning: false,
error: true,
exception: false,
strict: false,
private: false,
timeStamp: 0,
errorMessage: "page error test".to_string(),
};
messages.push(
json::from_str(
json::encode(&message).as_slice()).unwrap().as_object().unwrap().clone());*/
}
"LogMessage" => {
//TODO: figure out when LogMessage is necessary
/*let message = LogMessage {
_type: msg_type.to_string(),
timeStamp: 0,
message: "log message test".to_string(),
};
messages.push(
json::from_str(
json::encode(&message).as_slice()).unwrap().as_object().unwrap().clone());*/
}
let str_types = msg.get("messageTypes").unwrap().as_array().unwrap().into_iter().map(|json_type| {
json_type.as_string().unwrap()
});
let mut message_types = CachedConsoleMessageTypes::empty();
for str_type in str_types {
match str_type {
"PageError" => message_types.insert(PAGE_ERROR),
"ConsoleAPI" => message_types.insert(CONSOLE_API),
s => println!("unrecognized message type requested: \"{}\"", s),
}
}
};
};
let (chan, port) = channel();
self.script_chan.send(DevtoolScriptControlMsg::GetCachedMessages(
self.pipeline, message_types, chan)).unwrap();
let messages = try!(port.recv().map_err(|_| ())).into_iter().map(|message| {
json::encode(&message).unwrap().to_json().as_object().unwrap().to_owned()
}).collect();
let msg = GetCachedMessagesReply {
from: self.name(),