Register iframes with the devtools (#35874)

Previously, the devtools didn't know about
<iframe>s. They either ignored messages coming from
iframes or crashed.

This reverts https://github.com/servo/servo/pull/34032
and then filters out non-tab globals in the "listTabs"
message to the root actor.

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker 2025-03-09 21:42:39 +01:00 committed by GitHub
parent 4d73de3dde
commit 48aacc43b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 34 additions and 13 deletions

View file

@ -4025,6 +4025,7 @@ where
let page_info = DevtoolsPageInfo { let page_info = DevtoolsPageInfo {
title: new_pipeline.title.clone(), title: new_pipeline.title.clone(),
url: new_pipeline.url.clone(), url: new_pipeline.url.clone(),
is_top_level_global: top_level_id == browsing_context_id,
}; };
let state = NavigationState::Stop(new_pipeline.id, page_info); let state = NavigationState::Stop(new_pipeline.id, page_info);
let _ = chan.send(DevtoolsControlMsg::FromScript( let _ = chan.send(DevtoolsControlMsg::FromScript(

View file

@ -180,7 +180,11 @@ impl BrowsingContextActor {
actors: &mut ActorRegistry, actors: &mut ActorRegistry,
) -> BrowsingContextActor { ) -> BrowsingContextActor {
let name = actors.new_name("target"); let name = actors.new_name("target");
let DevtoolsPageInfo { title, url } = page_info; let DevtoolsPageInfo {
title,
url,
is_top_level_global,
} = page_info;
let accessibility = AccessibilityActor::new(actors.new_name("accessibility")); let accessibility = AccessibilityActor::new(actors.new_name("accessibility"));
@ -205,7 +209,7 @@ impl BrowsingContextActor {
let style_sheets = StyleSheetsActor::new(actors.new_name("stylesheets")); let style_sheets = StyleSheetsActor::new(actors.new_name("stylesheets"));
let tabdesc = TabDescriptorActor::new(actors, name.clone()); let tabdesc = TabDescriptorActor::new(actors, name.clone(), is_top_level_global);
let thread = ThreadActor::new(actors.new_name("thread")); let thread = ThreadActor::new(actors.new_name("thread"));

View file

@ -200,10 +200,14 @@ impl Actor for RootActor {
tabs: self tabs: self
.tabs .tabs
.iter() .iter()
.map(|target| { .filter_map(|target| {
registry let tab_actor = registry.find::<TabDescriptorActor>(target);
.find::<TabDescriptorActor>(target) // Filter out iframes and workers
.encodable(registry, false) if tab_actor.is_top_level_global() {
Some(tab_actor.encodable(registry, false))
} else {
None
}
}) })
.collect(), .collect(),
}; };

View file

@ -65,6 +65,7 @@ struct GetWatcherReply {
pub struct TabDescriptorActor { pub struct TabDescriptorActor {
name: String, name: String,
browsing_context_actor: String, browsing_context_actor: String,
is_top_level_global: bool,
} }
impl Actor for TabDescriptorActor { impl Actor for TabDescriptorActor {
@ -125,6 +126,7 @@ impl TabDescriptorActor {
pub(crate) fn new( pub(crate) fn new(
actors: &mut ActorRegistry, actors: &mut ActorRegistry,
browsing_context_actor: String, browsing_context_actor: String,
is_top_level_global: bool,
) -> TabDescriptorActor { ) -> TabDescriptorActor {
let name = actors.new_name("tab-description"); let name = actors.new_name("tab-description");
let root = actors.find_mut::<RootActor>("root"); let root = actors.find_mut::<RootActor>("root");
@ -132,6 +134,7 @@ impl TabDescriptorActor {
TabDescriptorActor { TabDescriptorActor {
name, name,
browsing_context_actor, browsing_context_actor,
is_top_level_global,
} }
} }
@ -157,4 +160,8 @@ impl TabDescriptorActor {
url, url,
} }
} }
pub(crate) fn is_top_level_global(&self) -> bool {
self.is_top_level_global
}
} }

View file

@ -204,6 +204,7 @@ impl WorkerMethods<crate::DomTypeHolder> for Worker {
let page_info = DevtoolsPageInfo { let page_info = DevtoolsPageInfo {
title, title,
url: worker_url.clone(), url: worker_url.clone(),
is_top_level_global: false,
}; };
let _ = chan.send(ScriptToDevtoolsControlMsg::NewGlobal( let _ = chan.send(ScriptToDevtoolsControlMsg::NewGlobal(
(browsing_context, pipeline_id, Some(worker_id)), (browsing_context, pipeline_id, Some(worker_id)),

View file

@ -3238,13 +3238,14 @@ impl ScriptThread {
.unwrap(); .unwrap();
// Notify devtools that a new script global exists. // Notify devtools that a new script global exists.
if incomplete.top_level_browsing_context_id.0 == incomplete.browsing_context_id { let is_top_level_global =
self.notify_devtools( incomplete.top_level_browsing_context_id.0 == incomplete.browsing_context_id;
document.Title(), self.notify_devtools(
final_url.clone(), document.Title(),
(incomplete.browsing_context_id, incomplete.pipeline_id, None), final_url.clone(),
); is_top_level_global,
} (incomplete.browsing_context_id, incomplete.pipeline_id, None),
);
document.set_https_state(metadata.https_state); document.set_https_state(metadata.https_state);
document.set_navigation_start(incomplete.navigation_start); document.set_navigation_start(incomplete.navigation_start);
@ -3272,12 +3273,14 @@ impl ScriptThread {
&self, &self,
title: DOMString, title: DOMString,
url: ServoUrl, url: ServoUrl,
is_top_level_global: bool,
(bc, p, w): (BrowsingContextId, PipelineId, Option<WorkerId>), (bc, p, w): (BrowsingContextId, PipelineId, Option<WorkerId>),
) { ) {
if let Some(ref chan) = self.senders.devtools_server_sender { if let Some(ref chan) = self.senders.devtools_server_sender {
let page_info = DevtoolsPageInfo { let page_info = DevtoolsPageInfo {
title: String::from(title), title: String::from(title),
url, url,
is_top_level_global,
}; };
chan.send(ScriptToDevtoolsControlMsg::NewGlobal( chan.send(ScriptToDevtoolsControlMsg::NewGlobal(
(bc, p, w), (bc, p, w),

View file

@ -32,6 +32,7 @@ use uuid::Uuid;
pub struct DevtoolsPageInfo { pub struct DevtoolsPageInfo {
pub title: String, pub title: String,
pub url: ServoUrl, pub url: ServoUrl,
pub is_top_level_global: bool,
} }
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)] #[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]