Skip to content

Truly independent web browser

LibWebView+Hub+UI/Qt: Move browsing history and favicons into the UI

Andreas Kling7cf806964146
diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cpp
index 3f939f50322..209e656d852 100644
--- a/Libraries/LibWebView/Application.cpp
+++ b/Libraries/LibWebView/Application.cpp
@@ -1748,16 +1748,10 @@ ErrorOr<void> Application::launch_services()
: Database::MigrationOutcome::DatabaseTooNew;
}
- if (favicons_outcome == Database::MigrationOutcome::Success && history_outcome == Database::MigrationOutcome::Success) {
- m_default_session->favicon_store = TRY(FaviconStore::create(history_database));
- m_default_session->history_store = TRY(HistoryStore::create(history_database));
- m_should_remove_unreferenced_favicons = true;
- } else {
- dbgln("History database was created by a newer Ladybird version; favicons and history will not be persisted this session");
+ // NB: The application keeps browsing history in this database. The omnibox reads it here too, so we migrate it
+ // before the omnibox opens it.
+ if (favicons_outcome != Database::MigrationOutcome::Success || history_outcome != Database::MigrationOutcome::Success)
history_database_directory = {};
- m_default_session->favicon_store = FaviconStore::create();
- m_default_session->history_store = HistoryStore::create(*m_default_session->favicon_store);
- }
// A headless run, a browser that WebDriver drives, and one that logs process statistics never join a browser
// already running on their profile. Yet startup recovery would still rewrite the saved session, reset the
@@ -1768,8 +1762,6 @@ ErrorOr<void> Application::launch_services()
dbgln_if(WEBVIEW_HISTORY_DEBUG, "[History] SQL history is disabled, disabling browsing history");
m_default_session->cookie_jar = CookieJar::create();
- m_default_session->favicon_store = FaviconStore::create();
- m_default_session->history_store = HistoryStore::create_disabled();
m_default_session->hsts_store = HSTSStore::create();
m_default_session->storage_jar = StorageJar::create();
m_download_store = DownloadStore::create_disabled();
@@ -2454,7 +2446,6 @@ NonnullRefPtr<Core::Promise<Empty>> Application::clear_browsing_data(ClearBrowsi
}
if (options.delete_history == ClearBrowsingDataOptions::Delete::Yes) {
- m_default_session->history_store->remove_entries_accessed_since(options.since);
if (auto result = CrashReportStore::the().remove_websites_saved_since(options.since); result.is_error())
dbgln("Unable to remove the websites of crash reports: {}", result.error());
CrashReportOutbox::the().reports_changed();
@@ -2850,18 +2841,6 @@ void Application::download_content_blocker_list_if_needed(Badge<Application, Set
}
// The shared actions that depend on the page follow the active view, whichever tab or window made it the active one.
-// NB: Only the application knows which favicons it keeps for itself, so without one telling us, nothing is removed.
-void Application::remove_unreferenced_favicons(HashTable<String> referenced_hashes)
-{
- if (!m_should_remove_unreferenced_favicons)
- return;
- m_should_remove_unreferenced_favicons = false;
-
- for (auto& hash : m_default_session->history_store->referenced_favicon_hashes())
- referenced_hashes.set(move(hash));
- m_default_session->favicon_store->remove_unreferenced_favicons(referenced_hashes);
-}
-
void Application::set_spell_checker(OwnPtr<SpellChecker> spell_checker)
{
m_spell_checker = move(spell_checker);
diff --git a/Libraries/LibWebView/Application.h b/Libraries/LibWebView/Application.h
index eb28ac9c526..34694a4d272 100644
--- a/Libraries/LibWebView/Application.h
+++ b/Libraries/LibWebView/Application.h
@@ -103,10 +103,8 @@ public:
static WebContentOptions& web_content_options() { return the().m_web_content_options; }
SpellChecker* spell_checker() { return m_spell_checker.ptr(); }
- void remove_unreferenced_favicons(HashTable<String> referenced_hashes);
// Going through history, the application can have a reason to keep what was typed to reach a page.
- virtual void read_keeps_omnibox_engagements(URL::URL const&, Function<void(bool)> on_read) const { on_read(false); }
void set_spell_checker(OwnPtr<SpellChecker>);
@@ -564,7 +562,6 @@ private:
RefPtr<Core::Timer> m_permission_expiry_timer;
OwnPtr<AutocompleteService> m_autocomplete_service;
- bool m_should_remove_unreferenced_favicons { false };
Main::Arguments m_arguments;
OwnPtr<Core::StatsLog> m_stats_log;
diff --git a/Libraries/LibWebView/BrowsingSession.cpp b/Libraries/LibWebView/BrowsingSession.cpp
index 2bf42dcf48d..e5f86885344 100644
--- a/Libraries/LibWebView/BrowsingSession.cpp
+++ b/Libraries/LibWebView/BrowsingSession.cpp
@@ -7,9 +7,7 @@
#include <LibWebView/BlobURLStore.h>
#include <LibWebView/BrowsingSession.h>
#include <LibWebView/CookieJar.h>
-#include <LibWebView/FaviconStore.h>
#include <LibWebView/HSTSStore.h>
-#include <LibWebView/HistoryStore.h>
#include <LibWebView/PermissionManager.h>
#include <LibWebView/StorageJar.h>
@@ -31,8 +29,6 @@ NonnullRefPtr<BrowsingSession> BrowsingSession::create(IsPrivate is_private)
session->storage_jar = StorageJar::create();
session->blob_url_store = make<BlobURLStore>();
session->hsts_store = HSTSStore::create();
- session->favicon_store = FaviconStore::create();
- session->history_store = HistoryStore::create_disabled();
}
return session;
diff --git a/Libraries/LibWebView/BrowsingSession.h b/Libraries/LibWebView/BrowsingSession.h
index 54c69172d0e..36bc201546e 100644
--- a/Libraries/LibWebView/BrowsingSession.h
+++ b/Libraries/LibWebView/BrowsingSession.h
@@ -37,8 +37,6 @@ public:
OwnPtr<StorageJar> storage_jar;
OwnPtr<BlobURLStore> blob_url_store;
OwnPtr<HSTSStore> hsts_store;
- OwnPtr<FaviconStore> favicon_store;
- OwnPtr<HistoryStore> history_store;
OwnPtr<PermissionManager> permission_manager;
private:
diff --git a/Libraries/LibWebView/CMakeLists.txt b/Libraries/LibWebView/CMakeLists.txt
index bb17d79712d..052798a5116 100644
--- a/Libraries/LibWebView/CMakeLists.txt
+++ b/Libraries/LibWebView/CMakeLists.txt
@@ -95,7 +95,6 @@ set(SOURCES
WebUI/ApplicationWebUI.cpp
WebUI/CrashReportsUI.cpp
WebUI/DownloadsUI.cpp
- WebUI/HistoryUI.cpp
WebUI/SettingsUI.cpp
WebUI/VersionUI.cpp
WebWorkerClient.cpp
diff --git a/Libraries/LibWebView/ProcessSnapshot.cpp b/Libraries/LibWebView/ProcessSnapshot.cpp
index 83804372e6b..c979aafdd86 100644
--- a/Libraries/LibWebView/ProcessSnapshot.cpp
+++ b/Libraries/LibWebView/ProcessSnapshot.cpp
@@ -59,7 +59,6 @@ Vector<ProcessSnapshot> process_snapshots(ProcessManager& manager)
.view_id = view.view_id(),
.url = view.url(),
.kind = ProcessPageKind::TopLevel,
- .favicon_hash = view.favicon_hash(),
},
});
view.traversable().for_each_in_subtree([&](auto const& navigable) {
@@ -100,8 +99,6 @@ Vector<ProcessSnapshot> process_snapshots(ProcessManager& manager)
.view_id = page->view->view_id(),
.url = page->url,
.kind = page->kind,
- // NB: The view's favicon is its top-level page's, which an embedded frame of another site does not share.
- .favicon_hash = page->kind == ProcessPageKind::TopLevel ? page->view->favicon_hash() : Optional<String> {},
};
}
snapshots.append(move(snapshot));
@@ -109,16 +106,6 @@ Vector<ProcessSnapshot> process_snapshots(ProcessManager& manager)
return snapshots;
}
-Optional<ByteBuffer> favicon_png_for_page(ProcessPageSnapshot const& page)
-{
- if (!page.favicon_hash.has_value())
- return {};
- auto view = ViewImplementation::find_view_by_id(page.view_id);
- if (!view.has_value())
- return {};
- return view->session().favicon_store->favicon_png(*page.favicon_hash);
-}
-
bool end_process(ProcessManager& process_manager, u64 child_id)
{
auto result = process_manager.terminate_child(child_id, Core::Process::TerminationMode::Forceful);
diff --git a/Libraries/LibWebView/ProcessSnapshot.h b/Libraries/LibWebView/ProcessSnapshot.h
index 622afe5b254..eaf10bf19c1 100644
--- a/Libraries/LibWebView/ProcessSnapshot.h
+++ b/Libraries/LibWebView/ProcessSnapshot.h
@@ -28,7 +28,6 @@ struct ProcessPageSnapshot {
u64 view_id { 0 };
URL::URL url;
ProcessPageKind kind { ProcessPageKind::TopLevel };
- Optional<String> favicon_hash;
};
// A tab whose page a WebContent process hosts.
@@ -64,6 +63,4 @@ WEBVIEW_API Vector<ProcessSnapshot> process_snapshots(ProcessManager&);
// Ends a process, and is satisfied with one that is already gone. Returns false for one that could not be ended.
WEBVIEW_API bool end_process(ProcessManager&, u64 child_id);
-WEBVIEW_API Optional<ByteBuffer> favicon_png_for_page(ProcessPageSnapshot const&);
-
}
diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp
index db3b710004a..deb76944876 100644
--- a/Libraries/LibWebView/ViewImplementation.cpp
+++ b/Libraries/LibWebView/ViewImplementation.cpp
@@ -180,11 +180,6 @@ pid_t ViewImplementation::web_content_pid() const
return page().client().pid();
}
-Vector<HistoryEntry> ViewImplementation::recent_history_entries(size_t limit) const
-{
- return m_session->history_store->list_entries({}, 0, limit);
-}
-
CanonicalTraversable& ViewImplementation::traversable() const
{
VERIFY(m_top_level_traversable);
@@ -421,17 +416,6 @@ void ViewImplementation::set_title(Utf16String title)
void ViewImplementation::set_favicon(Optional<Gfx::Bitmap const&> favicon)
{
- m_favicon_hash.clear();
-
- if (favicon.has_value()) {
- if (auto favicon_png = Gfx::PNGWriter::encode(*favicon); !favicon_png.is_error())
- m_favicon_hash = m_session->favicon_store->add_favicon(favicon_png.release_value());
-
- if (m_favicon_hash.has_value()) {
- m_session->history_store->update_favicon(url(), *m_favicon_hash);
- }
- }
-
if (on_favicon_change)
on_favicon_change(favicon);
}
@@ -821,7 +805,7 @@ void ViewImplementation::did_finish_history_traversal(Web::HTML::CrossProcessId
dump_session_history("webcontent-history-traversal-complete"sv);
}
-Vector<ViewImplementation::SessionHistoryTraversalMenuItem> ViewImplementation::session_history_traversal_menu_items(int direction) const
+Vector<ViewImplementation::SessionHistoryTraversalItem> ViewImplementation::session_history_traversal_items(int direction) const
{
VERIFY(direction == -1 || direction == 1);
@@ -829,21 +813,10 @@ Vector<ViewImplementation::SessionHistoryTraversalMenuItem> ViewImplementation::
auto used_steps = session_history.used_steps();
auto current_used_step_index = session_history.current_used_step_index();
- Vector<SessionHistoryTraversalMenuItem> items;
+ Vector<SessionHistoryTraversalItem> items;
auto append_item = [&](size_t target_step_index) {
auto target_step = used_steps[target_step_index];
- auto const& target_entry = *session_history.top_level_entry_for_step(target_step);
- auto history_entry = m_session->history_store->entry_for_url(target_entry.url);
- auto url = target_entry.url.serialize();
- auto title = history_entry.has_value() && history_entry->title.has_value() && !history_entry->title->is_empty()
- ? move(*history_entry->title)
- : url;
- items.append({
- target_step,
- move(title),
- move(url),
- history_entry.has_value() ? move(history_entry->favicon_png) : OptionalNone {},
- });
+ items.append({ target_step, session_history.top_level_entry_for_step(target_step)->url });
};
if (direction < 0) {
diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.h
index 1a213954ca4..507764e566a 100644
--- a/Libraries/LibWebView/ViewImplementation.h
+++ b/Libraries/LibWebView/ViewImplementation.h
@@ -220,7 +220,6 @@ public:
Utf16String const& title() const { return m_title; }
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; }
@@ -258,11 +257,9 @@ public:
Optional<ByteString> crash_report_name() const;
Optional<String> crash_report_website() const;
- struct SessionHistoryTraversalMenuItem {
+ struct SessionHistoryTraversalItem {
i32 step { 0 };
- String title;
- String url;
- Optional<ByteBuffer> favicon_png;
+ URL::URL url;
};
static Web::UIEvents::KeyModifier history_traversal_key_modifier();
void traverse_the_history_by_delta(
@@ -273,8 +270,7 @@ public:
i32 step,
CheckForCancelation = CheckForCancelation::Yes,
Function<void()> on_ready = nullptr);
- [[nodiscard]] Vector<SessionHistoryTraversalMenuItem> session_history_traversal_menu_items(int direction) const;
- Vector<HistoryEntry> recent_history_entries(size_t limit) const;
+ [[nodiscard]] Vector<SessionHistoryTraversalItem> session_history_traversal_items(int direction) const;
[[nodiscard]] SessionHistorySnapshot session_history_snapshot() const;
[[nodiscard]] ErrorOr<void> restore_session_history_from_snapshot(SessionHistorySnapshot);
@@ -717,6 +713,10 @@ public:
virtual void did_change_session_history(SessionHistorySnapshot const&, URL::URL const&) { }
+ // The application keeps browsing history: this view visited a page, or learned the title of one it visited.
+ virtual void did_visit_page(URL::URL const&, Optional<String> const&, HistoryVisitTransition) { }
+ virtual void did_change_visited_page_title(URL::URL const&, String const&) { }
+
bool can_navigate_back() const { return m_can_navigate_back; }
bool can_navigate_forward() const { return m_can_navigate_forward; }
@@ -899,7 +899,6 @@ protected:
URL::URL m_displayed_url { URL::about_blank() };
bool m_text_fragment_indication_is_visible { false };
Utf16String m_title;
- Optional<String> m_favicon_hash;
struct CrashState {
URL::URL failed_url;
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index 3d86d3d326e..5aecd31d5ec 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -446,10 +446,10 @@ void WebContentPage::maybe_record_history_visit_for_current_load(URL::URL const&
// Title and favicon updates already give us a useful history entry, so
// do not wait for did_finish_loading() on pages that never reach it.
- auto transition = HistoryVisitTransition::Link;
- if (displays_tab())
- transition = view().m_history_visit_transition_for_current_load;
- client().session().history_store->record_visit(url, move(title), UnixDateTime::now(), transition);
+ // NB: Only a page that shows a tab has a view to tell the application through.
+ if (!displays_tab())
+ return;
+ view().did_visit_page(url, title, view().m_history_visit_transition_for_current_load);
m_history_recorded_url_for_current_load = normalized_url.release_value();
}
@@ -2940,9 +2940,7 @@ void WebContentPage::did_finish_loading(Web::HTML::CrossProcessId navigable_id,
maybe_record_history_visit_for_current_load(committed_url, title, "load finish"sv);
if (title.has_value())
- client().session().history_store->update_title(committed_url, *title);
- if (view().favicon_hash().has_value())
- client().session().history_store->update_favicon(committed_url, *view().favicon_hash());
+ view().did_change_visited_page_title(committed_url, *title);
view().did_finish_navigation();
@@ -2971,7 +2969,7 @@ void WebContentPage::did_change_title(Utf16String title)
view().url(),
title_utf8);
- client().session().history_store->update_title(view().url(), title_utf8);
+ view().did_change_visited_page_title(view().url(), title_utf8);
}
if (title.is_empty())
diff --git a/Libraries/LibWebView/WebUI.cpp b/Libraries/LibWebView/WebUI.cpp
index 74ce88be6fc..11fa4cb934e 100644
--- a/Libraries/LibWebView/WebUI.cpp
+++ b/Libraries/LibWebView/WebUI.cpp
@@ -13,7 +13,6 @@
#include <LibWebView/WebUI/ApplicationWebUI.h>
#include <LibWebView/WebUI/CrashReportsUI.h>
#include <LibWebView/WebUI/DownloadsUI.h>
-#include <LibWebView/WebUI/HistoryUI.h>
#include <LibWebView/WebUI/SettingsUI.h>
#include <LibWebView/WebUI/VersionUI.h>
@@ -24,7 +23,6 @@ static constexpr auto s_pages = to_array<WebUI::Page>({
{ "blocking"sv, "Blocking"sv, WebUI::PageType::Static },
{ "crashes"sv, "Crash Reports"sv, WebUI::PageType::Dynamic },
{ "downloads"sv, "Downloads"sv, WebUI::PageType::Dynamic },
- { "history"sv, "History"sv, WebUI::PageType::Dynamic },
{ "newtab"sv, "New Tab"sv, WebUI::PageType::Static },
{ "settings"sv, "Settings"sv, WebUI::PageType::Dynamic },
{ "services"sv, "Services"sv, WebUI::PageType::Static },
@@ -101,8 +99,6 @@ ErrorOr<RefPtr<WebUI>> WebUI::create(WebContentClient& client, Web::PageId page_
web_ui = TRY(create_web_ui<CrashReportsUI>(client, page_id, move(host)));
else if (page->host == "downloads"sv)
web_ui = TRY(create_web_ui<DownloadsUI>(client, page_id, move(host)));
- else if (page->host == "history"sv)
- web_ui = TRY(create_web_ui<HistoryUI>(client, page_id, move(host)));
else if (page->host.is_one_of("settings"sv, "welcome"sv))
web_ui = TRY(create_web_ui<SettingsUI>(client, page_id, move(host)));
else if (page->host == "version"sv)
diff --git a/Libraries/LibWebView/WebUI/HistoryUI.h b/Libraries/LibWebView/WebUI/HistoryUI.h
deleted file mode 100644
index 787f04e9440..00000000000
--- a/Libraries/LibWebView/WebUI/HistoryUI.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (c) 2026, Tim Flynn <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <LibWebView/WebUI.h>
-
-namespace WebView {
-
-class HistoryUI final : public WebUI {
- WEB_UI(HistoryUI);
-
-private:
- virtual void register_interfaces() override;
-
- void load_history_entries(JsonValue const&);
- void remove_history_entry(JsonValue const&);
- void forget_history_site(JsonValue const&);
-};
-
-}
diff --git a/Services/Hub/Application.cpp b/Services/Hub/Application.cpp
index 78edb636f1c..640b3391c92 100644
--- a/Services/Hub/Application.cpp
+++ b/Services/Hub/Application.cpp
@@ -129,24 +129,6 @@ Optional<WebView::ViewImplementation&> Application::open_blank_new_tab(Web::HTML
return view;
}
-void Application::read_keeps_omnibox_engagements(URL::URL const& url, Function<void(bool)> on_read) const
-{
- auto* ui = ConnectionFromUI::the();
- if (!ui) {
- on_read(false);
- return;
- }
- auto request_id = m_next_ui_request_id++;
- m_pending_omnibox_engagement_reads.set(request_id, move(on_read));
- ui->async_app_read_keeps_omnibox_engagements(request_id, url);
-}
-
-void Application::did_read_keeps_omnibox_engagements(u64 request_id, bool keeps_engagements)
-{
- if (auto on_read = m_pending_omnibox_engagement_reads.take(request_id); on_read.has_value())
- (*on_read)(keeps_engagements);
-}
-
// NB: Which window a tab goes to must not depend on what is active once the UI reads the message. A tab must stay in
// the browsing session of the page that opened it. With no such page, the active view here is the one that was
// active when the UI sent what led to this, since the UI's messages arrive in order.
diff --git a/Services/Hub/Application.h b/Services/Hub/Application.h
index 06696ce59cd..ccf2fe59178 100644
--- a/Services/Hub/Application.h
+++ b/Services/Hub/Application.h
@@ -66,7 +66,6 @@ public:
void did_resolve_external_url_handler(u64 request_id, Optional<u64> handler_id, String application_name, bool is_ladybird);
void launch_external_url(u64 handler_id, URL::URL const&, Function<void(bool)>) const;
void did_launch_external_url(u64 request_id, bool launched);
- void did_read_keeps_omnibox_engagements(u64 request_id, bool keeps_engagements);
void did_read_clipboard_text(u64 request_id, Utf16String);
void did_read_clipboard_item(u64 request_id, Web::Clipboard::SystemClipboardItem);
void did_get_download_path(u64 request_id, Optional<ByteString>);
@@ -81,7 +80,6 @@ private:
virtual void create_platform_arguments(Core::ArgsParser&) override;
virtual Optional<WebView::ViewImplementation&> active_web_view() const override;
virtual Optional<WebView::ViewImplementation&> open_blank_new_tab(Web::HTML::ActivateTab, WebView::ViewImplementation const* related_view = nullptr) const override;
- virtual void read_keeps_omnibox_engagements(URL::URL const&, Function<void(bool)> on_read) const override;
virtual void open_url_in_new_tab(URL::URL const&, Web::HTML::ActivateTab, WebView::ViewImplementation const* source_view = nullptr) const override;
virtual void activate_or_open_tab_with_url(URL::URL const&) const override;
virtual void open_urls_in_new_tabs(ReadonlySpan<URL::URL>) const override;
@@ -148,7 +146,6 @@ private:
NewTabSource new_tab_source(WebView::ViewImplementation const* source_view) const;
mutable u64 m_next_ui_request_id { 1 };
- mutable HashMap<u64, Function<void(bool)>> m_pending_omnibox_engagement_reads;
};
}
diff --git a/Services/Hub/ConnectionFromUI.cpp b/Services/Hub/ConnectionFromUI.cpp
index 669494dcaec..d90f08a5494 100644
--- a/Services/Hub/ConnectionFromUI.cpp
+++ b/Services/Hub/ConnectionFromUI.cpp
@@ -13,7 +13,6 @@
#include <LibRequests/RequestClient.h>
#include <LibWebView/BrowsingSession.h>
#include <LibWebView/CrashReportStore.h>
-#include <LibWebView/HistoryStore.h>
#include <LibWebView/MicrophoneAuthorizer.h>
#include <LibWebView/PageTranslation.h>
#include <LibWebView/ProcessSnapshot.h>
@@ -506,19 +505,6 @@ void ConnectionFromUI::open_microphone_system_settings()
static_cast<WebView::Application&>(Application::the()).microphone_authorizer().open_system_settings();
}
-void ConnectionFromUI::favicons_in_use(Vector<String> favicon_hashes)
-{
- HashTable<String> referenced_hashes;
- for (auto& favicon_hash : favicon_hashes)
- referenced_hashes.set(move(favicon_hash));
- Application::the().remove_unreferenced_favicons(move(referenced_hashes));
-}
-
-void ConnectionFromUI::answer_keeps_omnibox_engagements(u64 request_id, bool keeps_engagements)
-{
- Application::the().did_read_keeps_omnibox_engagements(request_id, keeps_engagements);
-}
-
void ConnectionFromUI::add_web_ui_page(String host, String title)
{
WebView::WebUI::add_application_page(move(host), move(title));
@@ -530,15 +516,6 @@ void ConnectionFromUI::send_web_ui_message(u64 web_ui_id, String name, JsonValue
web_ui->send_to_page(name, data);
}
-Messages::HubServer::FaviconsResponse ConnectionFromUI::favicons(Vector<String> favicon_hashes)
-{
- Vector<Optional<ByteBuffer>> favicon_pngs;
- favicon_pngs.ensure_capacity(favicon_hashes.size());
- for (auto const& favicon_hash : favicon_hashes)
- favicon_pngs.unchecked_append(Application::default_session().favicon_store->favicon_png(favicon_hash));
- return favicon_pngs;
-}
-
Messages::HubServer::InitializeResponse ConnectionFromUI::initialize()
{
auto const& options = Application::browser_options();
@@ -559,6 +536,7 @@ Messages::HubServer::InitializeResponse ConnectionFromUI::initialize()
state.config_directory = profile.paths().config;
state.data_directory = profile.paths().data;
state.persists_sessions = Application::the().persists_sessions();
+ state.uses_sql_database = options.disable_sql_database == WebView::DisableSQLDatabase::No;
state.profile_identifier = profile.identifier();
state.profile_identity = profile.paths().identity;
state.profile_is_temporary = profile.is_temporary();
@@ -730,18 +708,11 @@ Messages::HubServer::ViewNeedsBeforeunloadCheckResponse ConnectionFromUI::view_n
return view && view->needs_beforeunload_check();
}
-Messages::HubServer::ViewRecentHistoryEntriesResponse ConnectionFromUI::view_recent_history_entries(u64 view_id, u64 limit)
-{
- if (auto* view = find_view(view_id))
- return view->recent_history_entries(limit);
- return Vector<WebView::HistoryEntry> {};
-}
-
-Messages::HubServer::ViewSessionHistoryTraversalMenuItemsResponse ConnectionFromUI::view_session_history_traversal_menu_items(u64 view_id, i32 direction)
+Messages::HubServer::ViewSessionHistoryTraversalItemsResponse ConnectionFromUI::view_session_history_traversal_items(u64 view_id, i32 direction)
{
if (auto* view = find_view(view_id))
- return view->session_history_traversal_menu_items(direction);
- return Vector<WebView::ViewImplementation::SessionHistoryTraversalMenuItem> {};
+ return view->session_history_traversal_items(direction);
+ return Vector<WebView::ViewImplementation::SessionHistoryTraversalItem> {};
}
Messages::HubServer::ViewSessionHistorySnapshotResponse ConnectionFromUI::view_session_history_snapshot(u64 view_id)
@@ -785,11 +756,6 @@ Messages::HubServer::ViewPageDescriptionResponse ConnectionFromUI::view_page_des
return { move(page.url), move(page.user_agent), page.viewport_size, page.device_pixel_ratio, page.zoom_level };
}
-Messages::HubServer::HistoryEntryForUrlResponse ConnectionFromUI::history_entry_for_url(WebView::IsPrivate is_private, URL::URL url)
-{
- return Application::session_for_new_view(is_private)->history_store->entry_for_url(url);
-}
-
void ConnectionFromUI::update_settings(u64 change_id, ByteString changes_json)
{
auto changes = JsonValue::from_string(changes_json);
diff --git a/Services/Hub/ConnectionFromUI.h b/Services/Hub/ConnectionFromUI.h
index 5bea69ba13e..19fe43b7f6c 100644
--- a/Services/Hub/ConnectionFromUI.h
+++ b/Services/Hub/ConnectionFromUI.h
@@ -61,12 +61,9 @@ private:
// ^HubServerEndpoint
virtual Messages::HubServer::InitializeResponse initialize() override;
- virtual Messages::HubServer::FaviconsResponse favicons(Vector<String> favicon_hashes) override;
virtual Messages::HubServer::CreateViewResponse create_view(Hub::NewViewRequest request) override;
virtual Messages::HubServer::ViewDescriptionResponse view_description(u64 view_id) override;
virtual void ui_did_start() override;
- virtual void favicons_in_use(Vector<String> favicon_hashes) override;
- virtual void answer_keeps_omnibox_engagements(u64 request_id, bool keeps_engagements) override;
virtual void add_web_ui_page(String host, String title) override;
virtual void send_web_ui_message(u64 web_ui_id, String name, JsonValue data) override;
virtual void post_report(u64 post_id, URL::URL url, Vector<HTTP::Header> headers, ByteString body) override;
@@ -89,14 +86,12 @@ private:
virtual Messages::HubServer::ProcessSnapshotsResponse process_snapshots() override;
virtual Messages::HubServer::TerminateProcessResponse terminate_process(u64 child_id) override;
virtual Messages::HubServer::ViewNeedsBeforeunloadCheckResponse view_needs_beforeunload_check(u64 view_id) override;
- virtual Messages::HubServer::ViewRecentHistoryEntriesResponse view_recent_history_entries(u64 view_id, u64 limit) override;
- virtual Messages::HubServer::ViewSessionHistoryTraversalMenuItemsResponse view_session_history_traversal_menu_items(u64 view_id, i32 direction) override;
+ virtual Messages::HubServer::ViewSessionHistoryTraversalItemsResponse view_session_history_traversal_items(u64 view_id, i32 direction) override;
virtual Messages::HubServer::ViewSessionHistorySnapshotResponse view_session_history_snapshot(u64 view_id) override;
virtual Messages::HubServer::ViewRestoreSessionHistoryFromSnapshotResponse view_restore_session_history_from_snapshot(u64 view_id, WebView::SessionHistorySnapshot snapshot) override;
virtual Messages::HubServer::ViewHistoryStepAtDeltaResponse view_history_step_at_delta(u64 view_id, i32 delta) override;
virtual Messages::HubServer::ViewLookUpSelectedTextAtResponse view_look_up_selected_text_at(u64 view_id, Gfx::IntPoint position) override;
virtual Messages::HubServer::ViewPageDescriptionResponse view_page_description(u64 view_id) override;
- virtual Messages::HubServer::HistoryEntryForUrlResponse history_entry_for_url(WebView::IsPrivate is_private, URL::URL url) override;
virtual void view_set_site_permission(u64 view_id, URL::Origin origin, Web::Permissions::PermissionName name, Optional<WebView::PermissionDecision> decision) override;
virtual void view_did_show_permission_prompt(u64 view_id, WebView::PermissionPromptRequest request) override;
virtual void view_load_navigation(u64 view_id, Web::HTML::PreparedNavigationDescriptor navigation) override;
diff --git a/Services/Hub/HubClient.ipc b/Services/Hub/HubClient.ipc
index 67253b73b43..dbaeca2c323 100644
--- a/Services/Hub/HubClient.ipc
+++ b/Services/Hub/HubClient.ipc
@@ -23,6 +23,7 @@
#include <LibWebView/Autocomplete.h>
#include <LibWebView/ContextMenuRequest.h>
#include <LibWebView/FileDownloader.h>
+#include <LibWebView/HistoryStore.h>
#include <LibWebView/SessionHistory.h>
#include <LibWebView/TabPerformanceStats.h>
#include <LibWebCommon/Clipboard/SystemClipboard.h>
@@ -144,6 +145,7 @@ struct Hub::InitialState {
ByteString config_directory;
ByteString data_directory;
bool persists_sessions;
+ bool uses_sql_database;
String user_agent;
Web::NavigatorCompatibilityMode navigator_compatibility_mode;
bool scripting_enabled;
@@ -190,7 +192,6 @@ struct Hub::ViewState {
URL::URL url;
URL::URL displayed_url;
Utf16String title;
- Optional<String> favicon_hash;
String handle;
bool is_loading;
bool crash_overlay_active;
@@ -281,12 +282,13 @@ endpoint HubClient
app_read_clipboard_item(u64 request_id) =|
app_ask_user_for_download_path(u64 request_id, ByteString file) =|
settings_changed(ByteString settings_json, u64 last_applied_change_id) =|
- app_read_keeps_omnibox_engagements(u64 request_id, URL::URL url) =|
web_ui_opened(u64 web_ui_id, String host) =|
web_ui_message(u64 web_ui_id, String name, JsonValue data) =|
web_ui_closed(u64 web_ui_id) =|
view_request_context_menu(u64 view_id, WebView::ContextMenuRequest request) =|
view_session_history_changed(u64 view_id, WebView::SessionHistorySnapshot history, URL::URL url) =|
+ view_visited_page(u64 view_id, URL::URL url, Optional<String> title, WebView::HistoryVisitTransition transition) =|
+ view_visited_page_title_change(u64 view_id, URL::URL url, String title) =|
view_did_make_link_to_highlight(u64 view_id, Optional<URL::URL> url) =|
view_favicon_change(u64 view_id, Optional<Gfx::ShareableBitmap> favicon) =|
view_request_before_unload(u64 view_id, u64 answer_id, String source) =|
diff --git a/Services/Hub/HubServer.ipc b/Services/Hub/HubServer.ipc
index 6309ff775ba..3ac5e125762 100644
--- a/Services/Hub/HubServer.ipc
+++ b/Services/Hub/HubServer.ipc
@@ -64,26 +64,9 @@ struct WebView::OmniboxEngagement {
}
[ExistingCpp]
-struct WebView::HistoryEntry {
- String url;
- Optional<String> title;
- Optional<ByteBuffer> favicon_png;
- i64 visit_count;
- i64 direct_visit_count;
- UnixDateTime last_visited_time;
- UnixDateTime last_qualifying_visit_time;
- UnixDateTime last_direct_visit_time;
- double decayed_visit_score;
- double decayed_direct_score;
- UnixDateTime score_updated_at;
-}
-
-[ExistingCpp]
-struct WebView::ViewImplementation::SessionHistoryTraversalMenuItem {
+struct WebView::ViewImplementation::SessionHistoryTraversalItem {
i32 step;
- String title;
- String url;
- Optional<ByteBuffer> favicon_png;
+ URL::URL url;
}
[ExistingCpp]
@@ -91,7 +74,6 @@ struct WebView::ProcessPageSnapshot {
u64 view_id;
URL::URL url;
WebView::ProcessPageKind kind;
- Optional<String> favicon_hash;
}
[ExistingCpp]
@@ -141,11 +123,8 @@ endpoint HubServer
create_view(Hub::NewViewRequest request) => (u64 view_id, Hub::ViewState state)
view_description(u64 view_id) => (Hub::ViewState state)
ui_did_start() =|
- favicons_in_use(Vector<String> favicon_hashes) =|
- answer_keeps_omnibox_engagements(u64 request_id, bool keeps_engagements) =|
add_web_ui_page(String host, String title) =|
send_web_ui_message(u64 web_ui_id, String name, JsonValue data) =|
- favicons(Vector<String> favicon_hashes) => (Vector<Optional<ByteBuffer>> favicon_pngs)
post_report(u64 post_id, URL::URL url, Vector<HTTP::Header> headers, ByteString body) =|
cancel_report_post(u64 post_id) =|
@@ -169,15 +148,13 @@ endpoint HubServer
terminate_process(u64 child_id) => (bool terminated)
view_needs_beforeunload_check(u64 view_id) => (bool needs_check)
- view_recent_history_entries(u64 view_id, u64 limit) => (Vector<WebView::HistoryEntry> entries)
- view_session_history_traversal_menu_items(u64 view_id, i32 direction) => (Vector<WebView::ViewImplementation::SessionHistoryTraversalMenuItem> items)
+ view_session_history_traversal_items(u64 view_id, i32 direction) => (Vector<WebView::ViewImplementation::SessionHistoryTraversalItem> items)
view_session_history_snapshot(u64 view_id) => (Optional<WebView::SessionHistorySnapshot> snapshot)
view_restore_session_history_from_snapshot(u64 view_id, WebView::SessionHistorySnapshot snapshot) => (bool restored)
view_history_step_at_delta(u64 view_id, i32 delta) => (Optional<i32> step)
view_look_up_selected_text_at(u64 view_id, Gfx::IntPoint position) => (bool looked_up)
view_page_description(u64 view_id) => (URL::URL url, String user_agent, Gfx::IntSize viewport_size, double device_pixel_ratio, double zoom_level)
- history_entry_for_url(WebView::IsPrivate is_private, URL::URL url) => (Optional<WebView::HistoryEntry> entry)
view_set_site_permission(u64 view_id, URL::Origin origin, Web::Permissions::PermissionName name, Optional<WebView::PermissionDecision> decision) =|
view_did_show_permission_prompt(u64 view_id, WebView::PermissionPromptRequest request) =|
view_load_navigation(u64 view_id, Web::HTML::PreparedNavigationDescriptor navigation) =|
diff --git a/Services/Hub/View.cpp b/Services/Hub/View.cpp
index 84a0baf4572..8709ae1f6d3 100644
--- a/Services/Hub/View.cpp
+++ b/Services/Hub/View.cpp
@@ -612,7 +612,6 @@ ViewState View::current_state() const
state.url = url();
state.displayed_url = displayed_url();
state.title = title();
- state.favicon_hash = favicon_hash();
state.handle = handle();
state.is_loading = is_loading();
state.zoom_level = zoom_level();
@@ -718,4 +717,16 @@ void View::did_change_session_history(WebView::SessionHistorySnapshot const& his
ui->async_view_session_history_changed(view_id(), history, url);
}
+void View::did_visit_page(URL::URL const& url, Optional<String> const& title, WebView::HistoryVisitTransition transition)
+{
+ if (auto* ui = ConnectionFromUI::the())
+ ui->async_view_visited_page(view_id(), url, title, transition);
+}
+
+void View::did_change_visited_page_title(URL::URL const& url, String const& title)
+{
+ if (auto* ui = ConnectionFromUI::the())
+ ui->async_view_visited_page_title_change(view_id(), url, title);
+}
+
}
diff --git a/Services/Hub/View.h b/Services/Hub/View.h
index 6c6994ea5f3..70ab13ca9da 100644
--- a/Services/Hub/View.h
+++ b/Services/Hub/View.h
@@ -66,6 +66,8 @@ private:
virtual void did_request_context_menu(WebView::ContextMenuRequest) override;
virtual void did_make_link_to_highlight(Optional<URL::URL>) override;
virtual void did_change_session_history(WebView::SessionHistorySnapshot const&, URL::URL const&) override;
+ virtual void did_visit_page(URL::URL const&, Optional<String> const& title, WebView::HistoryVisitTransition) override;
+ virtual void did_change_visited_page_title(URL::URL const&, String const&) override;
virtual void read_clipboard_item(Function<void(Web::Clipboard::SystemClipboardItem)>) const override;
virtual void did_accept_presented_backing_store(i32 bitmap_id, Gfx::IntRect damage_rect) override;
// NB: The UI hands a backing store back, once it no longer shows what is in it.
diff --git a/Tests/LibWebView/TestApplicationDestruction.cpp b/Tests/LibWebView/TestApplicationDestruction.cpp
index 76a4e3ba7e9..15854f69f65 100644
--- a/Tests/LibWebView/TestApplicationDestruction.cpp
+++ b/Tests/LibWebView/TestApplicationDestruction.cpp
@@ -137,7 +137,7 @@ TEST_CASE(application_destruction_with_pending_web_ui_callbacks)
{
auto app = TRY_OR_FAIL(environment.create_application());
auto theme = TRY_OR_FAIL(load_test_theme());
- for (auto host : { "settings"sv, "history"sv, "downloads"sv }) {
+ for (auto host : { "settings"sv, "crashes"sv, "downloads"sv }) {
for (bool retained_by_callback : { false, true }) {
auto view = WebView::HeadlessWebView::create(theme, { 1000, 700 });
auto& page = view->page();
diff --git a/Tests/LibWebView/TestBrowserHistoryTraversal.cpp b/Tests/LibWebView/TestBrowserHistoryTraversal.cpp
index 816078260f6..d2d28467579 100644
--- a/Tests/LibWebView/TestBrowserHistoryTraversal.cpp
+++ b/Tests/LibWebView/TestBrowserHistoryTraversal.cpp
@@ -165,7 +165,7 @@ TEST_CASE(browser_history_traversal)
view->load(url_d);
wait_until_at(url_d);
- auto back_menu_items = view->session_history_traversal_menu_items(-1);
+ auto back_menu_items = view->session_history_traversal_items(-1);
VERIFY(back_menu_items.size() == 3);
VERIFY(back_menu_items[0].step == 2);
VERIFY(back_menu_items[1].step == 1);
diff --git a/Tests/LibWebView/TestOmnibox.cpp b/Tests/LibWebView/TestOmnibox.cpp
index e20c4e7a663..111dcffe29e 100644
--- a/Tests/LibWebView/TestOmnibox.cpp
+++ b/Tests/LibWebView/TestOmnibox.cpp
@@ -205,7 +205,6 @@ TEST_CASE(all_web_ui_pages_are_suggested)
"about:blocking"sv,
"about:crashes"sv,
"about:downloads"sv,
- "about:history"sv,
"about:newtab"sv,
"about:settings"sv,
"about:services"sv,
diff --git a/Tests/UI/Qt/TestProcessManagerWindow.cpp b/Tests/UI/Qt/TestProcessManagerWindow.cpp
index b326146774c..c907cbf931b 100644
--- a/Tests/UI/Qt/TestProcessManagerWindow.cpp
+++ b/Tests/UI/Qt/TestProcessManagerWindow.cpp
@@ -38,6 +38,8 @@ static Ladybird::ProcessManagerWindow::Source source_for(WebView::ProcessManager
return {
.take_snapshots = [&manager] { return WebView::process_snapshots(manager); },
.end_process = [&manager](u64 child_id) { return WebView::end_process(manager, child_id); },
+ .favicon_hash = {},
+ .favicon_png = {},
};
}
diff --git a/UI/Qt/Application.cpp b/UI/Qt/Application.cpp
index b173c4ea48f..5a74b0db91e 100644
--- a/UI/Qt/Application.cpp
+++ b/UI/Qt/Application.cpp
@@ -20,6 +20,8 @@
#include <LibWebCommon/WebView/Utilities.h>
#include <LibWebView/CanonicalTraversable.h>
#include <LibWebView/CrashReportStore.h>
+#include <LibWebView/FaviconStore.h>
+#include <LibWebView/HistoryStore.h>
#include <LibWebView/NotificationBackend.h>
#include <LibWebView/PageTranslation.h>
#include <LibWebView/PictureInPictureManager.h>
@@ -49,6 +51,7 @@
#include <UI/Qt/ChromeLayout.h>
#include <UI/Qt/EventLoopImplementationQt.h>
#include <UI/Qt/ExternalURLHandler.h>
+#include <UI/Qt/HistoryPage.h>
#include <UI/Qt/Menu.h>
#include <UI/Qt/PictureInPictureWindow.h>
#include <UI/Qt/PlainText.h>
@@ -800,6 +803,7 @@ ErrorOr<void> Application::connect_to_hub(Main::Arguments const& arguments)
m_settings = make<WebView::Settings>(WebView::Settings::create_from_json(TRY(JsonValue::from_string(state.settings_json))));
m_bookmark_store = make<BookmarkStore>(BookmarkStore::create(LexicalPath::join(state.config_directory, "Bookmarks.json"sv).string()));
create_session_store(state.data_directory, state.persists_sessions);
+ create_history_store(state.data_directory, state.uses_sql_database);
// NB: Reports stay in files, which both of us read. This process keeps its own for when it crashes, and the next
// launch recovers that the same as one of the Hub's.
auto& crash_report_store = WebView::CrashReportStore::the();
@@ -964,6 +968,16 @@ void Application::show_process_manager()
.take_snapshots = [] { return WebView::process_snapshots(WebView::Application::process_manager()); },
.end_process = [](u64 child_id) { return WebView::end_process(WebView::Application::process_manager(), child_id); },
#endif
+ .favicon_hash = [](WebView::ProcessPageSnapshot const& page) -> Optional<String> {
+ if (auto* view = RemoteView::find(page.view_id))
+ return view->favicon_hash();
+ return {};
+ },
+ .favicon_png = [](String const& favicon_hash) {
+ // NB: A private window's favicons are in a store of their own, which the hash finds as well.
+ if (auto png = favicon_store(WebView::IsPrivate::No).favicon_png(favicon_hash); png.has_value())
+ return png;
+ return favicon_store(WebView::IsPrivate::Yes).favicon_png(favicon_hash); },
});
#if defined(AK_OS_MACOS)
// The traffic lights are centered in the Task Manager's title bar, which is 52 px tall.
@@ -988,6 +1002,7 @@ void Application::create_platform_actions()
m_bookmark_store = make<BookmarkStore>(BookmarkStore::create(LexicalPath::join(WebView::Application::profile().paths().config, "Bookmarks.json"sv).string()));
auto& hub = WebView::Application::the();
create_session_store(WebView::Application::profile().paths().data, hub.persists_sessions());
+ create_history_store(WebView::Application::profile().paths().data, WebView::Application::browser_options().disable_sql_database == WebView::DisableSQLDatabase::No);
m_application_actions = make<ApplicationActions>(ApplicationActions::PageOptions {
.user_agent = hub.user_agent_string(),
.navigator_compatibility_mode = hub.navigator_compatibility_mode(),
@@ -1004,6 +1019,8 @@ void Application::create_platform_actions()
hub->send_settings_changes(settings);
};
m_bookmarks = make<Bookmarks>(*m_bookmark_store);
+ if (auto* hub = HubConnection::the_if_connected())
+ hub->async_add_web_ui_page("history"_string, "History"_string);
m_open_task_manager_action = WebView::Action::create("Open Task Manager"sv, WebView::ActionID::OpenTaskManager, [this]() {
show_process_manager();
@@ -1243,6 +1260,81 @@ void Application::create_session_store(ByteString const& data_directory, bool pe
#endif
}
+void Application::create_history_store(ByteString const& data_directory, bool uses_sql_database)
+{
+ if (!uses_sql_database) {
+ m_favicon_store = WebView::FaviconStore::create();
+ m_history_store = WebView::HistoryStore::create_disabled();
+ return;
+ }
+
+ auto created = [&]() -> ErrorOr<bool> {
+ // The History database is shared by the favicon and history stores. Preflight both before applying either
+ // migration so a database that is too new remains untouched.
+ auto database = TRY(Database::Database::create(data_directory, "History"sv));
+ auto favicons_outcome = TRY(WebView::FaviconStore::migrate_schema(database, Database::MigrationMode::CheckOnly));
+ auto history_outcome = TRY(WebView::HistoryStore::migrate_schema(database, Database::MigrationMode::CheckOnly));
+ if (favicons_outcome != Database::MigrationOutcome::Success || history_outcome != Database::MigrationOutcome::Success)
+ return false;
+ if (TRY(WebView::FaviconStore::migrate_schema(database)) != Database::MigrationOutcome::Success)
+ return false;
+ if (TRY(WebView::HistoryStore::migrate_schema(database)) != Database::MigrationOutcome::Success)
+ return false;
+ m_favicon_store = TRY(WebView::FaviconStore::create(database));
+ m_history_store = TRY(WebView::HistoryStore::create(database));
+ return true;
+ }();
+ if (!created.is_error() && created.value()) {
+ m_should_remove_unreferenced_favicons = true;
+ return;
+ }
+
+ if (created.is_error())
+ dbgln("Unable to open the History database: {}", created.error());
+ else
+ dbgln("History database was created by a newer Ladybird version; favicons and history will not be persisted this session");
+ m_favicon_store = WebView::FaviconStore::create();
+ m_history_store = WebView::HistoryStore::create(*m_favicon_store);
+}
+
+WebView::FaviconStore& Application::favicon_store(WebView::IsPrivate is_private)
+{
+ if (is_private == WebView::IsPrivate::No)
+ return *s_the->m_favicon_store;
+ if (!s_the->m_private_favicon_store)
+ s_the->m_private_favicon_store = WebView::FaviconStore::create();
+ return *s_the->m_private_favicon_store;
+}
+
+// NB: The favicons of history and of bookmarks share a store, so it is only once the bookmarks are read that the
+// ones nothing uses any more are known.
+void Application::remove_unreferenced_favicons(HashTable<String> referenced_hashes)
+{
+ if (!m_should_remove_unreferenced_favicons)
+ return;
+ m_should_remove_unreferenced_favicons = false;
+
+ for (auto& hash : m_history_store->referenced_favicon_hashes())
+ referenced_hashes.set(move(hash));
+ m_favicon_store->remove_unreferenced_favicons(referenced_hashes);
+}
+
+void Application::history_page_opened(u64 web_ui_id)
+{
+ m_history_pages.set(web_ui_id, make<HistoryPage>(web_ui_id));
+}
+
+void Application::history_page_received_message(u64 web_ui_id, String const& name, JsonValue const& data)
+{
+ if (auto page = m_history_pages.get(web_ui_id); page.has_value())
+ (*page)->received_message(name, data);
+}
+
+void Application::history_page_closed(u64 web_ui_id)
+{
+ m_history_pages.remove(web_ui_id);
+}
+
SessionStore& Application::session_store(WebView::IsPrivate is_private)
{
if (is_private == WebView::IsPrivate::No)
@@ -1256,6 +1348,7 @@ SessionStore& Application::session_store(WebView::IsPrivate is_private)
void Application::did_clear_history_since(UnixDateTime since)
{
+ m_history_store->remove_entries_accessed_since(since);
for (auto* store : { m_session_store.ptr(), m_private_session_store.ptr() }) {
if (!store)
continue;
@@ -1493,6 +1586,7 @@ void Application::finish_private_session_restart()
view.clear_session_tab_id();
});
m_private_session_store = nullptr;
+ m_private_favicon_store = nullptr;
open_new_window(WebView::IsPrivate::Yes);
for (auto const& window : windows) {
diff --git a/UI/Qt/Application.h b/UI/Qt/Application.h
index dde3cfa8641..084d85a6ec3 100644
--- a/UI/Qt/Application.h
+++ b/UI/Qt/Application.h
@@ -32,6 +32,8 @@ class QWidget;
namespace Ladybird {
+class HistoryPage;
+
class Bookmarks;
class ProcessManagerWindow;
@@ -91,6 +93,15 @@ public:
// The windows and tabs of each kind of window, which this run keeps for the next one unless they are private.
static SessionStore& session_store(WebView::IsPrivate);
+ // Browsing history and the favicons it, the bookmarks and the open tabs show. Private windows keep no history.
+ static WebView::HistoryStore& history_store() { return *s_the->m_history_store; }
+ static WebView::FaviconStore& favicon_store(WebView::IsPrivate);
+ void remove_unreferenced_favicons(HashTable<String> referenced_hashes);
+
+ void history_page_opened(u64 web_ui_id);
+ void history_page_received_message(u64 web_ui_id, String const& name, JsonValue const& data);
+ void history_page_closed(u64 web_ui_id);
+
virtual ~Application() override;
Function<void(URL::URL)> on_open_file;
@@ -267,6 +278,7 @@ private:
void on_recently_closed_entries_changed() const;
void did_clear_history_since(UnixDateTime);
void create_session_store(ByteString const& data_directory, bool persists_sessions);
+ void create_history_store(ByteString const& data_directory, bool uses_sql_database);
void quit_for_signal();
static Application* s_the;
@@ -297,6 +309,11 @@ private:
OwnPtr<BookmarkStore> m_bookmark_store;
OwnPtr<SessionStore> m_session_store;
OwnPtr<SessionStore> m_private_session_store;
+ OwnPtr<WebView::FaviconStore> m_favicon_store;
+ OwnPtr<WebView::FaviconStore> m_private_favicon_store;
+ OwnPtr<WebView::HistoryStore> m_history_store;
+ bool m_should_remove_unreferenced_favicons { false };
+ HashMap<u64, NonnullOwnPtr<HistoryPage>> m_history_pages;
Vector<int> m_session_signal_handlers;
OwnPtr<Bookmarks> m_bookmarks;
OwnPtr<ApplicationActions> m_application_actions;
diff --git a/UI/Qt/Bookmarks.cpp b/UI/Qt/Bookmarks.cpp
index c602eea6caf..a9ab9babc00 100644
--- a/UI/Qt/Bookmarks.cpp
+++ b/UI/Qt/Bookmarks.cpp
@@ -7,6 +7,7 @@
#include <LibURL/InternalURLs.h>
#include <LibURL/URL.h>
#include <LibWebView/AutocompleteRanker.h>
+#include <LibWebView/FaviconStore.h>
#include <LibWebView/URL.h>
#include <UI/Qt/Application.h>
#include <UI/Qt/Bookmarks.h>
@@ -31,14 +32,13 @@ Bookmarks::Bookmarks(BookmarkStore& store)
create_menus();
create_context_menus();
- if (auto* hub = HubConnection::the_if_connected()) {
+ if (auto* hub = HubConnection::the_if_connected())
hub->async_add_web_ui_page("bookmarks"_string, "Bookmarks"_string);
- Vector<String> favicon_hashes;
- for (auto const& favicon_hash : m_store.favicon_hashes())
- favicon_hashes.append(favicon_hash);
- hub->async_favicons_in_use(move(favicon_hashes));
- }
+ HashTable<String> favicon_hashes;
+ for (auto const& favicon_hash : m_store.favicon_hashes())
+ favicon_hashes.set(favicon_hash);
+ Application::the().remove_unreferenced_favicons(move(favicon_hashes));
}
Bookmarks::~Bookmarks() = default;
@@ -425,15 +425,8 @@ void Bookmarks::read_missing_favicons()
if (missing_hashes.is_empty())
return;
-#ifdef LADYBIRD_HUB_IN_OWN_PROCESS
- auto favicons = HubConnection::the().favicons(missing_hashes);
- VERIFY(favicons.size() == missing_hashes.size());
- for (size_t i = 0; i < missing_hashes.size(); ++i)
- m_favicons.set(missing_hashes[i], move(favicons[i]));
-#else
for (auto const& hash : missing_hashes)
- m_favicons.set(hash, WebView::Application::default_session().favicon_store->favicon_png(hash));
-#endif
+ m_favicons.set(hash, Application::favicon_store(WebView::IsPrivate::No).favicon_png(hash));
}
Optional<ByteBuffer> Bookmarks::favicon_png(String const& favicon_hash) const
diff --git a/UI/Qt/BrowserWindow.cpp b/UI/Qt/BrowserWindow.cpp
index edda5003b09..ffb9cd552d5 100644
--- a/UI/Qt/BrowserWindow.cpp
+++ b/UI/Qt/BrowserWindow.cpp
@@ -806,11 +806,9 @@ SessionStore& BrowserWindow::session() const
Optional<WebView::HistoryEntry> BrowserWindow::history_entry_for_url(URL::URL const& url) const
{
-#ifdef LADYBIRD_HUB_IN_OWN_PROCESS
- return HubConnection::the().history_entry_for_url(m_is_private, url);
-#else
- return WebView::Application::session_for_new_view(m_is_private)->history_store->entry_for_url(url);
-#endif
+ if (m_is_private == WebView::IsPrivate::Yes)
+ return {};
+ return Application::history_store().entry_for_url(url);
}
Tab& BrowserWindow::create_restored_tab(RestoredSessionTab const& restored, int index, bool defer)
diff --git a/UI/Qt/CMakeLists.txt b/UI/Qt/CMakeLists.txt
index 51334e4b8b8..9c78155898c 100644
--- a/UI/Qt/CMakeLists.txt
+++ b/UI/Qt/CMakeLists.txt
@@ -33,6 +33,7 @@ add_library(ladybird_impl STATIC
FeedbackPopover.cpp
FindInPageWidget.cpp
HiddenPageSizing.cpp
+ HistoryPage.cpp
HubConnection.cpp
Icon.cpp
InputMethodUtils.cpp
diff --git a/Libraries/LibWebView/WebUI/HistoryUI.cpp b/UI/Qt/HistoryPage.cpp
similarity index 69%
rename from Libraries/LibWebView/WebUI/HistoryUI.cpp
rename to UI/Qt/HistoryPage.cpp
index 638504d19fd..ad0bc82778d 100644
--- a/Libraries/LibWebView/WebUI/HistoryUI.cpp
+++ b/UI/Qt/HistoryPage.cpp
@@ -8,19 +8,19 @@
#include <AK/JsonArray.h>
#include <AK/JsonObject.h>
#include <LibURL/Parser.h>
-#include <LibWebView/Application.h>
#include <LibWebView/HistoryStore.h>
-#include <LibWebView/WebContentClient.h>
-#include <LibWebView/WebUI/HistoryUI.h>
+#include <UI/Qt/Application.h>
+#include <UI/Qt/HistoryPage.h>
+#include <UI/Qt/HubConnection.h>
#include <algorithm>
-namespace WebView {
+namespace Ladybird {
static constexpr size_t DEFAULT_HISTORY_PAGE_SIZE = 50;
static constexpr size_t MAX_HISTORY_PAGE_SIZE = 100;
-static Optional<String> site_key_for_entry(HistoryEntry const& entry)
+static Optional<String> site_key_for_entry(WebView::HistoryEntry const& entry)
{
auto parsed_url = URL::Parser::basic_parse(entry.url);
if (!parsed_url.has_value())
@@ -35,7 +35,7 @@ static Optional<String> site_key_for_entry(HistoryEntry const& entry)
return MUST(String::from_utf8(parsed_url->serialized_host()));
}
-static JsonObject serialize_history_entry(HistoryEntry const& entry)
+static JsonObject serialize_history_entry(WebView::HistoryEntry const& entry)
{
String favicon_base64_png;
if (entry.favicon_png.has_value()) {
@@ -53,20 +53,22 @@ static JsonObject serialize_history_entry(HistoryEntry const& entry)
return serialized;
}
-void HistoryUI::register_interfaces()
+HistoryPage::HistoryPage(u64 web_ui_id)
+ : m_web_ui_id(web_ui_id)
{
- register_interface("loadHistoryEntries"sv, [this](auto const& data) {
+}
+
+void HistoryPage::received_message(String const& name, JsonValue const& data)
+{
+ if (name == "loadHistoryEntries"sv)
load_history_entries(data);
- });
- register_interface("removeHistoryEntry"sv, [this](auto const& data) {
+ else if (name == "removeHistoryEntry"sv)
remove_history_entry(data);
- });
- register_interface("forgetHistorySite"sv, [this](auto const& data) {
+ else if (name == "forgetHistorySite"sv)
forget_history_site(data);
- });
}
-void HistoryUI::load_history_entries(JsonValue const& data)
+void HistoryPage::load_history_entries(JsonValue const& data)
{
if (!data.is_object())
return;
@@ -83,7 +85,7 @@ void HistoryUI::load_history_entries(JsonValue const& data)
else
limit = DEFAULT_HISTORY_PAGE_SIZE;
- auto entries = client().session().history_store->list_entries(query, offset, *limit + 1);
+ auto entries = Application::history_store().list_entries(query, offset, *limit + 1);
auto has_more = entries.size() > *limit;
if (has_more)
entries.resize(*limit);
@@ -100,10 +102,10 @@ void HistoryUI::load_history_entries(JsonValue const& data)
result.set("hasMore"sv, has_more);
result.set("entries"sv, move(serialized_entries));
- async_send_message("loadHistoryEntries"sv, move(result));
+ HubConnection::the().async_send_web_ui_message(m_web_ui_id, "loadHistoryEntries"_string, move(result));
}
-void HistoryUI::remove_history_entry(JsonValue const& data)
+void HistoryPage::remove_history_entry(JsonValue const& data)
{
if (!data.is_object())
return;
@@ -116,15 +118,12 @@ void HistoryUI::remove_history_entry(JsonValue const& data)
if (!parsed_url.has_value())
return;
- Application::the().read_keeps_omnibox_engagements(*parsed_url, [self = NonnullRefPtr { *this }, url = *parsed_url](bool keeps_engagements) {
- if (!self->has_client())
- return;
- auto remove_engagements = keeps_engagements ? RemoveHistoryEntryEngagements::No : RemoveHistoryEntryEngagements::Yes;
- self->client().session().history_store->remove_entry_for_url(url, remove_engagements);
- });
+ // NB: What was typed to reach a bookmarked page stays, so the omnibox keeps offering it.
+ auto remove_engagements = Application::bookmark_store().is_bookmarked(*parsed_url) ? WebView::RemoveHistoryEntryEngagements::No : WebView::RemoveHistoryEntryEngagements::Yes;
+ Application::history_store().remove_entry_for_url(*parsed_url, remove_engagements);
}
-void HistoryUI::forget_history_site(JsonValue const& data)
+void HistoryPage::forget_history_site(JsonValue const& data)
{
if (!data.is_object())
return;
@@ -137,7 +136,7 @@ void HistoryUI::forget_history_site(JsonValue const& data)
if (!parsed_url.has_value())
return;
- client().session().history_store->remove_entries_for_same_site(*parsed_url);
+ Application::history_store().remove_entries_for_same_site(*parsed_url);
}
}
diff --git a/UI/Qt/HistoryPage.h b/UI/Qt/HistoryPage.h
new file mode 100644
index 00000000000..c8ef24b2afa
--- /dev/null
+++ b/UI/Qt/HistoryPage.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2026, Tim Flynn <[email protected]>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/JsonValue.h>
+#include <AK/String.h>
+
+namespace Ladybird {
+
+// One open about:history. The page reaches this through the Hub, which does not know what the page is about.
+class HistoryPage {
+public:
+ AK_ALLOC_WITH_KMALLOC;
+
+ explicit HistoryPage(u64 web_ui_id);
+
+ void received_message(String const& name, JsonValue const& data);
+
+private:
+ void load_history_entries(JsonValue const&);
+ void remove_history_entry(JsonValue const&);
+ void forget_history_site(JsonValue const&);
+
+ u64 m_web_ui_id { 0 };
+};
+
+}
diff --git a/UI/Qt/HubConnection.cpp b/UI/Qt/HubConnection.cpp
index 3591284ca5e..182d1f112c1 100644
--- a/UI/Qt/HubConnection.cpp
+++ b/UI/Qt/HubConnection.cpp
@@ -176,8 +176,10 @@ void HubConnection::view_favicon_change(u64 view_id, Optional<Gfx::ShareableBitm
auto* view = RemoteView::find(view_id);
if (!view)
return;
- if (view->is_private() == WebView::IsPrivate::No && view->favicon_hash().has_value())
- Application::bookmark_store().update_favicon(view->url(), *view->favicon_hash());
+ if (favicon.has_value() && favicon->is_valid())
+ view->did_change_favicon(*favicon->bitmap());
+ else
+ view->did_change_favicon({});
if (!view->on_favicon_change)
return;
if (favicon.has_value() && favicon->is_valid())
@@ -595,25 +597,24 @@ void HubConnection::app_open_new_window(Vector<URL::URL> urls)
application.on_new_window(urls);
}
-void HubConnection::app_read_keeps_omnibox_engagements(u64 request_id, URL::URL url)
-{
- async_answer_keeps_omnibox_engagements(request_id, Application::bookmark_store().is_bookmarked(url));
-}
-
void HubConnection::web_ui_opened(u64 web_ui_id, String host)
{
if (host == "bookmarks"sv)
Application::bookmarks().page_opened(web_ui_id);
+ else if (host == "history"sv)
+ Application::the().history_page_opened(web_ui_id);
}
void HubConnection::web_ui_message(u64 web_ui_id, String name, JsonValue data)
{
Application::bookmarks().page_received_message(web_ui_id, name, data);
+ Application::the().history_page_received_message(web_ui_id, name, data);
}
void HubConnection::web_ui_closed(u64 web_ui_id)
{
Application::bookmarks().page_closed(web_ui_id);
+ Application::the().history_page_closed(web_ui_id);
}
void HubConnection::set_settings_from_hub(JsonValue const& settings)
@@ -658,6 +659,18 @@ void HubConnection::view_request_context_menu(u64 view_id, WebView::ContextMenuR
view->did_request_context_menu(request);
}
+void HubConnection::view_visited_page(u64 view_id, URL::URL url, Optional<String> title, WebView::HistoryVisitTransition transition)
+{
+ if (auto* view = RemoteView::find(view_id))
+ view->did_visit_page(url, title, transition);
+}
+
+void HubConnection::view_visited_page_title_change(u64 view_id, URL::URL url, String title)
+{
+ if (auto* view = RemoteView::find(view_id))
+ view->did_change_visited_page_title(url, title);
+}
+
void HubConnection::view_session_history_changed(u64 view_id, WebView::SessionHistorySnapshot history, URL::URL url)
{
if (auto* view = RemoteView::find(view_id))
@@ -710,7 +723,11 @@ void HubConnection::view_load_start(u64 view_id)
void HubConnection::view_load_finish(u64 view_id, URL::URL url)
{
- if (auto* view = RemoteView::find(view_id); view && view->on_load_finish)
+ auto* view = RemoteView::find(view_id);
+ if (!view)
+ return;
+ view->did_finish_loading(url);
+ if (view->on_load_finish)
view->on_load_finish(move(url));
}
diff --git a/UI/Qt/HubConnection.h b/UI/Qt/HubConnection.h
index 5d6ad43d11b..ce151e05eac 100644
--- a/UI/Qt/HubConnection.h
+++ b/UI/Qt/HubConnection.h
@@ -115,13 +115,14 @@ private:
virtual void app_read_clipboard_item(u64 request_id) override;
virtual void app_ask_user_for_download_path(u64 request_id, ByteString file) override;
virtual void settings_changed(ByteString settings_json, u64 last_applied_change_id) override;
- virtual void app_read_keeps_omnibox_engagements(u64 request_id, URL::URL url) override;
virtual void web_ui_opened(u64 web_ui_id, String host) override;
virtual void web_ui_message(u64 web_ui_id, String name, JsonValue data) override;
virtual void web_ui_closed(u64 web_ui_id) override;
virtual void view_request_context_menu(u64 view_id, WebView::ContextMenuRequest request) override;
virtual void view_did_make_link_to_highlight(u64 view_id, Optional<URL::URL> url) override;
virtual void view_session_history_changed(u64 view_id, WebView::SessionHistorySnapshot history, URL::URL url) override;
+ virtual void view_visited_page(u64 view_id, URL::URL url, Optional<String> title, WebView::HistoryVisitTransition transition) override;
+ virtual void view_visited_page_title_change(u64 view_id, URL::URL url, String title) override;
virtual void view_favicon_change(u64 view_id, Optional<Gfx::ShareableBitmap> favicon) override;
virtual void view_request_before_unload(u64 view_id, u64 answer_id, String source) override;
virtual void view_request_external_url_confirmation(u64 view_id, u64 answer_id, URL::URL url, URL::Origin initiator_origin, String application_name) override;
diff --git a/UI/Qt/Menu.cpp b/UI/Qt/Menu.cpp
index baac303b2de..04a53c9aa18 100644
--- a/UI/Qt/Menu.cpp
+++ b/UI/Qt/Menu.cpp
@@ -367,7 +367,7 @@ static void add_items_to_menu(QMenu& qmenu, WebView::Menu& menu)
#endif
}
-static QAction* create_session_history_traversal_menu_action(QMenu& menu, WebView::ViewImplementation::SessionHistoryTraversalMenuItem const& item)
+static QAction* create_session_history_traversal_menu_action(QMenu& menu, RemoteView::SessionHistoryTraversalMenuItem const& item)
{
static constexpr int const MENU_ICON_SIZE = 16;
diff --git a/UI/Qt/ProcessManagerWindow.cpp b/UI/Qt/ProcessManagerWindow.cpp
index 0f87bd20cd1..ae7343ccfe1 100644
--- a/UI/Qt/ProcessManagerWindow.cpp
+++ b/UI/Qt/ProcessManagerWindow.cpp
@@ -611,16 +611,20 @@ void ProcessManagerWindow::hideEvent(QHideEvent* event)
QIcon ProcessManagerWindow::favicon_for(WebView::ProcessPageSnapshot const& page)
{
- if (!page.favicon_hash.has_value())
+ // NB: The view's favicon is its top-level page's, which an embedded frame of another site does not share.
+ Optional<String> favicon_hash;
+ if (page.kind == WebView::ProcessPageKind::TopLevel && m_source.favicon_hash)
+ favicon_hash = m_source.favicon_hash(page);
+ if (!favicon_hash.has_value())
return create_chrome_icon(ChromeIcon::Globe, Theme::panel().body);
- if (auto icon = m_favicons.get(*page.favicon_hash); icon.has_value())
+ if (auto icon = m_favicons.get(*favicon_hash); icon.has_value())
return *icon;
QIcon icon;
- if (auto png = WebView::favicon_png_for_page(page); png.has_value())
+ if (auto png = m_source.favicon_png ? m_source.favicon_png(*favicon_hash) : Optional<ByteBuffer> {}; png.has_value())
icon = favicon_with_rounded_corners(icon_from_png(png->bytes(), 16), 16);
if (icon.isNull())
icon = create_chrome_icon(ChromeIcon::Globe, Theme::panel().body);
- m_favicons.set(*page.favicon_hash, icon);
+ m_favicons.set(*favicon_hash, icon);
return icon;
}
diff --git a/UI/Qt/ProcessManagerWindow.h b/UI/Qt/ProcessManagerWindow.h
index c7aedf1e779..ca129aabf91 100644
--- a/UI/Qt/ProcessManagerWindow.h
+++ b/UI/Qt/ProcessManagerWindow.h
@@ -47,6 +47,8 @@ public:
struct Source {
Function<Vector<WebView::ProcessSnapshot>()> take_snapshots;
Function<bool(u64 child_id)> end_process;
+ Function<Optional<String>(WebView::ProcessPageSnapshot const&)> favicon_hash;
+ Function<Optional<ByteBuffer>(String const& favicon_hash)> favicon_png;
};
explicit ProcessManagerWindow(Source);
diff --git a/UI/Qt/RemoteView.cpp b/UI/Qt/RemoteView.cpp
index 25d270718a5..057568ff3e7 100644
--- a/UI/Qt/RemoteView.cpp
+++ b/UI/Qt/RemoteView.cpp
@@ -9,8 +9,11 @@
# include <Hub/Application.h>
# include <LibWebView/PageTranslation.h>
#endif
+#include <LibGfx/ImageFormats/PNGWriter.h>
#include <LibURL/InternalURLs.h>
#include <LibUnicode/DisplayNames.h>
+#include <LibWebView/FaviconStore.h>
+#include <LibWebView/HistoryStore.h>
#include <LibWebView/PageTranslation.h>
#include <LibWebView/Translator.h>
#include <LibWebView/URL.h>
@@ -312,11 +315,6 @@ WebView::WebCompatReport::Page RemoteView::describe_page() const
return { .url = page.take_url(), .user_agent = page.take_user_agent(), .viewport_size = page.viewport_size(), .device_pixel_ratio = page.device_pixel_ratio(), .zoom_level = page.zoom_level() };
}
-Vector<WebView::HistoryEntry> RemoteView::recent_history_entries(size_t limit) const
-{
- return HubConnection::the().view_recent_history_entries(view_id(), limit);
-}
-
bool RemoteView::look_up_selected_text_at(Gfx::IntPoint widget_position)
{
return HubConnection::the().view_look_up_selected_text_at(view_id(), widget_position);
@@ -327,9 +325,9 @@ bool RemoteView::needs_beforeunload_check() const
return HubConnection::the().view_needs_beforeunload_check(view_id());
}
-Vector<RemoteView::SessionHistoryTraversalMenuItem> RemoteView::session_history_traversal_menu_items(int direction) const
+Vector<WebView::ViewImplementation::SessionHistoryTraversalItem> RemoteView::session_history_traversal_items(int direction) const
{
- return HubConnection::the().view_session_history_traversal_menu_items(view_id(), direction);
+ return HubConnection::the().view_session_history_traversal_items(view_id(), direction);
}
WebView::SessionHistorySnapshot RemoteView::session_history_snapshot() const
@@ -359,11 +357,6 @@ WebView::WebCompatReport::Page RemoteView::describe_page() const
return WebView::WebCompatReport::describe_page(*m_view);
}
-Vector<WebView::HistoryEntry> RemoteView::recent_history_entries(size_t limit) const
-{
- return m_view->recent_history_entries(limit);
-}
-
bool RemoteView::look_up_selected_text_at(Gfx::IntPoint widget_position)
{
return m_view->look_up_selected_text_at(widget_position);
@@ -374,9 +367,9 @@ bool RemoteView::needs_beforeunload_check() const
return m_view->needs_beforeunload_check();
}
-Vector<RemoteView::SessionHistoryTraversalMenuItem> RemoteView::session_history_traversal_menu_items(int direction) const
+Vector<WebView::ViewImplementation::SessionHistoryTraversalItem> RemoteView::session_history_traversal_items(int direction) const
{
- return m_view->session_history_traversal_menu_items(direction);
+ return m_view->session_history_traversal_items(direction);
}
WebView::SessionHistorySnapshot RemoteView::session_history_snapshot() const
@@ -409,6 +402,67 @@ void RemoteView::did_change_session_history(WebView::SessionHistorySnapshot hist
Application::session_store(m_is_private).update_tab_state({ .tab_id = *m_session_tab_id, .history = move(history), .url = move(url) });
}
+Vector<WebView::HistoryEntry> RemoteView::recent_history_entries(size_t limit) const
+{
+ if (is_private() == WebView::IsPrivate::Yes)
+ return {};
+ return Application::history_store().list_entries({}, 0, limit);
+}
+
+Vector<RemoteView::SessionHistoryTraversalMenuItem> RemoteView::session_history_traversal_menu_items(int direction) const
+{
+ Vector<SessionHistoryTraversalMenuItem> items;
+ for (auto& item : session_history_traversal_items(direction)) {
+ Optional<WebView::HistoryEntry> history_entry;
+ if (is_private() == WebView::IsPrivate::No)
+ history_entry = Application::history_store().entry_for_url(item.url);
+ auto url = item.url.serialize();
+ auto title = history_entry.has_value() && history_entry->title.has_value() && !history_entry->title->is_empty()
+ ? move(*history_entry->title)
+ : url;
+ items.append({
+ .step = item.step,
+ .title = move(title),
+ .url = move(url),
+ .favicon_png = history_entry.has_value() ? move(history_entry->favicon_png) : OptionalNone {},
+ });
+ }
+ return items;
+}
+
+void RemoteView::did_change_favicon(Optional<Gfx::Bitmap const&> favicon)
+{
+ m_favicon_hash.clear();
+ if (!favicon.has_value())
+ return;
+
+ if (auto favicon_png = Gfx::PNGWriter::encode(*favicon); !favicon_png.is_error())
+ m_favicon_hash = Application::favicon_store(is_private()).add_favicon(favicon_png.release_value());
+ if (!m_favicon_hash.has_value() || is_private() == WebView::IsPrivate::Yes)
+ return;
+
+ Application::history_store().update_favicon(url(), *m_favicon_hash);
+ Application::bookmark_store().update_favicon(url(), *m_favicon_hash);
+}
+
+void RemoteView::did_visit_page(URL::URL const& url, Optional<String> const& title, WebView::HistoryVisitTransition transition)
+{
+ if (is_private() == WebView::IsPrivate::No)
+ Application::history_store().record_visit(url, title, UnixDateTime::now(), transition);
+}
+
+void RemoteView::did_change_visited_page_title(URL::URL const& url, String const& title)
+{
+ if (is_private() == WebView::IsPrivate::No)
+ Application::history_store().update_title(url, title);
+}
+
+void RemoteView::did_finish_loading(URL::URL const& url)
+{
+ if (is_private() == WebView::IsPrivate::No && m_favicon_hash.has_value())
+ Application::history_store().update_favicon(url, *m_favicon_hash);
+}
+
// The browser's own strings are English, so languages are named in English.
static String language_display_name(StringView language)
{
diff --git a/UI/Qt/RemoteView.h b/UI/Qt/RemoteView.h
index bcbbc50e7f2..9f1b3116e2c 100644
--- a/UI/Qt/RemoteView.h
+++ b/UI/Qt/RemoteView.h
@@ -25,7 +25,12 @@ public:
using NavigationListener = WebView::ViewImplementation::NavigationListener;
using ScreenRects = WebView::ViewImplementation::ScreenRects;
using ScreenshotType = WebView::ViewImplementation::ScreenshotType;
- using SessionHistoryTraversalMenuItem = WebView::ViewImplementation::SessionHistoryTraversalMenuItem;
+ struct SessionHistoryTraversalMenuItem {
+ i32 step { 0 };
+ String title;
+ String url;
+ Optional<ByteBuffer> favicon_png;
+ };
// Shows the view that the Hub has made, if any, or else makes a new one.
RemoteView(Optional<u64> view_id, Hub::View::InitialState);
@@ -73,7 +78,11 @@ public:
URL::URL url() const { return m_state.url; }
URL::URL const& displayed_url() const { return m_state.displayed_url; }
Utf16String const& title() const { return m_state.title; }
- Optional<String> const& favicon_hash() const { return m_state.favicon_hash; }
+ Optional<String> const& favicon_hash() const { return m_favicon_hash; }
+ void did_change_favicon(Optional<Gfx::Bitmap const&>);
+ void did_visit_page(URL::URL const&, Optional<String> const& title, WebView::HistoryVisitTransition);
+ void did_change_visited_page_title(URL::URL const&, String const& title);
+ void did_finish_loading(URL::URL const&);
String const& handle() const { return m_state.handle; }
void set_window_position(Gfx::IntPoint position) { HubConnection::the().async_view_set_window_position(view_id(), position); }
void set_window_size(Gfx::IntSize size) { HubConnection::the().async_view_set_window_size(view_id(), size); }
@@ -206,6 +215,7 @@ public:
bool is_translated() const { return m_state.is_translated; }
WebView::Menu& translation_menu() { return *m_translation_menu; }
+ Vector<WebView::ViewImplementation::SessionHistoryTraversalItem> session_history_traversal_items(int direction) const;
Vector<SessionHistoryTraversalMenuItem> session_history_traversal_menu_items(int direction) const;
WebView::SessionHistorySnapshot session_history_snapshot() const;
ErrorOr<void> restore_session_history_from_snapshot(WebView::SessionHistorySnapshot);
@@ -272,6 +282,7 @@ private:
double m_device_pixel_ratio { 1.0 };
Optional<u64> m_display_id;
Optional<SessionTabId> m_session_tab_id;
+ Optional<String> m_favicon_hash;
bool m_scales_frames_to_fit { false };
Hub::ViewState m_state;
HashMap<u64, NavigationListener> m_navigation_listeners;