diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-05-26 10:34:03 -0500 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-05-26 10:34:03 -0500 |
commit | 8759d42559bc5c10f8d90903f33f75bddf44d9fe (patch) | |
tree | 808d6b11c7d2de44f31a888932c206bcedf26081 | |
parent | 7d0409b8421e1b0c055507acc7d784cac890f47e (diff) | |
parent | b5f74eb54cc4bb4cccc2f7cad8a358078eb591b6 (diff) | |
download | servo-8759d42559bc5c10f8d90903f33f75bddf44d9fe.tar.gz servo-8759d42559bc5c10f8d90903f33f75bddf44d9fe.zip |
Auto merge of #6168 - tamird:get-cached-messages, r=jdm
Rebase of #4175, closes #4175. r? @jdm
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6168)
<!-- Reviewable:end -->
-rw-r--r-- | components/devtools/actors/console.rs | 105 | ||||
-rw-r--r-- | components/devtools_traits/Cargo.toml | 1 | ||||
-rw-r--r-- | components/devtools_traits/lib.rs | 40 | ||||
-rw-r--r-- | components/script/devtools.rs | 41 | ||||
-rw-r--r-- | components/script/script_task.rs | 2 | ||||
-rw-r--r-- | components/servo/Cargo.lock | 1 |
6 files changed, 102 insertions, 88 deletions
diff --git a/components/devtools/actors/console.rs b/components/devtools/actors/console.rs index 1e0623d1061..5b83f6bc544 100644 --- a/components/devtools/actors/console.rs +++ b/components/devtools/actors/console.rs @@ -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; @@ -35,46 +35,6 @@ struct StartedListenersReply { } #[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, messages: Vec<json::Object>, @@ -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(), diff --git a/components/devtools_traits/Cargo.toml b/components/devtools_traits/Cargo.toml index 8f4a4a8ba17..f787628d153 100644 --- a/components/devtools_traits/Cargo.toml +++ b/components/devtools_traits/Cargo.toml @@ -18,3 +18,4 @@ time = "*" rustc-serialize = "0.3" url = "*" hyper = "0.4" +bitflags = "*" diff --git a/components/devtools_traits/lib.rs b/components/devtools_traits/lib.rs index 22f22e82836..f0a2d19dcb1 100644 --- a/components/devtools_traits/lib.rs +++ b/components/devtools_traits/lib.rs @@ -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>>), diff --git a/components/script/devtools.rs b/components/script/devtools.rs index cd093616207..f14e19999a5 100644 --- a/components/script/devtools.rs +++ b/components/script/devtools.rs @@ -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, diff --git a/components/script/script_task.rs b/components/script/script_task.rs index 7df8bef26aa..cc67e9a4993 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -801,6 +801,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) => diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 5928aa440b5..77e0e2d8cb0 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -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)", |