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:
@@ -91,6 +91,10 @@ impl HistoryEntry {
|
||||
self.favicon_key = None;
|
||||
}
|
||||
|
||||
pub fn set_title(&mut self, title: impl Into<String>) {
|
||||
self.title = title.into();
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn visited_at(&self) -> SystemTime {
|
||||
self.visited_at
|
||||
|
||||
@@ -293,6 +293,20 @@ impl BrowserTab {
|
||||
self.last_active_at = SystemTime::now();
|
||||
}
|
||||
|
||||
/// Set the tab title. Trims whitespace; an entirely-blank title
|
||||
/// keeps the previous value so a page that emits an empty
|
||||
/// `<title>` mid-load doesn't clobber the URL-derived label that
|
||||
/// the new-tab path installed.
|
||||
pub fn set_title(&mut self, title: impl Into<String>) -> bool {
|
||||
let title = title.into();
|
||||
let trimmed = title.trim();
|
||||
if trimmed.is_empty() || self.title == trimmed {
|
||||
return false;
|
||||
}
|
||||
self.title = trimmed.to_string();
|
||||
true
|
||||
}
|
||||
|
||||
/// Navigate in place and record the previous URL in this tab's
|
||||
/// back stack.
|
||||
pub fn navigate_to(&mut self, url: UrlText) {
|
||||
|
||||
@@ -71,6 +71,20 @@ impl UrlText {
|
||||
|
||||
url.host_str().map(str::to_string).unwrap_or_else(|| self.value.clone())
|
||||
}
|
||||
|
||||
/// Resolve the canonical `/favicon.ico` URL for an HTTP(S) page.
|
||||
/// Returns `None` for non-web schemes (`ely://`, `file://`, etc.)
|
||||
/// or URLs missing an authority — those tabs render the URL-derived
|
||||
/// glyph instead of a fetched icon.
|
||||
#[must_use]
|
||||
pub fn favicon_url(&self) -> Option<String> {
|
||||
let url = Url::parse(&self.value).ok()?;
|
||||
if !matches!(url.scheme(), "http" | "https") {
|
||||
return None;
|
||||
}
|
||||
url.host_str()?;
|
||||
url.join("/favicon.ico").ok().map(|favicon| favicon.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for UrlText {
|
||||
|
||||
Reference in New Issue
Block a user