зеркало из https://github.com/mozilla/gecko-dev.git
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
This commit is contained in:
Родитель
b4d017565f
Коммит
f17345da93
|
@ -3,7 +3,7 @@
|
|||
* 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;
|
||||
|
@ -32,6 +32,21 @@ struct ConnectReply {
|
|||
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()
|
||||
|
@ -59,6 +74,17 @@ impl Actor for PerformanceActor {
|
|||
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,
|
||||
})
|
||||
}
|
||||
|
@ -70,4 +96,24 @@ impl 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()),
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,9 @@
|
|||
/// 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;
|
||||
|
@ -44,6 +45,17 @@ pub struct RootActorMsg {
|
|||
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>,
|
||||
}
|
||||
|
@ -81,6 +93,17 @@ impl Actor for RootActor {
|
|||
ActorMessageStatus::Processed
|
||||
}
|
||||
|
||||
"protocolDescription" => {
|
||||
let msg = ProtocolDescriptionReply {
|
||||
from: self.name(),
|
||||
types: Types {
|
||||
performance: PerformanceActor::description(),
|
||||
},
|
||||
};
|
||||
stream.write_json_packet(&msg);
|
||||
ActorMessageStatus::Processed
|
||||
}
|
||||
|
||||
_ => ActorMessageStatus::Ignored
|
||||
})
|
||||
}
|
||||
|
|
|
@ -39,6 +39,15 @@ struct ReconfigureReply {
|
|||
from: String
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct SourcesReply {
|
||||
from: String,
|
||||
sources: Vec<Source>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
enum Source {}
|
||||
|
||||
pub struct ThreadActor {
|
||||
name: String,
|
||||
}
|
||||
|
@ -88,6 +97,15 @@ impl Actor for ThreadActor {
|
|||
ActorMessageStatus::Processed
|
||||
}
|
||||
|
||||
"sources" => {
|
||||
let msg = SourcesReply {
|
||||
from: self.name(),
|
||||
sources: vec![],
|
||||
};
|
||||
stream.write_json_packet(&msg);
|
||||
ActorMessageStatus::Processed
|
||||
}
|
||||
|
||||
_ => ActorMessageStatus::Ignored,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -12,6 +12,20 @@ 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>;
|
||||
|
|
Загрузка…
Ссылка в новой задаче