mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
devtools: TabDescription actor
This commit is contained in:
parent
714acb942c
commit
da80d4ff01
6 changed files with 148 additions and 28 deletions
|
@ -159,7 +159,13 @@ impl ActorRegistry {
|
||||||
msg: &Map<String, Value>,
|
msg: &Map<String, Value>,
|
||||||
stream: &mut TcpStream,
|
stream: &mut TcpStream,
|
||||||
) -> Result<(), ()> {
|
) -> Result<(), ()> {
|
||||||
let to = msg.get("to").unwrap().as_str().unwrap();
|
let to = match msg.get("to") {
|
||||||
|
Some(to) => to.as_str().unwrap(),
|
||||||
|
None => {
|
||||||
|
warn!("Received unexpected message: {:?}", msg);
|
||||||
|
return Err(());
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
match self.actors.get(to) {
|
match self.actors.get(to) {
|
||||||
None => debug!("message received for unknown actor \"{}\"", to),
|
None => debug!("message received for unknown actor \"{}\"", to),
|
||||||
|
|
|
@ -12,8 +12,8 @@ use crate::actors::emulation::EmulationActor;
|
||||||
use crate::actors::inspector::InspectorActor;
|
use crate::actors::inspector::InspectorActor;
|
||||||
use crate::actors::performance::PerformanceActor;
|
use crate::actors::performance::PerformanceActor;
|
||||||
use crate::actors::profiler::ProfilerActor;
|
use crate::actors::profiler::ProfilerActor;
|
||||||
use crate::actors::root::RootActor;
|
|
||||||
use crate::actors::stylesheets::StyleSheetsActor;
|
use crate::actors::stylesheets::StyleSheetsActor;
|
||||||
|
use crate::actors::tab::TabDescriptorActor;
|
||||||
use crate::actors::thread::ThreadActor;
|
use crate::actors::thread::ThreadActor;
|
||||||
use crate::actors::timeline::TimelineActor;
|
use crate::actors::timeline::TimelineActor;
|
||||||
use crate::protocol::JsonPacketStream;
|
use crate::protocol::JsonPacketStream;
|
||||||
|
@ -130,6 +130,7 @@ pub struct BrowsingContextActor {
|
||||||
pub performance: String,
|
pub performance: String,
|
||||||
pub styleSheets: String,
|
pub styleSheets: String,
|
||||||
pub thread: String,
|
pub thread: String,
|
||||||
|
pub tab: String,
|
||||||
pub streams: RefCell<Vec<TcpStream>>,
|
pub streams: RefCell<Vec<TcpStream>>,
|
||||||
pub browsing_context_id: BrowsingContextId,
|
pub browsing_context_id: BrowsingContextId,
|
||||||
pub active_pipeline: Cell<PipelineId>,
|
pub active_pipeline: Cell<PipelineId>,
|
||||||
|
@ -266,6 +267,9 @@ impl BrowsingContextActor {
|
||||||
let thread = ThreadActor::new(actors.new_name("context"));
|
let thread = ThreadActor::new(actors.new_name("context"));
|
||||||
|
|
||||||
let DevtoolsPageInfo { title, url } = page_info;
|
let DevtoolsPageInfo { title, url } = page_info;
|
||||||
|
|
||||||
|
let tabdesc = TabDescriptorActor::new(actors, name.clone());
|
||||||
|
|
||||||
let target = BrowsingContextActor {
|
let target = BrowsingContextActor {
|
||||||
name: name,
|
name: name,
|
||||||
script_chan: script_sender,
|
script_chan: script_sender,
|
||||||
|
@ -278,6 +282,7 @@ impl BrowsingContextActor {
|
||||||
profiler: profiler.name(),
|
profiler: profiler.name(),
|
||||||
performance: performance.name(),
|
performance: performance.name(),
|
||||||
styleSheets: styleSheets.name(),
|
styleSheets: styleSheets.name(),
|
||||||
|
tab: tabdesc.name(),
|
||||||
thread: thread.name(),
|
thread: thread.name(),
|
||||||
streams: RefCell::new(Vec::new()),
|
streams: RefCell::new(Vec::new()),
|
||||||
browsing_context_id: id,
|
browsing_context_id: id,
|
||||||
|
@ -291,9 +296,8 @@ impl BrowsingContextActor {
|
||||||
actors.register(Box::new(performance));
|
actors.register(Box::new(performance));
|
||||||
actors.register(Box::new(styleSheets));
|
actors.register(Box::new(styleSheets));
|
||||||
actors.register(Box::new(thread));
|
actors.register(Box::new(thread));
|
||||||
|
actors.register(Box::new(tabdesc));
|
||||||
|
|
||||||
let root = actors.find_mut::<RootActor>("root");
|
|
||||||
root.tabs.push(target.name.clone());
|
|
||||||
target
|
target
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
/// Connection point for all new remote devtools interactions, providing lists of know actors
|
/// Connection point for all new remote devtools interactions, providing lists of know actors
|
||||||
/// that perform more specific actions (targets, addons, browser chrome, etc.)
|
/// that perform more specific actions (targets, addons, browser chrome, etc.)
|
||||||
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
|
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
|
||||||
use crate::actors::browsing_context::{BrowsingContextActor, BrowsingContextActorMsg};
|
|
||||||
use crate::actors::device::DeviceActor;
|
use crate::actors::device::DeviceActor;
|
||||||
use crate::actors::performance::PerformanceActor;
|
use crate::actors::performance::PerformanceActor;
|
||||||
|
use crate::actors::tab::{TabDescriptorActor, TabDescriptorActorMsg};
|
||||||
use crate::actors::worker::{WorkerActor, WorkerMsg};
|
use crate::actors::worker::{WorkerActor, WorkerMsg};
|
||||||
use crate::protocol::{ActorDescription, JsonPacketStream};
|
use crate::protocol::{ActorDescription, JsonPacketStream};
|
||||||
use serde_json::{Map, Value};
|
use serde_json::{Map, Value};
|
||||||
|
@ -45,13 +45,13 @@ struct GetRootReply {
|
||||||
struct ListTabsReply {
|
struct ListTabsReply {
|
||||||
from: String,
|
from: String,
|
||||||
selected: u32,
|
selected: u32,
|
||||||
tabs: Vec<BrowsingContextActorMsg>,
|
tabs: Vec<TabDescriptorActorMsg>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct GetTabReply {
|
struct GetTabReply {
|
||||||
from: String,
|
from: String,
|
||||||
tab: BrowsingContextActorMsg,
|
tab: TabDescriptorActorMsg,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
@ -181,7 +181,11 @@ impl Actor for RootActor {
|
||||||
tabs: self
|
tabs: self
|
||||||
.tabs
|
.tabs
|
||||||
.iter()
|
.iter()
|
||||||
.map(|target| registry.find::<BrowsingContextActor>(target).encodable())
|
.map(|target| {
|
||||||
|
registry
|
||||||
|
.find::<TabDescriptorActor>(target)
|
||||||
|
.encodable(®istry)
|
||||||
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
};
|
};
|
||||||
stream.write_json_packet(&actor);
|
stream.write_json_packet(&actor);
|
||||||
|
@ -211,10 +215,10 @@ impl Actor for RootActor {
|
||||||
},
|
},
|
||||||
|
|
||||||
"getTab" => {
|
"getTab" => {
|
||||||
let tab = registry.find::<BrowsingContextActor>(&self.tabs[0]);
|
let tab = registry.find::<TabDescriptorActor>(&self.tabs[0]);
|
||||||
let reply = GetTabReply {
|
let reply = GetTabReply {
|
||||||
from: self.name(),
|
from: self.name(),
|
||||||
tab: tab.encodable(),
|
tab: tab.encodable(®istry),
|
||||||
};
|
};
|
||||||
stream.write_json_packet(&reply);
|
stream.write_json_packet(&reply);
|
||||||
ActorMessageStatus::Processed
|
ActorMessageStatus::Processed
|
||||||
|
|
101
components/devtools/actors/tab.rs
Normal file
101
components/devtools/actors/tab.rs
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
/* 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 https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
|
||||||
|
use crate::actors::browsing_context::{BrowsingContextActor, BrowsingContextActorMsg};
|
||||||
|
use crate::actors::root::RootActor;
|
||||||
|
use crate::protocol::JsonPacketStream;
|
||||||
|
use serde_json::{Map, Value};
|
||||||
|
use std::net::TcpStream;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct TabDescriptorTraits {
|
||||||
|
getFavicon: bool,
|
||||||
|
hasTabInfo: bool,
|
||||||
|
watcher: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct TabDescriptorActorMsg {
|
||||||
|
actor: String,
|
||||||
|
title: String,
|
||||||
|
url: String,
|
||||||
|
outerWindowID: u32,
|
||||||
|
browsingContextId: u32,
|
||||||
|
traits: TabDescriptorTraits,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct GetTargetReply {
|
||||||
|
from: String,
|
||||||
|
frame: BrowsingContextActorMsg,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct TabDescriptorActor {
|
||||||
|
name: String,
|
||||||
|
browsing_context_actor: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Actor for TabDescriptorActor {
|
||||||
|
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 {
|
||||||
|
"getTarget" => {
|
||||||
|
let frame = registry
|
||||||
|
.find::<BrowsingContextActor>(&self.browsing_context_actor)
|
||||||
|
.encodable();
|
||||||
|
stream.write_json_packet(&GetTargetReply {
|
||||||
|
from: self.name(),
|
||||||
|
frame,
|
||||||
|
});
|
||||||
|
ActorMessageStatus::Processed
|
||||||
|
},
|
||||||
|
_ => ActorMessageStatus::Ignored,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TabDescriptorActor {
|
||||||
|
pub(crate) fn new(
|
||||||
|
actors: &mut ActorRegistry,
|
||||||
|
browsing_context_actor: String,
|
||||||
|
) -> TabDescriptorActor {
|
||||||
|
let name = actors.new_name("tabDescription");
|
||||||
|
let root = actors.find_mut::<RootActor>("root");
|
||||||
|
root.tabs.push(name.clone());
|
||||||
|
TabDescriptorActor {
|
||||||
|
name: name,
|
||||||
|
browsing_context_actor,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn encodable(&self, registry: &ActorRegistry) -> TabDescriptorActorMsg {
|
||||||
|
let ctx_actor = registry.find::<BrowsingContextActor>(&self.browsing_context_actor);
|
||||||
|
|
||||||
|
let title = ctx_actor.title.borrow().clone();
|
||||||
|
let url = ctx_actor.url.borrow().clone();
|
||||||
|
|
||||||
|
TabDescriptorActorMsg {
|
||||||
|
title,
|
||||||
|
url,
|
||||||
|
actor: self.name(),
|
||||||
|
browsingContextId: ctx_actor.browsing_context_id.index.0.get(),
|
||||||
|
outerWindowID: ctx_actor.active_pipeline.get().index.0.get(),
|
||||||
|
traits: TabDescriptorTraits {
|
||||||
|
getFavicon: false,
|
||||||
|
hasTabInfo: true,
|
||||||
|
watcher: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -66,6 +66,7 @@ mod actors {
|
||||||
pub mod profiler;
|
pub mod profiler;
|
||||||
pub mod root;
|
pub mod root;
|
||||||
pub mod stylesheets;
|
pub mod stylesheets;
|
||||||
|
pub mod tab;
|
||||||
pub mod thread;
|
pub mod thread;
|
||||||
pub mod timeline;
|
pub mod timeline;
|
||||||
pub mod worker;
|
pub mod worker;
|
||||||
|
|
|
@ -113,24 +113,11 @@ void DevtoolsClient::HandleMessage(JsonObject obj) {
|
||||||
} else if (obj.HasKey(L"tab")) {
|
} else if (obj.HasKey(L"tab")) {
|
||||||
// Got the current tab.
|
// Got the current tab.
|
||||||
auto tab = obj.GetNamedObject(L"tab");
|
auto tab = obj.GetNamedObject(L"tab");
|
||||||
if (tab.HasKey(L"actor")) {
|
JsonObject out;
|
||||||
// Attach to tab, and ask for cached messaged
|
out.Insert(L"to", tab.GetNamedValue(L"actor"));
|
||||||
JsonObject msg1;
|
out.Insert(L"type", JsonValue::CreateStringValue(L"getTarget"));
|
||||||
mConsoleActor = tab.GetNamedValue(L"consoleActor");
|
Send(out);
|
||||||
msg1.Insert(L"to", tab.GetNamedValue(L"actor"));
|
return;
|
||||||
msg1.Insert(L"type", JsonValue::CreateStringValue(L"attach"));
|
|
||||||
Send(msg1);
|
|
||||||
JsonObject msg2;
|
|
||||||
msg2.Insert(L"to", *mConsoleActor);
|
|
||||||
msg2.Insert(L"type",
|
|
||||||
JsonValue::CreateStringValue(L"getCachedMessages"));
|
|
||||||
JsonArray types;
|
|
||||||
types.Append(JsonValue::CreateStringValue(L"PageError"));
|
|
||||||
types.Append(JsonValue::CreateStringValue(L"ConsoleAPI"));
|
|
||||||
msg2.Insert(L"messageTypes", types);
|
|
||||||
Send(msg2);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (obj.HasKey(L"resultID")) {
|
} else if (obj.HasKey(L"resultID")) {
|
||||||
// evaluateJSAsync response.
|
// evaluateJSAsync response.
|
||||||
|
@ -163,6 +150,23 @@ void DevtoolsClient::HandleMessage(JsonObject obj) {
|
||||||
// FIXME: log if there is a non-200 HTTP response
|
// FIXME: log if there is a non-200 HTTP response
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else if (obj.HasKey(L"frame")) {
|
||||||
|
auto frame = obj.GetNamedObject(L"frame");
|
||||||
|
// Attach to tab, and ask for cached messaged
|
||||||
|
JsonObject msg1;
|
||||||
|
mConsoleActor = frame.GetNamedValue(L"consoleActor");
|
||||||
|
msg1.Insert(L"to", frame.GetNamedValue(L"actor"));
|
||||||
|
msg1.Insert(L"type", JsonValue::CreateStringValue(L"attach"));
|
||||||
|
Send(msg1);
|
||||||
|
JsonObject msg2;
|
||||||
|
msg2.Insert(L"to", *mConsoleActor);
|
||||||
|
msg2.Insert(L"type", JsonValue::CreateStringValue(L"getCachedMessages"));
|
||||||
|
JsonArray types;
|
||||||
|
types.Append(JsonValue::CreateStringValue(L"PageError"));
|
||||||
|
types.Append(JsonValue::CreateStringValue(L"ConsoleAPI"));
|
||||||
|
msg2.Insert(L"messageTypes", types);
|
||||||
|
Send(msg2);
|
||||||
|
return;
|
||||||
} else if (obj.HasKey(L"messages")) {
|
} else if (obj.HasKey(L"messages")) {
|
||||||
// Response to getCachedMessages
|
// Response to getCachedMessages
|
||||||
for (auto messageValue : obj.GetNamedArray(L"messages")) {
|
for (auto messageValue : obj.GetNamedArray(L"messages")) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue