diff --git a/components/devtools/actors/root.rs b/components/devtools/actors/root.rs index 2fb3c4de722..8ad21fc4bda 100644 --- a/components/devtools/actors/root.rs +++ b/components/devtools/actors/root.rs @@ -9,6 +9,7 @@ //! //! [Firefox JS implementation]: https://searchfox.org/mozilla-central/source/devtools/server/actors/root.js +use std::cell::RefCell; use std::net::TcpStream; use serde::Serialize; @@ -129,6 +130,7 @@ pub struct RootActor { pub device: String, pub preference: String, pub process: String, + pub active_tab: RefCell>, } impl Actor for RootActor { @@ -303,13 +305,24 @@ impl RootActor { registry: &ActorRegistry, browser_id: u32, ) -> Option { - self.tabs + let tab_msg = self + .tabs .iter() .map(|target| { registry .find::(target) .encodable(registry, true) }) - .find(|tab| tab.browser_id() == browser_id) + .find(|tab| tab.browser_id() == browser_id); + + if let Some(ref msg) = tab_msg { + *self.active_tab.borrow_mut() = Some(msg.actor()); + } + tab_msg + } + + #[allow(dead_code)] + pub fn active_tab(&self) -> Option { + self.active_tab.borrow().clone() } } diff --git a/components/devtools/actors/tab.rs b/components/devtools/actors/tab.rs index 702e765535e..564259ab1ff 100644 --- a/components/devtools/actors/tab.rs +++ b/components/devtools/actors/tab.rs @@ -43,6 +43,10 @@ impl TabDescriptorActorMsg { pub fn browser_id(&self) -> u32 { self.browser_id } + + pub fn actor(&self) -> String { + self.actor.clone() + } } #[derive(Serialize)] @@ -167,4 +171,9 @@ impl TabDescriptorActor { pub(crate) fn is_top_level_global(&self) -> bool { self.is_top_level_global } + + #[allow(dead_code)] + pub fn browsing_context(&self) -> String { + self.browsing_context_actor.clone() + } } diff --git a/components/devtools/lib.rs b/components/devtools/lib.rs index eb3aa80dbf9..7e7de928ab1 100644 --- a/components/devtools/lib.rs +++ b/components/devtools/lib.rs @@ -153,6 +153,7 @@ impl DevtoolsInstance { performance: performance.name(), preference: preference.name(), process: process.name(), + active_tab: None.into(), }); registry.register(root);