diff --git a/components/devtools/actors/browsing_context.rs b/components/devtools/actors/browsing_context.rs index 5ebe014cdad..b90d84d04bd 100644 --- a/components/devtools/actors/browsing_context.rs +++ b/components/devtools/actors/browsing_context.rs @@ -347,6 +347,13 @@ impl BrowsingContextActor { stream.write_json_packet(&msg); } } + + pub(crate) fn title_changed(&self, pipeline: PipelineId, title: String) { + if pipeline != self.active_pipeline.get() { + return; + } + *self.title.borrow_mut() = title; + } } #[derive(Serialize)] diff --git a/components/devtools/lib.rs b/components/devtools/lib.rs index a12205d4724..2227be98549 100644 --- a/components/devtools/lib.rs +++ b/components/devtools/lib.rs @@ -235,6 +235,26 @@ fn run_server( .navigate(state); } + fn handle_title_changed( + actors: Arc>, + pipelines: &HashMap, + browsing_contexts: &HashMap, + pipeline: PipelineId, + title: String, + ) { + let bc = match pipelines.get(&pipeline) { + Some(bc) => bc, + None => return, + }; + let name = match browsing_contexts.get(&bc) { + Some(name) => name, + None => return, + }; + let actors = actors.lock().unwrap(); + let browsing_context = actors.find::(name); + browsing_context.title_changed(pipeline, title); + } + // We need separate actor representations for each script global that exists; // clients can theoretically connect to multiple globals simultaneously. // TODO: move this into the root or target modules? @@ -578,6 +598,16 @@ fn run_server( actor_name, tick, )) => handle_framerate_tick(actors.clone(), actor_name, tick), + DevtoolsControlMsg::FromScript(ScriptToDevtoolsControlMsg::TitleChanged( + pipeline, + title, + )) => handle_title_changed( + actors.clone(), + &pipelines, + &browsing_contexts, + pipeline, + title, + ), DevtoolsControlMsg::FromScript(ScriptToDevtoolsControlMsg::NewGlobal( ids, script_sender, diff --git a/components/devtools_traits/lib.rs b/components/devtools_traits/lib.rs index 2ac1cae598a..7196c3a5b32 100644 --- a/components/devtools_traits/lib.rs +++ b/components/devtools_traits/lib.rs @@ -97,6 +97,9 @@ pub enum ScriptToDevtoolsControlMsg { /// Report a page error for the given pipeline ReportPageError(PipelineId, PageError), + + /// Report a page title change + TitleChanged(PipelineId, String), } /// Serialized JS return values diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 2d0f2ce1c26..3606ffc7c9d 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -934,6 +934,14 @@ impl Document { pub fn title_changed(&self) { if self.browsing_context().is_some() { self.send_title_to_embedder(); + let global = self.window.upcast::(); + if let Some(ref chan) = global.devtools_chan() { + let title = String::from(self.Title()); + let _ = chan.send(ScriptToDevtoolsControlMsg::TitleChanged( + global.pipeline_id(), + title, + )); + } } }