Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve devtools experience when navigating #26325

Merged
merged 7 commits into from Apr 28, 2020
Prev

Update devtools page titles.

  • Loading branch information
jdm committed Apr 28, 2020
commit 02ce6188aa967ef1722155f9b170183a01a14064
@@ -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)]
@@ -235,6 +235,26 @@ fn run_server(
.navigate(state);
}

fn handle_title_changed(
actors: Arc<Mutex<ActorRegistry>>,
pipelines: &HashMap<PipelineId, BrowsingContextId>,
browsing_contexts: &HashMap<BrowsingContextId, String>,
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::<BrowsingContextActor>(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,
@@ -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
@@ -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::<GlobalScope>();
if let Some(ref chan) = global.devtools_chan() {
let title = String::from(self.Title());
let _ = chan.send(ScriptToDevtoolsControlMsg::TitleChanged(
global.pipeline_id(),
title,
));
}
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.