Truly independent web browser
LibWebView: Keep a tab's title and favicon until its document changes
Shannon Booth8bbd26a65816
diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cppindex 870b8e09724..5c4b527c92b 100644--- a/Libraries/LibWebView/CanonicalTraversable.cpp+++ b/Libraries/LibWebView/CanonicalTraversable.cpp@@ -1555,7 +1555,8 @@ void CanonicalTraversable::did_activate_history_entry(HistoryOperation& operatioif (&navigable == this) {if (auto view = this->view(); view.has_value()) {- view->did_change_active_document({});+ if (&navigable.active_document() != replaced_document)+ view->did_change_active_document({});// NB: The address bar can already show a pending navigation's URL while the old document// is still visible. Only apply the destination's zoom after its document is activated.view->apply_zoom_for_current_host();diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cppindex cda4a494933..cc2575c4f1d 100644--- a/Libraries/LibWebView/ViewImplementation.cpp+++ b/Libraries/LibWebView/ViewImplementation.cpp@@ -181,6 +181,8 @@ void ViewImplementation::did_change_ongoing_navigation(Badge<CanonicalNavigable>void ViewImplementation::did_change_active_document(Badge<CanonicalTraversable>){+ set_title(Utf16String::from_utf8(url().serialize()));+ set_favicon({});did_update_url();}@@ -218,7 +220,7 @@ void ViewImplementation::set_text_fragment_indication_visibility(Badge<WebContenupdate_displayed_url();}-void ViewImplementation::set_title(Badge<WebContentPage>, Utf16String title)+void ViewImplementation::set_title(Utf16String title){if (m_title == title)return;@@ -229,7 +231,7 @@ void ViewImplementation::set_title(Badge<WebContentPage>, Utf16String title)on_title_change(m_title);}-void ViewImplementation::set_favicon(Badge<WebContentPage>, Optional<Gfx::Bitmap const&> favicon)+void ViewImplementation::set_favicon(Optional<Gfx::Bitmap const&> favicon){m_favicon_hash.clear();@@ -3347,6 +3349,7 @@ JsonValue ViewImplementation::webdriver_session_history() constJsonObject serialized;serialized.set("currentURL"sv, url().serialize());serialized.set("displayedURL"sv, m_displayed_url.serialize());+ serialized.set("title"sv, m_title.to_utf8());serialized.set("webContentProcessID"sv, page().client().pid());serialized.set("backButtonEnabled"sv, m_navigate_back_action->enabled());serialized.set("forwardButtonEnabled"sv, m_navigate_forward_action->enabled());diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.hindex eb324334844..12e38a3aa81 100644--- a/Libraries/LibWebView/ViewImplementation.h+++ b/Libraries/LibWebView/ViewImplementation.h@@ -131,10 +131,10 @@ public:URL::URL url() const;URL::URL const& displayed_url() const { return m_displayed_url; }- void set_title(Badge<WebContentPage>, Utf16String title);+ void set_title(Badge<WebContentPage>, Utf16String title) { set_title(move(title)); }Utf16String const& title() const { return m_title; }- void set_favicon(Badge<WebContentPage>, Optional<Gfx::Bitmap const&>);+ void set_favicon(Badge<WebContentPage>, Optional<Gfx::Bitmap const&> favicon) { set_favicon(favicon); }Optional<String> const& favicon_hash() const { return m_favicon_hash; }String const& handle() const { return m_window_handle; }@@ -626,6 +626,8 @@ protected:void set_owner_view(ViewImplementation const& owner_view) { m_owner_view_id = owner_view.view_id(); }void did_update_url();+ void set_title(Utf16String);+ void set_favicon(Optional<Gfx::Bitmap const&>);Optional<URL::URL const&> browser_ui_load_url() const;void update_displayed_url();void did_start_navigation();diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cppindex 22d7a6e8cf2..5dddf54ee1f 100644--- a/Libraries/LibWebView/WebContentPage.cpp+++ b/Libraries/LibWebView/WebContentPage.cpp@@ -447,8 +447,6 @@ void WebContentPage::begin_top_level_load(URL::URL const& url)view.m_history_visit_transition_for_next_load = HistoryVisitTransition::Link;view.did_start_navigation();- view.set_title({}, Utf16String::from_utf8(url.serialize()));- view.set_favicon({}, {});view.set_editing_history_state(false, false);if (view.on_load_start)diff --git a/Tests/LibWebView/test-webdriver-session-history.py b/Tests/LibWebView/test-webdriver-session-history.pyindex 334d66092c0..09e3dea8b51 100755--- a/Tests/LibWebView/test-webdriver-session-history.py+++ b/Tests/LibWebView/test-webdriver-session-history.py@@ -2630,7 +2630,11 @@ def run_pending_ui_load_test(webdriver_port, page_server, url_a, url_navigation_wait_for_event(page_server.blocked_navigation_requested, "pending UI load request")pending_history = session_history(webdriver_port, session_id)["ui"]- if pending_history["currentURL"] != url_a or pending_history["displayedURL"] != url_navigation_blocked:+ if (+ pending_history["currentURL"] != url_a+ or pending_history["displayedURL"] != url_navigation_blocked+ or pending_history["title"] != "A"+ ):raise AssertionError(f"Expected the pending UI load to show only in the address bar, got {pending_history}\n"+ "\n".join(log)@@ -2671,7 +2675,11 @@ document.cookie = "control=1; path=/";wait_for_event(page_server.blocked_no_content_navigation_requested, "page-initiated navigation request")superseded_history = session_history(webdriver_port, session_id)["ui"]- if superseded_history["currentURL"] != url_a or superseded_history["displayedURL"] != url_a:+ if (+ superseded_history["currentURL"] != url_a+ or superseded_history["displayedURL"] != url_a+ or superseded_history["title"] != "A"+ ):raise AssertionError(f"Expected the address bar to stop showing the superseded UI load, got {superseded_history}\n"+ "\n".join(log)