Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M1453: Review for GetCachedMessages #4175

Closed
wants to merge 9 commits into from
Prev

Implemented GetCachedMessages functionality

  • Loading branch information
sam0rai9 committed Dec 2, 2014
commit 7545938de90307e1e10317e0de7386a26ae503f3
@@ -9,8 +9,8 @@
use actor::{Actor, ActorRegistry};
use protocol::JsonPacketSender;

use devtools_traits::{EvaluateJS, NullValue, VoidValue, NumberValue, StringValue, BooleanValue};
use devtools_traits::{ActorValue, DevtoolScriptControlMsg};
use devtools_traits::{EvaluateJS, NullValue, VoidValue, NumberValue, StringValue, BooleanValue, GetCachedMessages};
use devtools_traits::{ActorValue, DevtoolScriptControlMsg, CachedMessageType};
use servo_msg::constellation_msg::PipelineId;

use collections::TreeMap;
@@ -71,7 +71,7 @@ enum ConsoleMessageType {
#[deriving(Encodable)]
struct GetCachedMessagesReply {
from: String,
messages: Vec<json::JsonObject>,
messages: Vec<CachedMessageType>,
}

#[deriving(Encodable)]
@@ -98,6 +98,11 @@ struct EvaluateJSReply {
helperResult: json::Json,
}

#[deriving(Encodable)]
struct CachedMessage {
pub messageType: String,
}

pub struct ConsoleActor {
pub name: String,
pub pipeline: PipelineId,
@@ -118,7 +123,14 @@ impl Actor for ConsoleActor {
match msg_type.as_slice() {
"getCachedMessages" => {
let types = msg.find(&"messageTypes".to_string()).unwrap().as_list().unwrap();
let /*mut*/ messages = vec!();
let (chan, port) = channel();
let mut cachedmsg: Vec<String> = Vec::new();
for json_mod in types.iter() {
let message: String = json::decode(json_mod.to_string().as_slice()).unwrap();
cachedmsg.push(message);
}
self.script_chan.send(GetCachedMessages(cachedmsg , chan));
let cachedReply = port.recv();
for msg_type in types.iter() {
let msg_type = msg_type.as_string().unwrap();
match msg_type.as_slice() {
@@ -164,7 +176,7 @@ impl Actor for ConsoleActor {

let msg = GetCachedMessagesReply {
from: self.name(),
messages: messages,
messages: cachedReply,
};
stream.write_json_packet(&msg);
true
@@ -75,6 +75,7 @@ pub enum DevtoolScriptControlMsg {
GetChildren(PipelineId, String, Sender<Vec<NodeInfo>>),
GetLayout(PipelineId, String, Sender<(f32, f32)>),
ModifyAttribute(PipelineId, String, Vec<Modification>),
GetCachedMessages(Vec<String>, Sender<Vec<CachedMessageType>>)
}

/// Messages to instruct devtools server to update its state relating to a particular
@@ -103,3 +104,25 @@ impl<D:Decoder<E>, E> Decodable<D, E> for Modification {
)
}
}

#[deriving(Encodable)]
pub struct ConsoleAPIMessage {
_type: String,
}

#[deriving(Encodable)]
pub struct PageErrorMessage {
_type: String,
}

#[deriving(Encodable)]
pub struct LogMessage {
_type: String,
}

#[deriving(Encodable)]
pub enum CachedMessageType {
ConsoleAPIType(ConsoleAPIMessage),
PageErrorType(PageErrorMessage),
LogMessageType(LogMessage),
}
@@ -37,7 +37,7 @@ use timers::TimerId;
use devtools_traits;
use devtools_traits::{DevtoolsControlChan, DevtoolsControlPort, NewGlobal, NodeInfo, GetRootNode};
use devtools_traits::{DevtoolScriptControlMsg, EvaluateJS, EvaluateJSReply, GetDocumentElement};
use devtools_traits::{GetChildren, GetLayout, ModifyAttribute};
use devtools_traits::{GetChildren, GetLayout, ModifyAttribute, GetCachedMessages, CachedMessageType};
use devtools_traits::Modification;
use script_traits::{CompositorEvent, ResizeEvent, ReflowEvent, ClickEvent, MouseDownEvent};
use script_traits::{MouseMoveEvent, MouseUpEvent, ConstellationControlMsg, ScriptTaskFactory};
@@ -544,6 +544,7 @@ impl ScriptTask {
FromDevtools(GetChildren(id, node_id, reply)) => self.handle_get_children(id, node_id, reply),
FromDevtools(GetLayout(id, node_id, reply)) => self.handle_get_layout(id, node_id, reply),
FromDevtools(ModifyAttribute(id, node_id, modifications)) => self.handle_modify_attribute(id, node_id, modifications),
FromDevtools(GetCachedMessages(message_types, reply)) => self.handle_get_cached_messages(message_types, reply),
}
}

@@ -639,6 +640,14 @@ impl ScriptTask {
}
}

fn handle_get_cached_messages(&self, _message_types: Vec<String>, reply: Sender<Vec<CachedMessageType>>) {
//TODO: check the messageTypes against a global Cache for console messages and page exceptions
let messages: Vec<CachedMessageType> = Vec::new();
//For each string in _message_types, search for the corresponding struct in the enum.
//Include the corresponding messages in the vector messages. Send messages.
reply.send(messages);
}

fn handle_new_layout(&self, new_layout_info: NewLayoutInfo) {
debug!("Script: new layout: {:?}", new_layout_info);
let NewLayoutInfo {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.