servo: Merge #11094 - Start implementing protocolDescription and canCurrentlyRecord in devtools (from nox:devtools); r=Ms2ger
authorAnthony Ramine <n.oxyde@gmail.com>
Mon, 30 May 2016 13:00:57 -0500
changeset 338960 beef64b4377f415066a2cc6fef5bb6064f86aefb
parent 338959 4eeef4cbe15da562cad672bd7d2f8ae9572f90fe
child 338961 0172182861f7a44e60979ba5bf949c9579d38e22
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMs2ger
servo: Merge #11094 - Start implementing protocolDescription and canCurrentlyRecord in devtools (from nox:devtools); r=Ms2ger We can merge it but it doesn't make things work more than before. Mostly filing it for comments, especially the `description` method. If you feel it's too verbose I guess the way to go would be to properly formalise all types involved in the devtools server, but that's going to be a gigantic task. Source-Repo: https://github.com/servo/servo Source-Revision: 4a016599835ec22738dec700750a361fdeaf3507
servo/components/devtools/actors/performance.rs
servo/components/devtools/actors/root.rs
servo/components/devtools/actors/thread.rs
servo/components/devtools/protocol.rs
--- a/servo/components/devtools/actors/performance.rs
+++ b/servo/components/devtools/actors/performance.rs
@@ -1,14 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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 actor::{Actor, ActorMessageStatus, ActorRegistry};
-use protocol::JsonPacketStream;
+use protocol::{ActorDescription, JsonPacketStream, Method};
 use serde_json::Value;
 use std::collections::BTreeMap;
 use std::net::TcpStream;
 
 pub struct PerformanceActor {
     name: String,
 }
 
@@ -27,16 +27,31 @@ struct PerformanceTraits {
 }
 
 #[derive(Serialize)]
 struct ConnectReply {
     from: String,
     traits: PerformanceTraits,
 }
 
+#[derive(Serialize)]
+struct CanCurrentlyRecordReply {
+    from: String,
+    value: SuccessMsg,
+}
+
+#[derive(Serialize)]
+struct SuccessMsg {
+    success: bool,
+    errors: Vec<Error>,
+}
+
+#[derive(Serialize)]
+enum Error {}
+
 impl Actor for PerformanceActor {
     fn name(&self) -> String {
         self.name.clone()
     }
 
     fn handle_message(&self,
                       _registry: &ActorRegistry,
                       msg_type: &str,
@@ -54,20 +69,51 @@ impl Actor for PerformanceActor {
                             withAllocations: true,
                             withJITOptimizations: true,
                         },
                     },
                 };
                 stream.write_json_packet(&msg);
                 ActorMessageStatus::Processed
             },
+            "canCurrentlyRecord" => {
+                let msg = CanCurrentlyRecordReply {
+                    from: self.name(),
+                    value: SuccessMsg {
+                        success: true,
+                        errors: vec![],
+                    }
+                };
+                stream.write_json_packet(&msg);
+                ActorMessageStatus::Processed
+            }
             _ => ActorMessageStatus::Ignored,
         })
     }
 }
 
 impl PerformanceActor {
     pub fn new(name: String) -> PerformanceActor {
         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()),
+                },
+            ],
+        }
+    }
 }
--- a/servo/components/devtools/actors/root.rs
+++ b/servo/components/devtools/actors/root.rs
@@ -3,18 +3,19 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /// Liberally derived from the [Firefox JS implementation]
 /// (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};
-use protocol::JsonPacketStream;
+use protocol::{ActorDescription, JsonPacketStream};
 use serde_json::Value;
 use std::collections::BTreeMap;
 use std::net::TcpStream;
 
 #[derive(Serialize)]
 struct ActorTraits {
     sources: bool,
     highlightable: bool,
@@ -39,16 +40,27 @@ struct ListTabsReply {
 
 #[derive(Serialize)]
 pub struct RootActorMsg {
     from: String,
     applicationType: String,
     traits: ActorTraits,
 }
 
+#[derive(Serialize)]
+pub struct ProtocolDescriptionReply {
+    from: String,
+    types: Types,
+}
+
+#[derive(Serialize)]
+pub struct Types {
+    performance: ActorDescription,
+}
+
 pub struct RootActor {
     pub tabs: Vec<String>,
 }
 
 impl Actor for RootActor {
     fn name(&self) -> String {
         "root".to_owned()
     }
@@ -76,16 +88,27 @@ impl Actor for RootActor {
                     tabs: self.tabs.iter().map(|tab| {
                         registry.find::<TabActor>(tab).encodable()
                     }).collect()
                 };
                 stream.write_json_packet(&actor);
                 ActorMessageStatus::Processed
             }
 
+            "protocolDescription" => {
+                let msg = ProtocolDescriptionReply {
+                    from: self.name(),
+                    types: Types {
+                        performance: PerformanceActor::description(),
+                    },
+                };
+                stream.write_json_packet(&msg);
+                ActorMessageStatus::Processed
+            }
+
             _ => ActorMessageStatus::Ignored
         })
     }
 }
 
 impl RootActor {
     pub fn encodable(&self) -> RootActorMsg {
         RootActorMsg {
--- a/servo/components/devtools/actors/thread.rs
+++ b/servo/components/devtools/actors/thread.rs
@@ -34,16 +34,25 @@ struct ThreadResumedReply {
     type_: String,
 }
 
 #[derive(Serialize)]
 struct ReconfigureReply {
     from: String
 }
 
+#[derive(Serialize)]
+struct SourcesReply {
+    from: String,
+    sources: Vec<Source>,
+}
+
+#[derive(Serialize)]
+enum Source {}
+
 pub struct ThreadActor {
     name: String,
 }
 
 impl ThreadActor {
     pub fn new(name: String) -> ThreadActor {
         ThreadActor {
             name: name,
@@ -83,12 +92,21 @@ impl Actor for ThreadActor {
                 ActorMessageStatus::Processed
             },
 
             "reconfigure" => {
                 stream.write_json_packet(&ReconfigureReply { from: self.name() });
                 ActorMessageStatus::Processed
             }
 
+            "sources" => {
+                let msg = SourcesReply {
+                    from: self.name(),
+                    sources: vec![],
+                };
+                stream.write_json_packet(&msg);
+                ActorMessageStatus::Processed
+            }
+
             _ => ActorMessageStatus::Ignored,
         })
     }
 }
--- a/servo/components/devtools/protocol.rs
+++ b/servo/components/devtools/protocol.rs
@@ -7,16 +7,30 @@
 //! (https://wiki.mozilla.org/Remote_Debugging_Protocol_Stream_Transport#JSON_Packets).
 
 use serde::Serialize;
 use serde_json::{self, Value};
 use std::error::Error;
 use std::io::{Read, Write};
 use std::net::TcpStream;
 
+#[derive(Serialize)]
+pub struct ActorDescription {
+    pub category: &'static str,
+    pub typeName: &'static str,
+    pub methods: Vec<Method>,
+}
+
+#[derive(Serialize)]
+pub struct Method {
+    pub name: &'static str,
+    pub request: Value,
+    pub response: Value,
+}
+
 pub trait JsonPacketStream {
     fn write_json_packet<T: Serialize>(&mut self, obj: &T);
     fn read_json_packet(&mut self) -> Result<Option<Value>, String>;
 }
 
 impl JsonPacketStream for TcpStream {
     fn write_json_packet<T: Serialize>(&mut self, obj: &T) {
         let s = serde_json::to_string(obj).unwrap();