Propagate page title and favicon into the active tab
Servo already publishes the live page title in every `LiveFrameReport` but the renderer was dropping it on the floor — tabs that navigated away from `ely://new-tab` kept showing "New Tab" forever, and there was no favicon visible anywhere in the sidebar. Add `BrowserCore::set_tab_title` and switch `set_tab_favicon_key` to return `Ok(true)` only when the value actually changed; both methods mirror the new value into the matching history entry so the History page stays in lockstep. Derive the canonical `/favicon.ico` URL from the loaded URL on `UrlText` and store it as the tab's `favicon_key`. In the surface layer, every Ready frame now emits a `WebSurfacePageMetadata` change alongside any `WebSurfaceUrlChange`, and the controller applies title + favicon URL together. Render the sidebar tab row's favicon via GPUI's HTTP image loader (falling through to the URL-derived glyph for `ely://` pages, file URLs, and hosts without a /favicon.ico endpoint).
This commit is contained in:
@@ -84,6 +84,17 @@ impl BrowserCore {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn set_history_title_for_tab(&mut self, tab: &BrowserTab, title: impl Into<String>) {
|
||||
let title = title.into();
|
||||
if let Some(entry) = self.history_entries.iter_mut().find(|entry| {
|
||||
entry.profile_id() == tab.profile_id()
|
||||
&& entry.space_id() == tab.space_id()
|
||||
&& entry.url() == tab.url()
|
||||
}) {
|
||||
entry.set_title(title);
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn find_history_match(&self, query: &str) -> Option<UrlText> {
|
||||
let normalized_query = query.trim().to_lowercase();
|
||||
if normalized_query.is_empty() {
|
||||
|
||||
@@ -292,17 +292,43 @@ impl BrowserCore {
|
||||
&mut self,
|
||||
tab_id: &TabId,
|
||||
favicon_key: impl Into<String>,
|
||||
) -> Result<(), CoreError> {
|
||||
) -> Result<bool, CoreError> {
|
||||
let favicon_key = favicon_key.into();
|
||||
let tab_index = self
|
||||
.tabs
|
||||
.iter()
|
||||
.position(|tab| tab.id() == tab_id)
|
||||
.ok_or_else(|| CoreError::TabNotFound { id: tab_id.clone() })?;
|
||||
if self.tabs[tab_index].favicon_key() == Some(favicon_key.as_str()) {
|
||||
return Ok(false);
|
||||
}
|
||||
self.tabs[tab_index].set_favicon_key(favicon_key.clone())?;
|
||||
let tab = self.tabs[tab_index].clone();
|
||||
self.set_history_favicon_key_for_tab(&tab, favicon_key);
|
||||
Ok(())
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// Replace `tab_id`'s title with the live page title and mirror
|
||||
/// the new title into the history entry that recorded the visit.
|
||||
/// Returns `Ok(true)` only when the title actually changed —
|
||||
/// callers can use this to suppress redundant re-renders.
|
||||
pub fn set_tab_title(
|
||||
&mut self,
|
||||
tab_id: &TabId,
|
||||
title: impl Into<String>,
|
||||
) -> Result<bool, CoreError> {
|
||||
let title = title.into();
|
||||
let tab_index = self
|
||||
.tabs
|
||||
.iter()
|
||||
.position(|tab| tab.id() == tab_id)
|
||||
.ok_or_else(|| CoreError::TabNotFound { id: tab_id.clone() })?;
|
||||
if !self.tabs[tab_index].set_title(title.clone()) {
|
||||
return Ok(false);
|
||||
}
|
||||
let tab = self.tabs[tab_index].clone();
|
||||
self.set_history_title_for_tab(&tab, tab.title().to_string());
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
pub fn clear_tab_favicon_key(&mut self, tab_id: &TabId) -> Result<(), CoreError> {
|
||||
|
||||
Reference in New Issue
Block a user