mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
DevTools - add DeviceActor and update Root to own global actors
This commit is contained in:
parent
cdd7f0a658
commit
5c8492d760
3 changed files with 123 additions and 1 deletions
86
components/devtools/actors/device.rs
Normal file
86
components/devtools/actors/device.rs
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
/* 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 serde_json::{Map, Value};
|
||||||
|
use std::net::TcpStream;
|
||||||
|
use protocol::{ActorDescription, Method};
|
||||||
|
use protocol::JsonPacketStream;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct GetDescriptionReply {
|
||||||
|
from: String,
|
||||||
|
value: SystemInfo,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct SystemInfo {
|
||||||
|
apptype: String,
|
||||||
|
platformVersion: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct DeviceActor {
|
||||||
|
pub name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Actor for DeviceActor {
|
||||||
|
fn name(&self) -> String {
|
||||||
|
self.name.clone()
|
||||||
|
}
|
||||||
|
fn handle_message(
|
||||||
|
&self,
|
||||||
|
_registry: &ActorRegistry,
|
||||||
|
msg_type: &str,
|
||||||
|
_msg: &Map<String, Value>,
|
||||||
|
stream: &mut TcpStream,
|
||||||
|
) -> Result<ActorMessageStatus, ()> {
|
||||||
|
|
||||||
|
Ok(match msg_type {
|
||||||
|
"getDescription" => {
|
||||||
|
|
||||||
|
let msg = GetDescriptionReply {
|
||||||
|
from: self.name(),
|
||||||
|
value: SystemInfo {
|
||||||
|
apptype: "servo".to_string(),
|
||||||
|
platformVersion: "63.0".to_string(),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
stream.write_json_packet(&msg);
|
||||||
|
ActorMessageStatus::Processed
|
||||||
|
},
|
||||||
|
|
||||||
|
_ => ActorMessageStatus::Ignored,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DeviceActor {
|
||||||
|
pub fn new(name: String) -> DeviceActor {
|
||||||
|
DeviceActor { name: name }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn description() -> ActorDescription {
|
||||||
|
ActorDescription {
|
||||||
|
category: "actor",
|
||||||
|
typeName: "device",
|
||||||
|
methods: vec![Method {
|
||||||
|
name: "getDescription",
|
||||||
|
request: Value::Null,
|
||||||
|
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,6 +8,7 @@
|
||||||
/// that perform more specific actions (targets, addons, browser chrome, etc.)
|
/// that perform more specific actions (targets, addons, browser chrome, etc.)
|
||||||
use actor::{Actor, ActorMessageStatus, ActorRegistry};
|
use actor::{Actor, ActorMessageStatus, ActorRegistry};
|
||||||
use actors::browsing_context::{BrowsingContextActor, BrowsingContextActorMsg};
|
use actors::browsing_context::{BrowsingContextActor, BrowsingContextActorMsg};
|
||||||
|
use actors::device::DeviceActor;
|
||||||
use actors::performance::PerformanceActor;
|
use actors::performance::PerformanceActor;
|
||||||
use protocol::{ActorDescription, JsonPacketStream};
|
use protocol::{ActorDescription, JsonPacketStream};
|
||||||
use serde_json::{Map, Value};
|
use serde_json::{Map, Value};
|
||||||
|
@ -30,6 +31,14 @@ struct ListAddonsReply {
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
enum AddonMsg {}
|
enum AddonMsg {}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct GetRootReply {
|
||||||
|
from: String,
|
||||||
|
selected: u32,
|
||||||
|
performanceActor: String,
|
||||||
|
deviceActor: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct ListTabsReply {
|
struct ListTabsReply {
|
||||||
from: String,
|
from: String,
|
||||||
|
@ -53,10 +62,13 @@ pub struct ProtocolDescriptionReply {
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct Types {
|
pub struct Types {
|
||||||
performance: ActorDescription,
|
performance: ActorDescription,
|
||||||
|
device: ActorDescription,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct RootActor {
|
pub struct RootActor {
|
||||||
pub tabs: Vec<String>,
|
pub tabs: Vec<String>,
|
||||||
|
pub performance: String,
|
||||||
|
pub device: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Actor for RootActor {
|
impl Actor for RootActor {
|
||||||
|
@ -81,6 +93,17 @@ impl Actor for RootActor {
|
||||||
ActorMessageStatus::Processed
|
ActorMessageStatus::Processed
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"getRoot" => {
|
||||||
|
let actor = GetRootReply {
|
||||||
|
from: "root".to_owned(),
|
||||||
|
selected: 0,
|
||||||
|
performanceActor: self.performance.clone(),
|
||||||
|
deviceActor: self.device.clone(),
|
||||||
|
};
|
||||||
|
stream.write_json_packet(&actor);
|
||||||
|
ActorMessageStatus::Processed
|
||||||
|
},
|
||||||
|
|
||||||
// https://docs.firefox-dev.tools/backend/protocol.html#listing-browser-tabs
|
// https://docs.firefox-dev.tools/backend/protocol.html#listing-browser-tabs
|
||||||
"listTabs" => {
|
"listTabs" => {
|
||||||
let actor = ListTabsReply {
|
let actor = ListTabsReply {
|
||||||
|
@ -101,6 +124,7 @@ impl Actor for RootActor {
|
||||||
from: self.name(),
|
from: self.name(),
|
||||||
types: Types {
|
types: Types {
|
||||||
performance: PerformanceActor::description(),
|
performance: PerformanceActor::description(),
|
||||||
|
device: DeviceActor::description(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
stream.write_json_packet(&msg);
|
stream.write_json_packet(&msg);
|
||||||
|
|
|
@ -27,6 +27,7 @@ extern crate time;
|
||||||
use actor::{Actor, ActorRegistry};
|
use actor::{Actor, ActorRegistry};
|
||||||
use actors::browsing_context::BrowsingContextActor;
|
use actors::browsing_context::BrowsingContextActor;
|
||||||
use actors::console::ConsoleActor;
|
use actors::console::ConsoleActor;
|
||||||
|
use actors::device::DeviceActor;
|
||||||
use actors::framerate::FramerateActor;
|
use actors::framerate::FramerateActor;
|
||||||
use actors::inspector::InspectorActor;
|
use actors::inspector::InspectorActor;
|
||||||
use actors::network_event::{EventActor, NetworkEventActor, ResponseStartMsg};
|
use actors::network_event::{EventActor, NetworkEventActor, ResponseStartMsg};
|
||||||
|
@ -57,6 +58,7 @@ mod actor;
|
||||||
mod actors {
|
mod actors {
|
||||||
pub mod browsing_context;
|
pub mod browsing_context;
|
||||||
pub mod console;
|
pub mod console;
|
||||||
|
pub mod device;
|
||||||
pub mod framerate;
|
pub mod framerate;
|
||||||
pub mod inspector;
|
pub mod inspector;
|
||||||
pub mod memory;
|
pub mod memory;
|
||||||
|
@ -146,9 +148,19 @@ fn run_server(
|
||||||
|
|
||||||
let mut registry = ActorRegistry::new();
|
let mut registry = ActorRegistry::new();
|
||||||
|
|
||||||
let root = Box::new(RootActor { tabs: vec![] });
|
let performance = PerformanceActor::new(registry.new_name("performance"));
|
||||||
|
|
||||||
|
let device = DeviceActor::new(registry.new_name("device"));
|
||||||
|
|
||||||
|
let root = Box::new(RootActor {
|
||||||
|
tabs: vec![],
|
||||||
|
device: device.name(),
|
||||||
|
performance: performance.name(),
|
||||||
|
});
|
||||||
|
|
||||||
registry.register(root);
|
registry.register(root);
|
||||||
|
registry.register(Box::new(performance));
|
||||||
|
registry.register(Box::new(device));
|
||||||
registry.find::<RootActor>("root");
|
registry.find::<RootActor>("root");
|
||||||
|
|
||||||
let actors = registry.create_shareable();
|
let actors = registry.create_shareable();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue