From fd9be5097d7a65af511ad4d19fa54971c58e210a Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 10 Aug 2020 17:52:22 -0400 Subject: [PATCH] devtools: Treat session history traversal like a navigation. --- components/constellation/constellation.rs | 25 ++++++++++++++++++++++- components/constellation/pipeline.rs | 4 ++++ components/script/dom/document.rs | 6 +++++- components/script_traits/script_msg.rs | 3 +++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index 5dbacfb939f..5aaf8bf5d8c 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -112,7 +112,10 @@ use compositing::compositor_thread::Msg as ToCompositorMsg; use compositing::compositor_thread::WebrenderMsg; use compositing::{ConstellationMsg as FromCompositorMsg, SendableFrameTree}; use crossbeam_channel::{after, never, unbounded, Receiver, Sender}; -use devtools_traits::{ChromeToDevtoolsControlMsg, DevtoolsControlMsg}; +use devtools_traits::{ + ChromeToDevtoolsControlMsg, DevtoolsControlMsg, DevtoolsPageInfo, NavigationState, + ScriptToDevtoolsControlMsg, +}; use embedder_traits::{Cursor, EmbedderMsg, EmbedderProxy, EventLoopWaker}; use embedder_traits::{MediaSessionEvent, MediaSessionPlaybackState}; use euclid::{default::Size2D as UntypedSize2D, Size2D}; @@ -1934,6 +1937,11 @@ where BrowsingContextId::from(source_top_ctx_id), FromScriptMsg::GetWebGPUChan(sender), ), + FromScriptMsg::TitleChanged(pipeline, title) => { + if let Some(pipeline) = self.pipelines.get_mut(&pipeline) { + pipeline.title = title; + } + }, } } @@ -3935,6 +3943,21 @@ where old_pipeline.notify_visibility(false); } if let Some(new_pipeline) = self.pipelines.get(&new_pipeline_id) { + if let Some(ref chan) = self.devtools_chan { + let state = NavigationState::Start(new_pipeline.url.clone()); + let _ = chan.send(DevtoolsControlMsg::FromScript( + ScriptToDevtoolsControlMsg::Navigate(browsing_context_id, state), + )); + let page_info = DevtoolsPageInfo { + title: new_pipeline.title.clone(), + url: new_pipeline.url.clone(), + }; + let state = NavigationState::Stop(new_pipeline.id, page_info); + let _ = chan.send(DevtoolsControlMsg::FromScript( + ScriptToDevtoolsControlMsg::Navigate(browsing_context_id, state), + )); + } + new_pipeline.notify_visibility(true); } diff --git a/components/constellation/pipeline.rs b/components/constellation/pipeline.rs index 40d38c13159..108bc403e42 100644 --- a/components/constellation/pipeline.rs +++ b/components/constellation/pipeline.rs @@ -97,6 +97,9 @@ pub struct Pipeline { /// Has this pipeline received a notification that it is completely loaded? pub completely_loaded: bool, + + /// The title of this pipeline's document. + pub title: String, } /// Initial setup data needed to construct a pipeline. @@ -379,6 +382,7 @@ impl Pipeline { history_state_id: None, history_states: HashSet::new(), completely_loaded: false, + title: String::new(), }; pipeline.notify_visibility(is_visible); diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index fef552b326b..8b6cce24155 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -1142,9 +1142,13 @@ impl Document { pub fn title_changed(&self) { if self.browsing_context().is_some() { self.send_title_to_embedder(); + let title = String::from(self.Title()); + self.window.send_to_constellation(ScriptMsg::TitleChanged( + self.window.pipeline_id(), + title.clone(), + )); 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, diff --git a/components/script_traits/script_msg.rs b/components/script_traits/script_msg.rs index 83dc024b0d3..b17f84180b5 100644 --- a/components/script_traits/script_msg.rs +++ b/components/script_traits/script_msg.rs @@ -282,6 +282,8 @@ pub enum ScriptMsg { ), /// Get WebGPU channel GetWebGPUChan(IpcSender), + /// Notify the constellation of a pipeline's document's title. + TitleChanged(PipelineId, String), } impl fmt::Debug for ScriptMsg { @@ -341,6 +343,7 @@ impl fmt::Debug for ScriptMsg { MediaSessionEvent(..) => "MediaSessionEvent", RequestAdapter(..) => "RequestAdapter", GetWebGPUChan(..) => "GetWebGPUChan", + TitleChanged(..) => "TitleChanged", }; write!(formatter, "ScriptMsg::{}", variant) }