diff options
author | Josh Matthews <josh@joshmatthews.net> | 2020-04-26 17:34:52 -0400 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2020-04-28 11:07:45 -0400 |
commit | 565e9432c61d8f57db32f2376c2ccff82e9798a8 (patch) | |
tree | 8835d9f80aec38c07fc0cda2db0bb5b0a6cf1caa /components/devtools/lib.rs | |
parent | bce4ec5b70f98c98a996b05767dfa7c1915fa0ce (diff) | |
download | servo-565e9432c61d8f57db32f2376c2ccff82e9798a8.tar.gz servo-565e9432c61d8f57db32f2376c2ccff82e9798a8.zip |
Support connecting to worker globals from remote devtools.
Diffstat (limited to 'components/devtools/lib.rs')
-rw-r--r-- | components/devtools/lib.rs | 123 |
1 files changed, 73 insertions, 50 deletions
diff --git a/components/devtools/lib.rs b/components/devtools/lib.rs index 6d9bd938e14..477e44494ee 100644 --- a/components/devtools/lib.rs +++ b/components/devtools/lib.rs @@ -19,7 +19,7 @@ extern crate serde; use crate::actor::{Actor, ActorRegistry}; use crate::actors::browsing_context::BrowsingContextActor; -use crate::actors::console::ConsoleActor; +use crate::actors::console::{ConsoleActor, Root}; use crate::actors::device::DeviceActor; use crate::actors::framerate::FramerateActor; use crate::actors::network_event::{EventActor, NetworkEventActor, ResponseStartMsg}; @@ -27,7 +27,8 @@ use crate::actors::performance::PerformanceActor; use crate::actors::preference::PreferenceActor; use crate::actors::process::ProcessActor; use crate::actors::root::RootActor; -use crate::actors::worker::WorkerActor; +use crate::actors::thread::ThreadActor; +use crate::actors::worker::{WorkerActor, WorkerType}; use crate::protocol::JsonPacketStream; use crossbeam_channel::{unbounded, Receiver, Sender}; use devtools_traits::{ChromeToDevtoolsControlMsg, ConsoleMessage, DevtoolsControlMsg}; @@ -69,6 +70,12 @@ mod actors { } mod protocol; +#[derive(Clone, Debug, Eq, Hash, PartialEq)] +enum UniqueId { + Pipeline(PipelineId), + Worker(WorkerId), +} + #[derive(Serialize)] struct ConsoleAPICall { from: String, @@ -176,6 +183,7 @@ fn run_server( let root = Box::new(RootActor { tabs: vec![], + workers: vec![], device: device.name(), performance: performance.name(), preference: preference.name(), @@ -197,7 +205,7 @@ fn run_server( let mut pipelines: HashMap<PipelineId, BrowsingContextId> = HashMap::new(); let mut actor_requests: HashMap<String, String> = HashMap::new(); - let mut actor_workers: HashMap<(PipelineId, WorkerId), String> = HashMap::new(); + let mut actor_workers: HashMap<WorkerId, String> = HashMap::new(); /// Process the input from a single devtools client until EOF. fn handle_client(actors: Arc<Mutex<ActorRegistry>>, mut stream: TcpStream) { @@ -258,11 +266,11 @@ fn run_server( // TODO: move this into the root or target modules? fn handle_new_global( actors: Arc<Mutex<ActorRegistry>>, - ids: (Option<BrowsingContextId>, PipelineId, Option<WorkerId>), + ids: (BrowsingContextId, PipelineId, Option<WorkerId>), script_sender: IpcSender<DevtoolScriptControlMsg>, browsing_contexts: &mut HashMap<BrowsingContextId, String>, pipelines: &mut HashMap<PipelineId, BrowsingContextId>, - actor_workers: &mut HashMap<(PipelineId, WorkerId), String>, + actor_workers: &mut HashMap<WorkerId, String>, page_info: DevtoolsPageInfo, ) { let mut actors = actors.lock().unwrap(); @@ -271,47 +279,59 @@ fn run_server( let console_name = actors.new_name("console"); - let browsing_context_name = if let Some(browsing_context) = browsing_context { - pipelines.insert(pipeline, browsing_context); - if let Some(actor) = browsing_contexts.get(&browsing_context) { - actor.to_owned() - } else { - let browsing_context_actor = BrowsingContextActor::new( - console_name.clone(), - browsing_context, - page_info, - pipeline, - script_sender.clone(), - &mut *actors, - ); - let name = browsing_context_actor.name(); - browsing_contexts.insert(browsing_context, name.clone()); - actors.register(Box::new(browsing_context_actor)); - name - } - } else { - "".to_owned() - }; + let parent_actor = if let Some(id) = worker_id { + assert!(pipelines.get(&pipeline).is_some()); + assert!(browsing_contexts.get(&browsing_context).is_some()); - // XXXjdm this new actor is useless if it's not a new worker global - let console = ConsoleActor { - name: console_name, - cached_events: Default::default(), - browsing_context: browsing_context_name, - }; + let thread = ThreadActor::new(actors.new_name("context")); + let thread_name = thread.name(); + actors.register(Box::new(thread)); - if let Some(id) = worker_id { + let worker_name = actors.new_name("worker"); let worker = WorkerActor { - name: actors.new_name("worker"), - console: console.name(), + name: worker_name.clone(), + console: console_name.clone(), + thread: thread_name, id: id, + url: page_info.url.clone(), + type_: WorkerType::Dedicated, + script_chan: script_sender, + streams: Default::default(), }; let root = actors.find_mut::<RootActor>("root"); - root.tabs.push(worker.name.clone()); + root.workers.push(worker.name.clone()); - actor_workers.insert((pipeline, id), worker.name.clone()); + actor_workers.insert(id, worker_name.clone()); actors.register(Box::new(worker)); - } + + Root::DedicatedWorker(worker_name) + } else { + pipelines.insert(pipeline, browsing_context); + Root::BrowsingContext( + if let Some(actor) = browsing_contexts.get(&browsing_context) { + actor.to_owned() + } else { + let browsing_context_actor = BrowsingContextActor::new( + console_name.clone(), + browsing_context, + page_info, + pipeline, + script_sender, + &mut *actors, + ); + let name = browsing_context_actor.name(); + browsing_contexts.insert(browsing_context, name.clone()); + actors.register(Box::new(browsing_context_actor)); + name + }, + ) + }; + + let console = ConsoleActor { + name: console_name, + cached_events: Default::default(), + root: parent_actor, + }; actors.register(Box::new(console)); } @@ -319,15 +339,17 @@ fn run_server( fn handle_page_error( actors: Arc<Mutex<ActorRegistry>>, id: PipelineId, + worker_id: Option<WorkerId>, page_error: PageError, browsing_contexts: &HashMap<BrowsingContextId, String>, + actor_workers: &HashMap<WorkerId, String>, pipelines: &HashMap<PipelineId, BrowsingContextId>, ) { let console_actor_name = match find_console_actor( actors.clone(), id, - None, - &HashMap::new(), + worker_id, + actor_workers, browsing_contexts, pipelines, ) { @@ -336,9 +358,8 @@ fn run_server( }; let actors = actors.lock().unwrap(); let console_actor = actors.find::<ConsoleActor>(&console_actor_name); - let browsing_context_actor = - actors.find::<BrowsingContextActor>(&console_actor.browsing_context); - console_actor.handle_page_error(page_error, id, &browsing_context_actor); + let id = worker_id.map_or(UniqueId::Pipeline(id), UniqueId::Worker); + console_actor.handle_page_error(page_error, id, &*actors); } fn handle_console_message( @@ -347,7 +368,7 @@ fn run_server( worker_id: Option<WorkerId>, console_message: ConsoleMessage, browsing_contexts: &HashMap<BrowsingContextId, String>, - actor_workers: &HashMap<(PipelineId, WorkerId), String>, + actor_workers: &HashMap<WorkerId, String>, pipelines: &HashMap<PipelineId, BrowsingContextId>, ) { let console_actor_name = match find_console_actor( @@ -363,22 +384,21 @@ fn run_server( }; let actors = actors.lock().unwrap(); let console_actor = actors.find::<ConsoleActor>(&console_actor_name); - let browsing_context_actor = - actors.find::<BrowsingContextActor>(&console_actor.browsing_context); - console_actor.handle_console_api(console_message, id, &browsing_context_actor); + let id = worker_id.map_or(UniqueId::Pipeline(id), UniqueId::Worker); + console_actor.handle_console_api(console_message, id, &*actors); } fn find_console_actor( actors: Arc<Mutex<ActorRegistry>>, pipeline: PipelineId, worker_id: Option<WorkerId>, - actor_workers: &HashMap<(PipelineId, WorkerId), String>, + actor_workers: &HashMap<WorkerId, String>, browsing_contexts: &HashMap<BrowsingContextId, String>, pipelines: &HashMap<PipelineId, BrowsingContextId>, ) -> Option<String> { let actors = actors.lock().unwrap(); if let Some(worker_id) = worker_id { - let actor_name = (*actor_workers).get(&(pipeline, worker_id))?; + let actor_name = actor_workers.get(&worker_id)?; Some(actors.find::<WorkerActor>(actor_name).console.clone()) } else { let id = pipelines.get(&pipeline)?; @@ -397,7 +417,7 @@ fn run_server( mut connections: Vec<TcpStream>, browsing_contexts: &HashMap<BrowsingContextId, String>, actor_requests: &mut HashMap<String, String>, - actor_workers: &HashMap<(PipelineId, WorkerId), String>, + actor_workers: &HashMap<WorkerId, String>, pipelines: &HashMap<PipelineId, BrowsingContextId>, pipeline_id: PipelineId, request_id: String, @@ -570,6 +590,7 @@ fn run_server( .expect("Thread spawning failed"); while let Ok(msg) = receiver.recv() { + debug!("{:?}", msg); match msg { DevtoolsControlMsg::FromChrome(ChromeToDevtoolsControlMsg::AddClient(stream)) => { let actors = actors.clone(); @@ -619,8 +640,10 @@ fn run_server( )) => handle_page_error( actors.clone(), id, + None, page_error, &browsing_contexts, + &actor_workers, &pipelines, ), DevtoolsControlMsg::FromScript(ScriptToDevtoolsControlMsg::ReportCSSError( |