mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Implemented GetCachedMessages
This commit is contained in:
parent
be6c251e4c
commit
b5f74eb54c
6 changed files with 102 additions and 88 deletions
|
@ -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(),
|
||||
|
|
|
@ -18,3 +18,4 @@ time = "*"
|
|||
rustc-serialize = "0.3"
|
||||
url = "*"
|
||||
hyper = "0.4"
|
||||
bitflags = "*"
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate bitflags;
|
||||
|
||||
extern crate msg;
|
||||
extern crate rustc_serialize;
|
||||
extern crate url;
|
||||
|
@ -118,6 +121,7 @@ pub enum DevtoolScriptControlMsg {
|
|||
GetDocumentElement(PipelineId, Sender<NodeInfo>),
|
||||
GetChildren(PipelineId, String, Sender<Vec<NodeInfo>>),
|
||||
GetLayout(PipelineId, String, Sender<(f32, f32)>),
|
||||
GetCachedMessages(PipelineId, CachedConsoleMessageTypes, Sender<Vec<CachedConsoleMessage>>),
|
||||
ModifyAttribute(PipelineId, String, Vec<Modification>),
|
||||
WantsLiveNotifications(PipelineId, bool),
|
||||
SetTimelineMarkers(PipelineId, Vec<TimelineMarkerType>, Sender<TimelineMarker>),
|
||||
|
@ -156,6 +160,42 @@ pub enum ConsoleMessage {
|
|||
},
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
flags CachedConsoleMessageTypes: u8 {
|
||||
const PAGE_ERROR = 1 << 0,
|
||||
const CONSOLE_API = 1 << 1,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(RustcEncodable)]
|
||||
pub enum CachedConsoleMessage {
|
||||
PageError {
|
||||
__type__: String,
|
||||
errorMessage: String,
|
||||
sourceName: String,
|
||||
lineText: String,
|
||||
lineNumber: u32,
|
||||
columnNumber: u32,
|
||||
category: String,
|
||||
timeStamp: u64,
|
||||
error: bool,
|
||||
warning: bool,
|
||||
exception: bool,
|
||||
strict: bool,
|
||||
private: bool,
|
||||
},
|
||||
ConsoleAPI {
|
||||
__type__: String,
|
||||
level: String,
|
||||
filename: String,
|
||||
lineNumber: u32,
|
||||
functionName: String,
|
||||
timeStamp: u64,
|
||||
private: bool,
|
||||
arguments: Vec<String>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum NetworkEvent {
|
||||
HttpRequest(Url, Method, Headers, Option<Vec<u8>>),
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use devtools_traits::{CachedConsoleMessage, CachedConsoleMessageTypes, PAGE_ERROR, CONSOLE_API};
|
||||
use devtools_traits::{EvaluateJSReply, NodeInfo, Modification, TimelineMarker, TimelineMarkerType};
|
||||
use dom::bindings::conversions::FromJSValConvertible;
|
||||
use dom::bindings::conversions::StringificationBehavior;
|
||||
|
@ -96,6 +97,46 @@ pub fn handle_get_layout(page: &Rc<Page>, pipeline: PipelineId, node_id: String,
|
|||
reply.send((width, height)).unwrap();
|
||||
}
|
||||
|
||||
pub fn handle_get_cached_messages(_pipeline_id: PipelineId,
|
||||
message_types: CachedConsoleMessageTypes,
|
||||
reply: Sender<Vec<CachedConsoleMessage>>) {
|
||||
//TODO: check the messageTypes against a global Cache for console messages and page exceptions
|
||||
let mut messages = Vec::new();
|
||||
if message_types.contains(PAGE_ERROR) {
|
||||
//TODO: do for real
|
||||
messages.push(CachedConsoleMessage::ConsoleAPI {
|
||||
__type__: "consoleAPICall".to_owned(),
|
||||
level: "error".to_owned(),
|
||||
filename: "http://localhost/~mihai/mozilla/test.html".to_owned(),
|
||||
lineNumber: 0,
|
||||
functionName: String::new(),
|
||||
timeStamp: 0,
|
||||
private: false,
|
||||
arguments: Vec::new(),
|
||||
})
|
||||
}
|
||||
if message_types.contains(CONSOLE_API) {
|
||||
//TODO: make script error reporter pass all reported errors
|
||||
// to devtools and cache them for returning here.
|
||||
messages.push(CachedConsoleMessage::PageError {
|
||||
__type__: "pageError".to_owned(),
|
||||
errorMessage: "page error test".to_owned(),
|
||||
sourceName: String::new(),
|
||||
lineText: String::new(),
|
||||
lineNumber: 0,
|
||||
columnNumber: 0,
|
||||
category: String::new(),
|
||||
timeStamp: 0,
|
||||
error: false,
|
||||
warning: false,
|
||||
exception: false,
|
||||
strict: false,
|
||||
private: false,
|
||||
})
|
||||
}
|
||||
reply.send(messages).unwrap();
|
||||
}
|
||||
|
||||
pub fn handle_modify_attribute(page: &Rc<Page>,
|
||||
pipeline: PipelineId,
|
||||
node_id: String,
|
||||
|
|
|
@ -800,6 +800,8 @@ impl ScriptTask {
|
|||
devtools::handle_get_children(&page, id, node_id, reply),
|
||||
DevtoolScriptControlMsg::GetLayout(id, node_id, reply) =>
|
||||
devtools::handle_get_layout(&page, id, node_id, reply),
|
||||
DevtoolScriptControlMsg::GetCachedMessages(pipeline_id, message_types, reply) =>
|
||||
devtools::handle_get_cached_messages(pipeline_id, message_types, reply),
|
||||
DevtoolScriptControlMsg::ModifyAttribute(id, node_id, modifications) =>
|
||||
devtools::handle_modify_attribute(&page, id, node_id, modifications),
|
||||
DevtoolScriptControlMsg::WantsLiveNotifications(pipeline_id, to_send) =>
|
||||
|
|
1
components/servo/Cargo.lock
generated
1
components/servo/Cargo.lock
generated
|
@ -216,6 +216,7 @@ dependencies = [
|
|||
name = "devtools_traits"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hyper 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"msg 0.0.1",
|
||||
"rustc-serialize 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue