Truly independent web browser
LibWebView+Hub+UI/Qt: Move session restore into the UI
Andreas Klinge109703005fd
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cppindex f87b8c59337..f243d8c76ba 100644--- a/Libraries/LibWeb/Internals/Internals.cpp+++ b/Libraries/LibWeb/Internals/Internals.cpp@@ -2362,14 +2362,14 @@ bool Internals::restore_captured_session_history_snapshot()return window().associated_document().page().client().page_did_request_restore_session_history_snapshot_for_testing();}-bool Internals::register_session_store_tab()+bool Internals::record_reported_session_history(){- return window().associated_document().page().client().page_did_request_register_session_store_tab_for_testing();+ return window().associated_document().page().client().page_did_request_record_reported_session_history_for_testing();}-Utf16String Internals::dump_session_store_tab_state()+Utf16String Internals::dump_reported_session_history(){- return dump_string_to_utf16(window().associated_document().page().client().page_did_request_session_store_tab_state_for_testing());+ return dump_string_to_utf16(window().associated_document().page().client().page_did_request_reported_session_history_for_testing());}bool Internals::has_populated_document(HTML::HTMLIFrameElement& iframe)diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.hindex 3f5bea5d362..384fd03e64a 100644--- a/Libraries/LibWeb/Internals/Internals.h+++ b/Libraries/LibWeb/Internals/Internals.h@@ -252,8 +252,8 @@ public:Utf16String dump_ui_process_session_history_without_update();bool capture_session_history_snapshot();bool restore_captured_session_history_snapshot();- bool register_session_store_tab();- Utf16String dump_session_store_tab_state();+ bool record_reported_session_history();+ Utf16String dump_reported_session_history();Utf16String dump_site_isolation_process_tree();bool has_populated_document(HTML::HTMLIFrameElement&);bool canvas_has_unpresented_content(HTML::HTMLCanvasElement&);diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idlindex d31538bbb47..8372e84037b 100644--- a/Libraries/LibWeb/Internals/Internals.idl+++ b/Libraries/LibWeb/Internals/Internals.idl@@ -267,8 +267,8 @@ interface Internals {DOMString dumpUIProcessSessionHistoryWithoutUpdate();boolean captureSessionHistorySnapshot();boolean restoreCapturedSessionHistorySnapshot();- boolean registerSessionStoreTab();- DOMString dumpSessionStoreTabState();+ boolean recordReportedSessionHistory();+ DOMString dumpReportedSessionHistory();DOMString dumpSiteIsolationProcessTree();// Reports if the browser process has created a document for the iframe that it hasn't made active yet.boolean hasPopulatedDocument(HTMLIFrameElement iframe);diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.hindex 49a3d14bf65..a9c5f907bdf 100644--- a/Libraries/LibWeb/Page/Page.h+++ b/Libraries/LibWeb/Page/Page.h@@ -926,8 +926,8 @@ public:virtual u64 page_did_request_tab_audibility_change_count_for_testing() { return 0; }virtual bool page_did_request_capture_session_history_snapshot_for_testing() { return false; }virtual bool page_did_request_restore_session_history_snapshot_for_testing() { return false; }- virtual bool page_did_request_register_session_store_tab_for_testing() { return false; }- virtual String page_did_request_session_store_tab_state_for_testing() { return "{}"_string; }+ virtual bool page_did_request_record_reported_session_history_for_testing() { return false; }+ virtual String page_did_request_reported_session_history_for_testing() { return "{}"_string; }virtual void page_did_request_history_operation([[maybe_unused]] HTML::CrossProcessId operation_id, [[maybe_unused]] HistoryOperationParameters parameters) { }virtual void page_did_revoke_history_operation([[maybe_unused]] HTML::CrossProcessId operation_id) { }virtual void page_did_request_child_navigable_unload([[maybe_unused]] HTML::CrossProcessId navigable_id) { }diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cppindex 15de0c8632b..3f939f50322 100644--- a/Libraries/LibWebView/Application.cpp+++ b/Libraries/LibWebView/Application.cpp@@ -69,7 +69,6 @@#include <LibWebView/PictureInPictureWindow.h>#include <LibWebView/ProcessType.h>#include <LibWebView/RequestServerManager.h>-#include <LibWebView/SessionStore.h>#include <LibWebView/SiteCompatibility.h>#include <LibWebView/SpellChecker.h>#include <LibWebView/StorageAreaRegistry.h>@@ -241,18 +240,12 @@ Application::~Application()m_process_manager = nullptr;m_browser_process = nullptr;- // Only a normal exit gets this far, and only after every teardown step above, so a crash never records a clean one.- if (m_default_session && m_default_session->session_store) {- m_default_session->session_store->flush_dirty_state();- m_default_session->session_store->mark_clean_exit();- }-s_the = nullptr;}-SessionLaunchPolicy Application::launch_restore_policy() const+void Application::quit_for_signal(){- return SessionLaunchPolicy::None;+ m_event_loop->quit(0);}bool Application::claim_cpu_profiler(ProcessType process_type)@@ -1242,12 +1235,6 @@ RefPtr<BrowsingSession> Application::existing_session(IsPrivate is_private)return is_private == IsPrivate::Yes ? the().m_private_session.strong_ref() : the().m_default_session;}-SessionStore* Application::session_store(IsPrivate is_private)-{- auto session = existing_session(is_private);- return session ? session->session_store.ptr() : nullptr;-}-WebDriverBrowserConnection* Application::webdriver_browser_connection(){if (!m_browser_options.webdriver_browser_endpoint.has_value() || m_webdriver_browser_connection_failed)@@ -1330,13 +1317,6 @@ void Application::reset_private_browsing_session()// RequestServer answers our own private client with the cookies of the session it was created for, so the next// private request made by the UI process needs a client of the new session.- // Views pending deferred deletion may still push updates, and the replacement store reuses their ids.- ViewImplementation::for_each_view([](ViewImplementation& view) {- if (view.is_private() == IsPrivate::Yes)- view.clear_session_tab_id();- return IterationDecision::Continue;- });-// NB: Those views own the session until they are deleted, so let go of it here. The private window opened next// starts a new one rather than picking up what this was asked to clear.m_private_session.clear();@@ -1779,26 +1759,11 @@ ErrorOr<void> Application::launch_services()m_default_session->history_store = HistoryStore::create(*m_default_session->favicon_store);}- // Fall back without modifying the existing Sessions database.- auto session_store = [&]() -> ErrorOr<NonnullOwnPtr<SessionStore>> {- // 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- // unclean-exit count, and demote the open windows of a browser running on this profile. So each gets a- // transient store instead, leaving the Sessions database as the last run left it.- if (m_browser_options.headless_mode.has_value() || m_browser_options.webdriver_browser_endpoint.has_value() || m_stats_log)- return SessionStore::create();-- auto session_database = TRY(Database::Database::create(database_path, "Sessions"sv, { .foreign_keys = Database::Database::ForeignKeys::Yes }));- if (TRY(SessionStore::migrate_schema(session_database)) != Database::MigrationOutcome::Success)- return Error::from_string_literal("Sessions database was created by a newer Ladybird version");- return SessionStore::create(session_database, launch_restore_policy());- }();- if (session_store.is_error()) {- dbgln("Sessions will not be persisted this session: {}", session_store.error());- m_default_session->session_store = SessionStore::create();- } else {- m_default_session->session_store = session_store.release_value();- }+ // 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+ // unclean-exit count, and demote the open windows of a browser running on this profile. So none of them keeps+ // its session, leaving the Sessions database as the last run left it.+ m_persists_sessions = !m_browser_options.headless_mode.has_value() && !m_browser_options.webdriver_browser_endpoint.has_value() && !m_stats_log;} else {dbgln_if(WEBVIEW_HISTORY_DEBUG, "[History] SQL history is disabled, disabling browsing history");@@ -1808,25 +1773,19 @@ ErrorOr<void> Application::launch_services()m_default_session->hsts_store = HSTSStore::create();m_default_session->storage_jar = StorageJar::create();m_download_store = DownloadStore::create_disabled();- m_default_session->session_store = SessionStore::create();}m_default_session->blob_url_store = make<BlobURLStore>();m_file_downloader.adopt_download_store({}, *m_download_store);- m_default_session->session_store->on_closed_units_changed = [this] {- on_recently_closed_entries_changed();- };-#if !defined(AK_OS_WINDOWS)// A run stopped by SIGINT or SIGTERM ends like a quit, rather than like a crash: It saves the session, leaves its// windows for the next launch to recover, and records a clean exit.- if (m_default_session->session_store->is_persistent()) {+ if (m_persists_sessions) {for (auto signal_number : { SIGINT, SIGTERM }) {m_session_signal_handlers.append(Core::EventLoop::register_signal(signal_number, [this](int) {- m_default_session->session_store->application_quitting();- m_event_loop->quit(0);+ quit_for_signal();}));}}@@ -2496,12 +2455,6 @@ NonnullRefPtr<Core::Promise<Empty>> Application::clear_browsing_data(ClearBrowsiif (options.delete_history == ClearBrowsingDataOptions::Delete::Yes) {m_default_session->history_store->remove_entries_accessed_since(options.since);- if (auto result = m_default_session->session_store->remove_entries_accessed_since(options.since); result.is_error())- dbgln("Unable to remove closed session entries: {}", result.error());- if (auto private_session = m_private_session.strong_ref()) {- if (auto result = private_session->session_store->remove_entries_accessed_since(options.since); result.is_error())- dbgln("Unable to remove closed private session entries: {}", result.error());- }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();@@ -2524,7 +2477,7 @@ NonnullRefPtr<Core::Promise<Empty>> Application::clear_browsing_data(ClearBrowsi}if (did_change_history)- on_recently_closed_entries_changed();+ did_clear_history_since(options.since);if (!promise) {promise = Core::Promise<Empty>::construct();diff --git a/Libraries/LibWebView/Application.h b/Libraries/LibWebView/Application.hindex 1aa184f0ffb..eb28ac9c526 100644--- a/Libraries/LibWebView/Application.h+++ b/Libraries/LibWebView/Application.h@@ -141,10 +141,6 @@ public:virtual bool supports_client_side_window_decorations() const { return false; }virtual bool supports_picture_in_picture() const;- // What startup recovery does with the windows the last run left open. Only a frontend that shows the launch plan- // asks for more than None.- virtual SessionLaunchPolicy launch_restore_policy() const;-// Returns true if the platform sends momentum scroll events after a touchpad flick.// If it does not, the compositor makes the fling.virtual bool platform_reports_scroll_momentum() const { return true; }@@ -211,6 +207,10 @@ public:static RefPtr<BrowsingSession> existing_session(IsPrivate);+ // Whether the windows and tabs of this run are kept for the next one. A headless run, a browser that WebDriver drives,+ // and one that logs process statistics never join a browser already running on their profile, so they keep none.+ bool persists_sessions() const { return m_persists_sessions; }+// A RequestServer client uses the cookies of the browsing session it was created for, whatever RequestServer says.void did_connect_request_server_client(int client_id, BrowsingSession&, RequestServer::SiteBinding);void did_disconnect_request_server_client(int client_id);@@ -221,7 +221,6 @@ public:Vector<int> request_server_client_ids_for_testing(BrowsingSession const&) const;// NB: Null once that session has ended, so a closed private tab is not offered back afterwards.- static SessionStore* session_store(IsPrivate);static ProcessManager& process_manager() { return *the().m_process_manager; }#if defined(AK_OS_WINDOWS)@@ -413,7 +412,11 @@ protected:virtual void update_tabs_display() const { }- virtual void on_recently_closed_entries_changed() const { }+ // The user cleared the history from this time on, so the application's records of it go too.+ virtual void did_clear_history_since(UnixDateTime) const { }++ // A run stopped by SIGINT or SIGTERM ends like a quit, rather than like a crash.+ virtual void quit_for_signal();virtual void on_devtools_enabled() const { }virtual void on_devtools_disabled() const { }@@ -571,6 +574,7 @@ private:bool m_cpu_profiler_claimed { false };Vector<int> m_cpu_profiler_signal_handlers;Vector<int> m_session_signal_handlers;+ bool m_persists_sessions { false };RequestServerOptions m_request_server_options;WebContentOptions m_web_content_options;RefPtr<FontService> m_font_service;diff --git a/Libraries/LibWebView/BrowsingSession.cpp b/Libraries/LibWebView/BrowsingSession.cppindex 2538a13383c..2bf42dcf48d 100644--- a/Libraries/LibWebView/BrowsingSession.cpp+++ b/Libraries/LibWebView/BrowsingSession.cpp@@ -11,7 +11,6 @@#include <LibWebView/HSTSStore.h>#include <LibWebView/HistoryStore.h>#include <LibWebView/PermissionManager.h>-#include <LibWebView/SessionStore.h>#include <LibWebView/StorageJar.h>namespace WebView {@@ -34,7 +33,6 @@ NonnullRefPtr<BrowsingSession> BrowsingSession::create(IsPrivate is_private)session->hsts_store = HSTSStore::create();session->favicon_store = FaviconStore::create();session->history_store = HistoryStore::create_disabled();- session->session_store = SessionStore::create();}return session;diff --git a/Libraries/LibWebView/BrowsingSession.h b/Libraries/LibWebView/BrowsingSession.hindex 0e3a3b14946..54c69172d0e 100644--- a/Libraries/LibWebView/BrowsingSession.h+++ b/Libraries/LibWebView/BrowsingSession.h@@ -39,7 +39,6 @@ public:OwnPtr<HSTSStore> hsts_store;OwnPtr<FaviconStore> favicon_store;OwnPtr<HistoryStore> history_store;- OwnPtr<SessionStore> session_store;OwnPtr<PermissionManager> permission_manager;private:diff --git a/Libraries/LibWebView/CMakeLists.txt b/Libraries/LibWebView/CMakeLists.txtindex dd8e4ac3288..bb17d79712d 100644--- a/Libraries/LibWebView/CMakeLists.txt+++ b/Libraries/LibWebView/CMakeLists.txt@@ -71,9 +71,7 @@ set(SOURCESRequestServerSiteBindings.cppSearchEngine.cppSessionHistory.cpp- SessionHistorySnapshotStorage.cppSessionHistoryTraversalQueue.cpp- SessionStore.cppSettings.cppSiteCompatibility.cppStorageAreaRegistry.cppdiff --git a/Libraries/LibWebView/Forward.h b/Libraries/LibWebView/Forward.hindex 9aeeb77fd91..2ec56757f1e 100644--- a/Libraries/LibWebView/Forward.h+++ b/Libraries/LibWebView/Forward.h@@ -60,7 +60,6 @@ class RequestServerInstance;class RequestServerManager;class RequestServerSiteBindings;class PermissionManager;-class SessionStore;class Settings;class SettingsUI;class SpellChecker;@@ -85,8 +84,6 @@ struct SearchEngine;struct WebContentOptions;class WebContentPage;-enum class SessionLaunchPolicy : u8;-}namespace AK {diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cppindex df160ad41ac..db3b710004a 100644--- a/Libraries/LibWebView/ViewImplementation.cpp+++ b/Libraries/LibWebView/ViewImplementation.cpp@@ -4104,17 +4104,11 @@ bool ViewImplementation::restore_captured_session_history_snapshot_for_testing(Breturn !result.is_error();}-bool ViewImplementation::register_session_store_tab_for_testing(Badge<WebContentPage>)+void ViewImplementation::record_reported_session_history_for_testing(Badge<WebContentPage>){- if (m_session_tab_id.has_value())- return true;-- auto tab_id = m_session->session_store->tab_opened({ .window_id = {}, .initial_url = url(), .insertion_index = {}, .is_active = SessionStore::IsActive::No });- if (tab_id.is_error())- return false;- set_session_tab_id(tab_id.value());+ m_records_reported_session_history_for_testing = true;+ set_reports_session_history(true);notify_session_history_changed();- return true;}static Optional<size_t> current_top_level_history_entry_index_for_step(Vector<Web::HTML::SessionHistoryEntryDescriptor> const& entries, Optional<i32> current_step)@@ -4131,39 +4125,44 @@ static Optional<size_t> current_top_level_history_entry_index_for_step(Vector<Wereturn current_entry_index;}-String ViewImplementation::session_store_tab_state_for_testing(Badge<WebContentPage>) const+String ViewImplementation::reported_session_history_for_testing(Badge<WebContentPage>) const{JsonObject serialized;- if (!m_session_tab_id.has_value())+ if (!m_reported_session_history_for_testing.has_value())return serialized.serialized();- auto cached_state = m_session->session_store->cached_tab_state_for_testing(*m_session_tab_id);- if (!cached_state.has_value())- return serialized.serialized();-- serialized.set("url"sv, cached_state->url.serialize());- if (cached_state->history.has_value()) {- auto const& history = *cached_state->history;- Optional<i32> current_step;- if (history.current_used_step_index < history.used_steps.size())- current_step = history.used_steps[history.current_used_step_index];- serialized.set("entries"sv, history_json_entries(history.entries, current_top_level_history_entry_index_for_step(history.entries, current_step)));- serialized.set("usedSteps"sv, history_json_steps(history.used_steps, history.current_used_step_index));- }+ auto const& reported = *m_reported_session_history_for_testing;+ auto const& history = reported.history;+ serialized.set("url"sv, reported.url.serialize());+ Optional<i32> current_step;+ if (history.current_used_step_index < history.used_steps.size())+ current_step = history.used_steps[history.current_used_step_index];+ serialized.set("entries"sv, history_json_entries(history.entries, current_top_level_history_entry_index_for_step(history.entries, current_step)));+ serialized.set("usedSteps"sv, history_json_steps(history.used_steps, history.current_used_step_index));return serialized.serialized();}+void ViewImplementation::set_reports_session_history(bool reports_session_history)+{+ auto was_reporting = exchange(m_reports_session_history, reports_session_history);+ if (!reports_session_history || was_reporting || !has_traversable())+ return;++ // NB: A view that navigated before reporting began has nothing else coming to tell of that. One still on its first+ // blank page has nothing to tell, and must not overwrite the history a restored tab is about to get.+ if (!traversable().session_history().current_entry().url.equals(URL::about_blank()))+ notify_session_history_changed();+}+void ViewImplementation::notify_session_history_changed(){- if (!m_session_tab_id.has_value())+ if (!m_reports_session_history)return;+ auto history = session_history_snapshot();auto url = traversable().session_history().current_entry().url;- SessionStore::TabStateUpdate update {- .tab_id = *m_session_tab_id,- .history = session_history_snapshot(),- .url = move(url),- };- m_session->session_store->update_tab_state(move(update));+ if (m_records_reported_session_history_for_testing)+ m_reported_session_history_for_testing = ReportedSessionHistory { history, url };+ did_change_session_history(history, url);}NonnullRefPtr<Core::Promise<Empty>> ViewImplementation::reset_state_for_testing()diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.hindex a617e788dc6..1a213954ca4 100644--- a/Libraries/LibWebView/ViewImplementation.h+++ b/Libraries/LibWebView/ViewImplementation.h@@ -80,7 +80,6 @@#include <LibWebView/PageBackingStores.h>#include <LibWebView/PermissionManager.h>#include <LibWebView/SessionHistory.h>-#include <LibWebView/SessionStore.h>#include <LibWebView/Settings.h>#include <LibWebView/SpellChecker.h>#include <LibWebView/TabIndicators.h>@@ -280,9 +279,8 @@ public:[[nodiscard]] SessionHistorySnapshot session_history_snapshot() const;[[nodiscard]] ErrorOr<void> restore_session_history_from_snapshot(SessionHistorySnapshot);- Optional<SessionTabId> session_tab_id() const { return m_session_tab_id; }- void set_session_tab_id(SessionTabId session_tab_id) { m_session_tab_id = session_tab_id; }- void clear_session_tab_id() { m_session_tab_id = {}; }+ // A view whose windows and tabs the application keeps tells it of each change to its session history.+ void set_reports_session_history(bool);void zoom_in();void zoom_out();@@ -532,8 +530,8 @@ public:void did_reset_state_for_testing(Badge<WebContentPage>, Web::HTML::SessionHistoryEntryDescriptor);bool capture_session_history_snapshot_for_testing(Badge<WebContentPage>);bool restore_captured_session_history_snapshot_for_testing(Badge<WebContentPage>);- bool register_session_store_tab_for_testing(Badge<WebContentPage>);- String session_store_tab_state_for_testing(Badge<WebContentPage>) const;+ void record_reported_session_history_for_testing(Badge<WebContentPage>);+ String reported_session_history_for_testing(Badge<WebContentPage>) const;void did_start_webdriver_navigation();void load_for_webdriver_navigation(URL::URL const&);String ui_process_session_history_for_testing(Badge<WebContentPage>) const;@@ -717,6 +715,8 @@ public:// Something the UI shows about this view may have changed, like whether it can undo or show its source.virtual void did_change_state() { }+ virtual void did_change_session_history(SessionHistorySnapshot const&, URL::URL const&) { }+bool can_navigate_back() const { return m_can_navigate_back; }bool can_navigate_forward() const { return m_can_navigate_forward; }@@ -1102,7 +1102,13 @@ protected:Web::HTML::MuteState m_mute_state { Web::HTML::MuteState::Unmuted };CanonicalTraversable* m_top_level_traversable { nullptr };- Optional<SessionTabId> m_session_tab_id;+ bool m_reports_session_history { false };+ struct ReportedSessionHistory {+ SessionHistorySnapshot history;+ URL::URL url;+ };+ Optional<ReportedSessionHistory> m_reported_session_history_for_testing;+ bool m_records_reported_session_history_for_testing { false };Optional<SessionHistorySnapshot> m_captured_session_history_snapshot_for_testing;RefPtr<Core::Promise<Empty>> m_pending_test_state_reset;RefPtr<Core::Promise<Empty>> m_pending_test_state_reset_queue_promise;diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cppindex 2a7accd1d11..3d86d3d326e 100644--- a/Libraries/LibWebView/WebContentPage.cpp+++ b/Libraries/LibWebView/WebContentPage.cpp@@ -3548,11 +3548,12 @@ Messages::WebContentTestClient::DidRequestRestoreSessionHistorySnapshotForTestinreturn { false };}-Messages::WebContentTestClient::DidRequestRegisterSessionStoreTabForTestingResponse WebContentPage::did_request_register_session_store_tab_for_testing()+Messages::WebContentTestClient::DidRequestRecordReportedSessionHistoryForTestingResponse WebContentPage::did_request_record_reported_session_history_for_testing(){- if (displays_tab())- return { view().register_session_store_tab_for_testing({}) };- return { false };+ if (!displays_tab())+ return { false };+ view().record_reported_session_history_for_testing({});+ return { true };}// A document populated for a navigable is one the browser process created for it, and has not made active yet.@@ -3568,10 +3569,10 @@ Messages::WebContentTestClient::DidRequestHasPopulatedDocumentForTestingResponsereturn has_populated_document;}-Messages::WebContentTestClient::DidRequestSessionStoreTabStateForTestingResponse WebContentPage::did_request_session_store_tab_state_for_testing()+Messages::WebContentTestClient::DidRequestReportedSessionHistoryForTestingResponse WebContentPage::did_request_reported_session_history_for_testing(){if (displays_tab())- return { view().session_store_tab_state_for_testing({}) };+ return { view().reported_session_history_for_testing({}) };return { "{}"_string };}diff --git a/Libraries/LibWebView/WebContentPage.h b/Libraries/LibWebView/WebContentPage.hindex a522aebf946..4045ce4661c 100644--- a/Libraries/LibWebView/WebContentPage.h+++ b/Libraries/LibWebView/WebContentPage.h@@ -422,8 +422,8 @@ private:Messages::WebContentTestClient::DidRequestHasPopulatedDocumentForTestingResponse did_request_has_populated_document_for_testing(Web::HTML::CrossProcessId navigable_id) const;Messages::WebContentTestClient::DidRequestCaptureSessionHistorySnapshotForTestingResponse did_request_capture_session_history_snapshot_for_testing();Messages::WebContentTestClient::DidRequestRestoreSessionHistorySnapshotForTestingResponse did_request_restore_session_history_snapshot_for_testing();- Messages::WebContentTestClient::DidRequestRegisterSessionStoreTabForTestingResponse did_request_register_session_store_tab_for_testing();- Messages::WebContentTestClient::DidRequestSessionStoreTabStateForTestingResponse did_request_session_store_tab_state_for_testing();+ Messages::WebContentTestClient::DidRequestRecordReportedSessionHistoryForTestingResponse did_request_record_reported_session_history_for_testing();+ Messages::WebContentTestClient::DidRequestReportedSessionHistoryForTestingResponse did_request_reported_session_history_for_testing();WeakPtr<WebContentClient> m_client;Web::PageId m_id;diff --git a/Libraries/LibWebView/WebContentTestClient.cpp b/Libraries/LibWebView/WebContentTestClient.cppindex 55bd9d0116e..fb499d176c0 100644--- a/Libraries/LibWebView/WebContentTestClient.cpp+++ b/Libraries/LibWebView/WebContentTestClient.cpp@@ -197,18 +197,18 @@ Messages::WebContentTestClient::DidRequestRestoreSessionHistorySnapshotForTestinreturn false;}-Messages::WebContentTestClient::DidRequestRegisterSessionStoreTabForTestingResponse WebContentTestClient::did_request_register_session_store_tab_for_testing(Web::PageId page_id)+Messages::WebContentTestClient::DidRequestRecordReportedSessionHistoryForTestingResponse WebContentTestClient::did_request_record_reported_session_history_for_testing(Web::PageId page_id){if (auto* page = m_client.page(page_id))- return page->did_request_register_session_store_tab_for_testing();+ return page->did_request_record_reported_session_history_for_testing();return false;}-Messages::WebContentTestClient::DidRequestSessionStoreTabStateForTestingResponse WebContentTestClient::did_request_session_store_tab_state_for_testing(Web::PageId page_id)+Messages::WebContentTestClient::DidRequestReportedSessionHistoryForTestingResponse WebContentTestClient::did_request_reported_session_history_for_testing(Web::PageId page_id){if (auto* page = m_client.page(page_id))- return page->did_request_session_store_tab_state_for_testing();+ return page->did_request_reported_session_history_for_testing();return String {};}diff --git a/Libraries/LibWebView/WebContentTestClient.h b/Libraries/LibWebView/WebContentTestClient.hindex 9165e5e1ef2..10502a966c6 100644--- a/Libraries/LibWebView/WebContentTestClient.h+++ b/Libraries/LibWebView/WebContentTestClient.h@@ -47,8 +47,8 @@ private:virtual Messages::WebContentTestClient::DidRequestHasPopulatedDocumentForTestingResponse did_request_has_populated_document_for_testing(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) override;virtual Messages::WebContentTestClient::DidRequestCaptureSessionHistorySnapshotForTestingResponse did_request_capture_session_history_snapshot_for_testing(Web::PageId page_id) override;virtual Messages::WebContentTestClient::DidRequestRestoreSessionHistorySnapshotForTestingResponse did_request_restore_session_history_snapshot_for_testing(Web::PageId page_id) override;- virtual Messages::WebContentTestClient::DidRequestRegisterSessionStoreTabForTestingResponse did_request_register_session_store_tab_for_testing(Web::PageId page_id) override;- virtual Messages::WebContentTestClient::DidRequestSessionStoreTabStateForTestingResponse did_request_session_store_tab_state_for_testing(Web::PageId page_id) override;+ virtual Messages::WebContentTestClient::DidRequestRecordReportedSessionHistoryForTestingResponse did_request_record_reported_session_history_for_testing(Web::PageId page_id) override;+ virtual Messages::WebContentTestClient::DidRequestReportedSessionHistoryForTestingResponse did_request_reported_session_history_for_testing(Web::PageId page_id) override;virtual Messages::WebContentTestClient::SetPermissionForTestingResponse set_permission_for_testing(Web::PageId, Web::HTML::CrossProcessId document_id, String name, String state) override;virtual void set_next_permission_prompt_outcome_for_testing(Web::PageId, String name, String outcome, bool held) override;virtual void set_system_microphone_authorization_for_testing(Web::PageId, String authorization, String answer, bool held) override;diff --git a/Services/Hub/Application.cpp b/Services/Hub/Application.cppindex c584e7ae4be..78edb636f1c 100644--- a/Services/Hub/Application.cpp+++ b/Services/Hub/Application.cpp@@ -332,10 +332,20 @@ void Application::update_tabs_display() constui->async_app_update_tabs_display();}-void Application::on_recently_closed_entries_changed() const+void Application::did_clear_history_since(UnixDateTime since) const{if (auto* ui = ConnectionFromUI::the())- ui->async_app_on_recently_closed_entries_changed();+ ui->async_app_did_clear_history_since(since);+}++void Application::quit_for_signal()+{+ // NB: The UI keeps the session, so it is the UI that quits. We end along with it.+ if (auto* ui = ConnectionFromUI::the()) {+ ui->async_app_quit_for_signal();+ return;+ }+ WebView::Application::quit_for_signal();}void Application::destroy_view(u64 view_id)@@ -387,14 +397,6 @@ void Application::on_devtools_disabled() constui->async_app_did_disable_devtools();}-WebView::SessionLaunchPolicy Application::launch_restore_policy() const-{- // Without the setting, only pinned tabs come back; with it, every window and tab does.- if (settings().restore_previous_session())- return WebView::SessionLaunchPolicy::Everything;- return WebView::SessionLaunchPolicy::PinnedOnly;-}-void Application::create_platform_actions(){if (m_host)diff --git a/Services/Hub/Application.h b/Services/Hub/Application.hindex c88a429f4cd..06696ce59cd 100644--- a/Services/Hub/Application.h+++ b/Services/Hub/Application.h@@ -98,13 +98,13 @@ private:virtual void read_clipboard_text(ClipboardType, Function<void(Utf16String)>) const override;virtual void read_clipboard_item(Function<void(Web::Clipboard::SystemClipboardItem)>) const override;virtual void update_tabs_display() const override;- virtual void on_recently_closed_entries_changed() const override;+ virtual void did_clear_history_since(UnixDateTime) const override;+ virtual void quit_for_signal() override;virtual NonnullOwnPtr<WebView::MicrophoneAuthorizer> create_microphone_authorizer() override;virtual NonnullOwnPtr<WebView::NotificationBackend> create_notification_backend() override;virtual bool captures_browser_crashes() const override { return true; }virtual void on_devtools_enabled() const override;virtual void on_devtools_disabled() const override;- virtual WebView::SessionLaunchPolicy launch_restore_policy() const override;virtual void create_platform_actions() override;virtual Optional<String> ui_font_family() const override;virtual Web::CSS::PreferredColorScheme interface_color_scheme() const override;diff --git a/Services/Hub/ConnectionFromUI.cpp b/Services/Hub/ConnectionFromUI.cppindex 887978bd7a3..669494dcaec 100644--- a/Services/Hub/ConnectionFromUI.cpp+++ b/Services/Hub/ConnectionFromUI.cpp@@ -411,15 +411,10 @@ void ConnectionFromUI::view_traverse_the_history_to_step(u64 view_id, i32 step)view->traverse_the_history_to_step(step);}-void ConnectionFromUI::view_set_session_tab_id(u64 view_id, Optional<WebView::SessionTabId> session_tab_id)+void ConnectionFromUI::view_set_reports_session_history(u64 view_id, bool reports_session_history){- auto* view = find_view(view_id);- if (!view)- return;- if (session_tab_id.has_value())- view->set_session_tab_id(*session_tab_id);- else- view->clear_session_tab_id();+ if (auto* view = find_view(view_id))+ view->set_reports_session_history(reports_session_history);}void ConnectionFromUI::view_file_picker_closed(u64 view_id, Vector<Web::HTML::SelectedFile> selected_files)@@ -511,11 +506,6 @@ void ConnectionFromUI::open_microphone_system_settings()static_cast<WebView::Application&>(Application::the()).microphone_authorizer().open_system_settings();}-static WebView::SessionStore& session_store_of(WebView::IsPrivate is_private)-{- return *Application::session_for_new_view(is_private)->session_store;-}-void ConnectionFromUI::favicons_in_use(Vector<String> favicon_hashes){HashTable<String> referenced_hashes;@@ -567,6 +557,8 @@ Messages::HubServer::InitializeResponse ConnectionFromUI::initialize()state.devtools_port = options.devtools_port;auto const& profile = Application::profile();state.config_directory = profile.paths().config;+ state.data_directory = profile.paths().data;+ state.persists_sessions = Application::the().persists_sessions();state.profile_identifier = profile.identifier();state.profile_identity = profile.paths().identity;state.profile_is_temporary = profile.is_temporary();@@ -793,119 +785,6 @@ Messages::HubServer::ViewPageDescriptionResponse ConnectionFromUI::view_page_desreturn { move(page.url), move(page.user_agent), page.viewport_size, page.device_pixel_ratio, page.zoom_level };}-Messages::HubServer::SessionWindowOpenedResponse ConnectionFromUI::session_window_opened(WebView::IsPrivate is_private)-{- auto id = session_store_of(is_private).window_opened();- if (id.is_error())- return Optional<WebView::SessionWindowId> {};- return Optional<WebView::SessionWindowId> { id.value() };-}--Messages::HubServer::SessionWindowClosingResponse ConnectionFromUI::session_window_closing(WebView::IsPrivate is_private, WebView::SessionStore::WindowClosing closing)-{- return !session_store_of(is_private).window_closing(move(closing)).is_error();-}--void ConnectionFromUI::session_window_activated(WebView::IsPrivate is_private, WebView::SessionWindowId id)-{- session_store_of(is_private).window_activated(id);-}--void ConnectionFromUI::session_window_geometry_changed(WebView::IsPrivate is_private, WebView::SessionWindowId id, WebView::SessionWindowGeometry geometry)-{- session_store_of(is_private).window_geometry_changed(id, geometry);-}--Messages::HubServer::SessionTabOpenedResponse ConnectionFromUI::session_tab_opened(WebView::IsPrivate is_private, WebView::SessionStore::TabOpened opened)-{- auto id = session_store_of(is_private).tab_opened(move(opened));- if (id.is_error())- return Optional<WebView::SessionTabId> {};- return Optional<WebView::SessionTabId> { id.value() };-}--Messages::HubServer::SessionTabClosedResponse ConnectionFromUI::session_tab_closed(WebView::IsPrivate is_private, WebView::SessionStore::TabClosed closed)-{- return !session_store_of(is_private).tab_closed(move(closed)).is_error();-}--void ConnectionFromUI::session_tab_detached(WebView::IsPrivate is_private, WebView::SessionTabId id)-{- session_store_of(is_private).tab_detached(id);-}--void ConnectionFromUI::session_tab_moved(WebView::IsPrivate is_private, WebView::SessionStore::TabMoved moved)-{- session_store_of(is_private).tab_moved(move(moved));-}--void ConnectionFromUI::session_tab_order_changed(WebView::IsPrivate is_private, WebView::SessionStore::TabOrderChanged changed)-{- session_store_of(is_private).tab_order_changed(move(changed));-}--Messages::HubServer::SessionTabPinnedChangedResponse ConnectionFromUI::session_tab_pinned_changed(WebView::IsPrivate is_private, WebView::SessionTabId id, bool pinned)-{- return !session_store_of(is_private).tab_pinned_changed(id, pinned).is_error();-}--void ConnectionFromUI::session_active_tab_changed(WebView::IsPrivate is_private, WebView::SessionTabId id)-{- session_store_of(is_private).active_tab_changed(id);-}--void ConnectionFromUI::session_application_quitting(WebView::IsPrivate is_private)-{- session_store_of(is_private).application_quitting();-}--void ConnectionFromUI::session_application_quit_aborted(WebView::IsPrivate is_private)-{- session_store_of(is_private).application_quit_aborted();-}--Messages::HubServer::SessionConsecutiveUncleanExitsResponse ConnectionFromUI::session_consecutive_unclean_exits(WebView::IsPrivate is_private)-{- return session_store_of(is_private).consecutive_unclean_exits();-}--Messages::HubServer::SessionHasClosedUnitsResponse ConnectionFromUI::session_has_closed_units(WebView::IsPrivate is_private)-{- return session_store_of(is_private).has_closed_units();-}--static Optional<WebView::ClosedSessionUnit> unit_or_nothing(ErrorOr<Optional<WebView::ClosedSessionUnit>> unit)-{- if (unit.is_error())- return {};- return unit.release_value();-}--Messages::HubServer::SessionTakeMostRecentlyClosedResponse ConnectionFromUI::session_take_most_recently_closed(WebView::IsPrivate is_private)-{- return unit_or_nothing(session_store_of(is_private).take_most_recently_closed());-}--Messages::HubServer::SessionRecentlyClosedUnitsResponse ConnectionFromUI::session_recently_closed_units(WebView::IsPrivate is_private, u64 limit)-{- return session_store_of(is_private).recently_closed_units(limit);-}--Messages::HubServer::SessionTakeClosedUnitResponse ConnectionFromUI::session_take_closed_unit(WebView::IsPrivate is_private, WebView::SessionWindowId id)-{- return unit_or_nothing(session_store_of(is_private).take_closed_unit(id));-}--Messages::HubServer::SessionTakeLaunchPlanResponse ConnectionFromUI::session_take_launch_plan(WebView::IsPrivate is_private)-{- return session_store_of(is_private).take_launch_plan();-}--Messages::HubServer::SessionLoadTabHistoryResponse ConnectionFromUI::session_load_tab_history(WebView::IsPrivate is_private, WebView::SessionTabId id)-{- return session_store_of(is_private).load_tab_history(id);-}-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);diff --git a/Services/Hub/ConnectionFromUI.h b/Services/Hub/ConnectionFromUI.hindex 657febaa862..5bea69ba13e 100644--- a/Services/Hub/ConnectionFromUI.h+++ b/Services/Hub/ConnectionFromUI.h@@ -96,26 +96,6 @@ private: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::SessionWindowOpenedResponse session_window_opened(WebView::IsPrivate is_private) override;- virtual Messages::HubServer::SessionWindowClosingResponse session_window_closing(WebView::IsPrivate is_private, WebView::SessionStore::WindowClosing closing) override;- virtual void session_window_activated(WebView::IsPrivate is_private, WebView::SessionWindowId id) override;- virtual void session_window_geometry_changed(WebView::IsPrivate is_private, WebView::SessionWindowId id, WebView::SessionWindowGeometry geometry) override;- virtual Messages::HubServer::SessionTabOpenedResponse session_tab_opened(WebView::IsPrivate is_private, WebView::SessionStore::TabOpened opened) override;- virtual Messages::HubServer::SessionTabClosedResponse session_tab_closed(WebView::IsPrivate is_private, WebView::SessionStore::TabClosed closed) override;- virtual void session_tab_detached(WebView::IsPrivate is_private, WebView::SessionTabId id) override;- virtual void session_tab_moved(WebView::IsPrivate is_private, WebView::SessionStore::TabMoved moved) override;- virtual void session_tab_order_changed(WebView::IsPrivate is_private, WebView::SessionStore::TabOrderChanged changed) override;- virtual Messages::HubServer::SessionTabPinnedChangedResponse session_tab_pinned_changed(WebView::IsPrivate is_private, WebView::SessionTabId id, bool pinned) override;- virtual void session_active_tab_changed(WebView::IsPrivate is_private, WebView::SessionTabId id) override;- virtual void session_application_quitting(WebView::IsPrivate is_private) override;- virtual void session_application_quit_aborted(WebView::IsPrivate is_private) override;- virtual Messages::HubServer::SessionConsecutiveUncleanExitsResponse session_consecutive_unclean_exits(WebView::IsPrivate is_private) override;- virtual Messages::HubServer::SessionHasClosedUnitsResponse session_has_closed_units(WebView::IsPrivate is_private) override;- virtual Messages::HubServer::SessionTakeMostRecentlyClosedResponse session_take_most_recently_closed(WebView::IsPrivate is_private) override;- virtual Messages::HubServer::SessionRecentlyClosedUnitsResponse session_recently_closed_units(WebView::IsPrivate is_private, u64 limit) override;- virtual Messages::HubServer::SessionTakeClosedUnitResponse session_take_closed_unit(WebView::IsPrivate is_private, WebView::SessionWindowId id) override;- virtual Messages::HubServer::SessionTakeLaunchPlanResponse session_take_launch_plan(WebView::IsPrivate is_private) override;- virtual Messages::HubServer::SessionLoadTabHistoryResponse session_load_tab_history(WebView::IsPrivate is_private, WebView::SessionTabId 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;@@ -123,7 +103,7 @@ private:virtual void view_open_navigation_in_new_tab(u64 view_id, Web::HTML::PreparedNavigationDescriptor navigation, Web::HTML::ActivateTab activate_tab) override;virtual void view_open_navigation_in_new_window(u64 view_id, Web::HTML::PreparedNavigationDescriptor navigation, WebView::IsPrivate is_private) override;virtual void view_traverse_the_history_to_step(u64 view_id, i32 step) override;- virtual void view_set_session_tab_id(u64 view_id, Optional<WebView::SessionTabId> session_tab_id) override;+ virtual void view_set_reports_session_history(u64 view_id, bool reports_session_history) override;virtual void view_file_picker_closed(u64 view_id, Vector<Web::HTML::SelectedFile> selected_files) override;virtual void view_save_screenshot(u64 view_id, Gfx::ShareableBitmap bitmap) override;virtual void view_request_selected_text(u64 view_id, u64 request_id) override;diff --git a/Services/Hub/HubClient.ipc b/Services/Hub/HubClient.ipcindex b344821f6b1..67253b73b43 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/SessionHistory.h>#include <LibWebView/TabPerformanceStats.h>#include <LibWebCommon/Clipboard/SystemClipboard.h>#include <LibWebCommon/HTML/PreparedNavigationDescriptor.h>@@ -141,6 +142,8 @@ struct Hub::UIInfo {struct Hub::InitialState {ByteString settings_json;ByteString config_directory;+ ByteString data_directory;+ bool persists_sessions;String user_agent;Web::NavigatorCompatibilityMode navigator_compatibility_mode;bool scripting_enabled;@@ -175,6 +178,13 @@ struct WebView::ContextMenuRequest {Optional<Web::MediaContextMenu> media;}+[ExistingCpp]+struct WebView::SessionHistorySnapshot {+ Vector<Web::HTML::SessionHistoryEntryDescriptor> entries;+ Vector<i32> used_steps;+ size_t current_used_step_index;+}+// What the UI needs to know about a view at any time, without having to ask.struct Hub::ViewState {URL::URL url;@@ -257,7 +267,8 @@ endpoint HubClientapp_set_clipboard_text(String text, WebView::Application::ClipboardType type) =|app_insert_clipboard_item(Web::Clipboard::SystemClipboardItem item) =|app_update_tabs_display() =|- app_on_recently_closed_entries_changed() =|+ app_did_clear_history_since(UnixDateTime since) =|+ app_quit_for_signal() =|app_did_enable_devtools() =|app_did_disable_devtools() =|app_open_urls_in_new_tabs(Vector<URL::URL> urls) =|@@ -275,6 +286,7 @@ endpoint HubClientweb_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_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.ipcindex 8bbad611db6..6309ff775ba 100644--- a/Services/Hub/HubServer.ipc+++ b/Services/Hub/HubServer.ipc@@ -21,7 +21,6 @@#include <LibWebView/HistoryStore.h>#include <LibWebView/ProcessSnapshot.h>#include <LibWebView/SessionHistory.h>-#include <LibWebView/SessionStore.h>#include <LibWebView/Translator.h>#include <LibWebView/ViewImplementation.h>@@ -64,15 +63,6 @@ struct WebView::OmniboxEngagement {UnixDateTime used_at;}-[ExistingCpp]-struct WebView::SessionWindowGeometry {- i32 x;- i32 y;- i32 width;- i32 height;- bool maximized;-}-[ExistingCpp]struct WebView::HistoryEntry {String url;@@ -88,91 +78,6 @@ struct WebView::HistoryEntry {UnixDateTime score_updated_at;}-[ExistingCpp]-struct WebView::SessionHistorySnapshot {- Vector<Web::HTML::SessionHistoryEntryDescriptor> entries;- Vector<i32> used_steps;- size_t current_used_step_index;-}--[ExistingCpp]-struct WebView::SessionStore::TabOpened {- Optional<WebView::SessionWindowId> window_id;- URL::URL initial_url;- Optional<i64> insertion_index;- WebView::SessionStore::IsActive is_active;-}--[ExistingCpp]-struct WebView::ClosedSessionTab {- URL::URL active_url;- Optional<WebView::SessionHistorySnapshot> history;- bool pinned;-}--[ExistingCpp]-struct WebView::ClosedSessionUnit {- Vector<WebView::ClosedSessionTab> tabs;- i64 active_tab_index;- bool was_window;- Optional<WebView::SessionWindowId> source_window_id;- Optional<i64> source_tab_index;- WebView::ClosedSessionUnit::Origin origin;- Optional<WebView::SessionWindowGeometry> geometry;-}--[ExistingCpp]-struct WebView::RecentlyClosedSessionUnit {- WebView::SessionWindowId id;- URL::URL active_url;- size_t tab_count;- bool was_window;- bool from_startup_recovery;- UnixDateTime closed_at;-}--[ExistingCpp]-struct WebView::RestoredSessionTab {- WebView::SessionTabId tab_id;- URL::URL url;- bool pinned;-}--[ExistingCpp]-struct WebView::RestoredSessionWindow {- WebView::SessionWindowId window_id;- Vector<WebView::RestoredSessionTab> tabs;- i64 active_tab_index;- Optional<WebView::SessionWindowGeometry> geometry;-}--[ExistingCpp]-struct WebView::SessionStore::TabClosed {- WebView::SessionTabId tab_id;- UnixDateTime closed_at;- WebView::SessionStore::KeepForReopening keep_for_reopening;-}--[ExistingCpp]-struct WebView::SessionStore::TabMoved {- WebView::SessionTabId tab_id;- WebView::SessionWindowId new_window_id;- i64 ordinal;-}--[ExistingCpp]-struct WebView::SessionStore::TabOrderChanged {- WebView::SessionWindowId window_id;- Vector<WebView::SessionTabId> ordered_tabs;-}--[ExistingCpp]-struct WebView::SessionStore::WindowClosing {- WebView::SessionWindowId window_id;- i64 active_tab_index;- UnixDateTime closed_at;-}-[ExistingCpp]struct WebView::ViewImplementation::SessionHistoryTraversalMenuItem {i32 step;@@ -272,26 +177,6 @@ endpoint HubServerview_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)- session_window_opened(WebView::IsPrivate is_private) => (Optional<WebView::SessionWindowId> id)- session_window_closing(WebView::IsPrivate is_private, WebView::SessionStore::WindowClosing closing) => (bool succeeded)- session_window_activated(WebView::IsPrivate is_private, WebView::SessionWindowId id) =|- session_window_geometry_changed(WebView::IsPrivate is_private, WebView::SessionWindowId id, WebView::SessionWindowGeometry geometry) =|- session_tab_opened(WebView::IsPrivate is_private, WebView::SessionStore::TabOpened opened) => (Optional<WebView::SessionTabId> id)- session_tab_closed(WebView::IsPrivate is_private, WebView::SessionStore::TabClosed closed) => (bool succeeded)- session_tab_detached(WebView::IsPrivate is_private, WebView::SessionTabId id) =|- session_tab_moved(WebView::IsPrivate is_private, WebView::SessionStore::TabMoved moved) =|- session_tab_order_changed(WebView::IsPrivate is_private, WebView::SessionStore::TabOrderChanged changed) =|- session_tab_pinned_changed(WebView::IsPrivate is_private, WebView::SessionTabId id, bool pinned) => (bool succeeded)- session_active_tab_changed(WebView::IsPrivate is_private, WebView::SessionTabId id) =|- session_application_quitting(WebView::IsPrivate is_private) =|- session_application_quit_aborted(WebView::IsPrivate is_private) =|- session_consecutive_unclean_exits(WebView::IsPrivate is_private) => (u32 count)- session_has_closed_units(WebView::IsPrivate is_private) => (bool has_closed_units)- session_take_most_recently_closed(WebView::IsPrivate is_private) => (Optional<WebView::ClosedSessionUnit> unit)- session_recently_closed_units(WebView::IsPrivate is_private, u64 limit) => (Vector<WebView::RecentlyClosedSessionUnit> units)- session_take_closed_unit(WebView::IsPrivate is_private, WebView::SessionWindowId id) => (Optional<WebView::ClosedSessionUnit> unit)- session_take_launch_plan(WebView::IsPrivate is_private) => (Vector<WebView::RestoredSessionWindow> windows)- session_load_tab_history(WebView::IsPrivate is_private, WebView::SessionTabId id) => (Optional<WebView::SessionHistorySnapshot> history)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) =|@@ -308,7 +193,7 @@ endpoint HubServerview_ignore_misspelling(u64 view_id, Utf16String word) =|view_learn_misspelling(u64 view_id, Utf16String word) =|view_do_context_menu_media_action(u64 view_id, WebView::ContextMenuMediaAction action) =|- view_set_session_tab_id(u64 view_id, Optional<WebView::SessionTabId> session_tab_id) =|+ view_set_reports_session_history(u64 view_id, bool reports_session_history) =|view_file_picker_closed(u64 view_id, Vector<Web::HTML::SelectedFile> selected_files) =|view_save_screenshot(u64 view_id, Gfx::ShareableBitmap bitmap) =|view_request_selected_text(u64 view_id, u64 request_id) =|diff --git a/Services/Hub/View.cpp b/Services/Hub/View.cppindex 1c4643fddf6..84a0baf4572 100644--- a/Services/Hub/View.cpp+++ b/Services/Hub/View.cpp@@ -712,4 +712,10 @@ void View::did_make_link_to_highlight(Optional<URL::URL> url)ui->async_view_did_make_link_to_highlight(view_id(), move(url));}+void View::did_change_session_history(WebView::SessionHistorySnapshot const& history, URL::URL const& url)+{+ if (auto* ui = ConnectionFromUI::the())+ ui->async_view_session_history_changed(view_id(), history, url);+}+}diff --git a/Services/Hub/View.h b/Services/Hub/View.hindex 14646117dca..6c6994ea5f3 100644--- a/Services/Hub/View.h+++ b/Services/Hub/View.h@@ -65,6 +65,7 @@ private:virtual Gfx::IntPoint to_widget_position(Gfx::IntPoint content_position) const override { return content_position; }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 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/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cppindex d496a5585d5..1ef55d54904 100644--- a/Services/WebContent/PageClient.cpp+++ b/Services/WebContent/PageClient.cpp@@ -2052,17 +2052,17 @@ bool PageClient::page_did_request_restore_session_history_snapshot_for_testing()return false;}-bool PageClient::page_did_request_register_session_store_tab_for_testing()+bool PageClient::page_did_request_record_reported_session_history_for_testing(){if (auto* test_connection = client().test_connection())- return test_connection->did_request_register_session_store_tab_for_testing(m_id);+ return test_connection->did_request_record_reported_session_history_for_testing(m_id);return false;}-String PageClient::page_did_request_session_store_tab_state_for_testing()+String PageClient::page_did_request_reported_session_history_for_testing(){if (auto* test_connection = client().test_connection())- return test_connection->did_request_session_store_tab_state_for_testing(m_id);+ return test_connection->did_request_reported_session_history_for_testing(m_id);return "{}"_string;}diff --git a/Services/WebContent/PageClient.h b/Services/WebContent/PageClient.hindex 039e45d3811..707d7d8aaec 100644--- a/Services/WebContent/PageClient.h+++ b/Services/WebContent/PageClient.h@@ -353,8 +353,8 @@ private:virtual u64 page_did_request_tab_audibility_change_count_for_testing() override;virtual bool page_did_request_capture_session_history_snapshot_for_testing() override;virtual bool page_did_request_restore_session_history_snapshot_for_testing() override;- virtual bool page_did_request_register_session_store_tab_for_testing() override;- virtual String page_did_request_session_store_tab_state_for_testing() override;+ virtual bool page_did_request_record_reported_session_history_for_testing() override;+ virtual String page_did_request_reported_session_history_for_testing() override;virtual void request_file(Web::FileRequest) override;virtual URL::BlobURLEntry::Token page_did_add_blob_url_entry(Web::HTML::EnvironmentSettingsObject const&, Utf16String const& url, Web::FileAPI::SerializedBlobURLEntry const&) override;virtual void page_did_remove_blob_url_entries(Web::HTML::EnvironmentSettingsObject const&, Vector<Utf16String> const& urls) override;diff --git a/Services/WebContent/WebContentTestClient.ipc b/Services/WebContent/WebContentTestClient.ipcindex 6b7551cfa75..7127a66454f 100644--- a/Services/WebContent/WebContentTestClient.ipc+++ b/Services/WebContent/WebContentTestClient.ipc@@ -47,8 +47,8 @@ endpoint WebContentTestClient routed by Web::PageId page_iddid_reset_state_for_testing(Web::PageId page_id, Web::HTML::SessionHistoryEntryDescriptor active_entry) =|[NotRouted] did_request_capture_session_history_snapshot_for_testing(Web::PageId page_id) => (bool captured)[NotRouted] did_request_restore_session_history_snapshot_for_testing(Web::PageId page_id) => (bool restored)- [NotRouted] did_request_register_session_store_tab_for_testing(Web::PageId page_id) => (bool registered)- [NotRouted] did_request_session_store_tab_state_for_testing(Web::PageId page_id) => (String state)+ [NotRouted] did_request_record_reported_session_history_for_testing(Web::PageId page_id) => (bool registered)+ [NotRouted] did_request_reported_session_history_for_testing(Web::PageId page_id) => (String state)create_virtual_gamepad() => (Optional<Web::Gamepad::VirtualGamepad> virtual_gamepad)set_virtual_gamepad_button(Web::Gamepad::GamepadHandle handle, i32 button, bool down) =|diff --git a/Tests/LibWeb/Text/input/navigation/restore-session-history-snapshot-round-trip.html b/Tests/LibWeb/Text/input/navigation/restore-session-history-snapshot-round-trip.htmlindex 9565daf64a7..badd2f6387c 100644--- a/Tests/LibWeb/Text/input/navigation/restore-session-history-snapshot-round-trip.html+++ b/Tests/LibWeb/Text/input/navigation/restore-session-history-snapshot-round-trip.html@@ -30,8 +30,8 @@}asyncTest(async done => {- if (!internals.registerSessionStoreTab()) {- println("FAIL: could not register the tab in the session store");+ if (!internals.recordReportedSessionHistory()) {+ println("FAIL: could not record the reported session history");done();return;}@@ -62,6 +62,6 @@await pollUIHistory(history => entryQueries(history) === "?a,?b,?c*");sessionStorage.setItem(phaseKey, "restored");sessionStorage.setItem("restore-round-trip-restore", internals.restoreCapturedSessionHistorySnapshot());- sessionStorage.setItem("restore-round-trip-store-url", queryFromURL(JSON.parse(internals.dumpSessionStoreTabState()).url));+ sessionStorage.setItem("restore-round-trip-store-url", queryFromURL(JSON.parse(internals.dumpReportedSessionHistory()).url));});</script>diff --git a/Tests/LibWeb/Text/input/navigation/targeted-entry-updates-reach-the-session-store.html b/Tests/LibWeb/Text/input/navigation/targeted-entry-updates-reach-the-session-store.htmlindex ef368fd840e..6e6f63501d7 100644--- a/Tests/LibWeb/Text/input/navigation/targeted-entry-updates-reach-the-session-store.html+++ b/Tests/LibWeb/Text/input/navigation/targeted-entry-updates-reach-the-session-store.html@@ -2,13 +2,13 @@<script src="../include.js"></script><script>function currentStoreEntry() {- return JSON.parse(internals.dumpSessionStoreTabState()).entries.find(entry => entry.current);+ return JSON.parse(internals.dumpReportedSessionHistory()).entries.find(entry => entry.current);}asyncTest(done => {window.addEventListener("load", () => {- if (!internals.registerSessionStoreTab()) {- println("FAIL: could not register the tab in the session store");+ if (!internals.recordReportedSessionHistory()) {+ println("FAIL: could not record the reported session history");done();return;}diff --git a/Tests/LibWebView/CMakeLists.txt b/Tests/LibWebView/CMakeLists.txtindex 8479be61ac8..235b9767439 100644--- a/Tests/LibWebView/CMakeLists.txt+++ b/Tests/LibWebView/CMakeLists.txt@@ -74,9 +74,7 @@ set(TEST_SOURCESTestPictureInPictureWindow.cppTestProfile.cppTestSessionHistory.cpp- TestSessionHistorySnapshotStorage.cppTestSessionHistoryTraversalQueue.cpp- TestSessionStore.cppTestSiteCompatibilityDataLoading.cppTestStartupSettings.cppTestStorageAreaRegistry.cppdiff --git a/Tests/LibWebView/TestApplicationDestruction.cpp b/Tests/LibWebView/TestApplicationDestruction.cppindex 94e77a20f46..76a4e3ba7e9 100644--- a/Tests/LibWebView/TestApplicationDestruction.cpp+++ b/Tests/LibWebView/TestApplicationDestruction.cpp@@ -9,6 +9,7 @@#include <LibCore/EventLoop.h>#include <LibCore/StandardPaths.h>#include <LibCore/ThreadEventQueue.h>+#include <LibDatabase/Database.h>#include <LibFileSystem/FileSystem.h>#include <LibGfx/SystemTheme.h>#include <LibWebView/Application.h>diff --git a/Tests/UI/Qt/CMakeLists.txt b/Tests/UI/Qt/CMakeLists.txtindex db733d54365..df0556e8484 100644--- a/Tests/UI/Qt/CMakeLists.txt+++ b/Tests/UI/Qt/CMakeLists.txt@@ -8,7 +8,7 @@ add_library(QtTestMain OBJECT)target_link_libraries(QtTestMain PRIVATE AK LibCore LibTest Qt::Core Qt::Gui Qt::Widgets)ladybird_test_suite(UI/Qt NO_TEST CUSTOM_MAIN "$<TARGET_OBJECTS:QtTestMain>")-target_link_libraries(TestUIQt PRIVATE LibCore LibFileSystem LibGfx LibIPC LibURL LibWeb LibWebCommon LibWebView ladybird_impl)+target_link_libraries(TestUIQt PRIVATE LibCore LibDatabase LibFileSystem LibGfx LibIPC LibURL LibWeb LibWebCommon LibWebView ladybird_impl)add_library(QtEventLoopTestMain OBJECTQtEventLoopTestMain.cpp@@ -39,6 +39,8 @@ set(TEST_SOURCESTestScreenshotSelectionOverlay.cppTestScreenshotViewer.cppTestSelectDropdown.cpp+ TestSessionHistorySnapshotStorage.cpp+ TestSessionStore.cppTestSiteSettingsPopover.cppTestStringUtils.cppTestWebCompatReportReview.cppdiff --git a/Tests/LibWebView/TestSessionHistorySnapshotStorage.cpp b/Tests/UI/Qt/TestSessionHistorySnapshotStorage.cppsimilarity index 99%rename from Tests/LibWebView/TestSessionHistorySnapshotStorage.cpprename to Tests/UI/Qt/TestSessionHistorySnapshotStorage.cppindex 8e909ca061a..de10b7f016a 100644--- a/Tests/LibWebView/TestSessionHistorySnapshotStorage.cpp+++ b/Tests/UI/Qt/TestSessionHistorySnapshotStorage.cpp@@ -8,9 +8,10 @@#include <LibTest/TestCase.h>#include <LibURL/Origin.h>#include <LibURL/Parser.h>-#include <LibWebView/SessionHistorySnapshotStorage.h>-#include <LibWebView/SessionStore.h>+#include <UI/Qt/SessionHistorySnapshotStorage.h>+#include <UI/Qt/SessionStore.h>+using namespace Ladybird;using namespace WebView;static URL::Origin::OpaqueData::Nonce sequential_nonce()@@ -290,7 +291,7 @@ static NonnullRefPtr<Database::Database> make_database()static SessionHistorySnapshotStatements prepare_snapshot_tables(Database::Database& database){- MUST(WebView::SessionStore::migrate_schema(database));+ MUST(SessionStore::migrate_schema(database));return MUST(prepare_session_history_snapshot_statements(database));}diff --git a/Tests/LibWebView/TestSessionStore.cpp b/Tests/UI/Qt/TestSessionStore.cppsimilarity index 99%rename from Tests/LibWebView/TestSessionStore.cpprename to Tests/UI/Qt/TestSessionStore.cppindex c77733dfbae..c57187d2ed8 100644--- a/Tests/LibWebView/TestSessionStore.cpp+++ b/Tests/UI/Qt/TestSessionStore.cpp@@ -7,8 +7,9 @@#include <LibDatabase/Database.h>#include <LibTest/TestCase.h>#include <LibURL/Parser.h>-#include <LibWebView/SessionStore.h>+#include <UI/Qt/SessionStore.h>+using namespace Ladybird;using namespace WebView;static URL::URL parse_url(StringView url)@@ -101,7 +102,7 @@ static void quit_cleanly(SessionStore& store, Vector<SessionWindowId> const& winTEST_CASE(fresh_database_migrates_to_the_latest_schema){auto database = TRY_OR_FAIL(Database::Database::create_memory_backed({ .foreign_keys = Database::Database::ForeignKeys::Yes }));- EXPECT_EQ(TRY_OR_FAIL(WebView::SessionStore::migrate_schema(*database)), Database::MigrationOutcome::Success);+ EXPECT_EQ(TRY_OR_FAIL(SessionStore::migrate_schema(*database)), Database::MigrationOutcome::Success);for (auto table : { "Sessions"sv, "SessionTabs"sv, "SessionUsedSteps"sv, "SessionHistories"sv, "SessionNestedHistories"sv, "SessionEntries"sv, "SessionUpgradeInsecureNavigations"sv })EXPECT(TRY_OR_FAIL(database->table_exists(table)));@@ -141,8 +142,8 @@ TEST_CASE(newer_sessions_schema_reports_database_too_new)TRY_OR_FAIL(database->execute_raw("CREATE TABLE SchemaVersions (store TEXT PRIMARY KEY, version INTEGER NOT NULL);"sv));TRY_OR_FAIL(database->execute_raw("INSERT INTO SchemaVersions (store, version) VALUES ('Sessions', 99);"sv));- EXPECT_EQ(TRY_OR_FAIL(WebView::SessionStore::migrate_schema(*database)), Database::MigrationOutcome::DatabaseTooNew);- EXPECT_EQ(TRY_OR_FAIL(WebView::SessionStore::migrate_schema(*database, Database::MigrationMode::CheckOnly)), Database::MigrationOutcome::DatabaseTooNew);+ EXPECT_EQ(TRY_OR_FAIL(SessionStore::migrate_schema(*database)), Database::MigrationOutcome::DatabaseTooNew);+ EXPECT_EQ(TRY_OR_FAIL(SessionStore::migrate_schema(*database, Database::MigrationMode::CheckOnly)), Database::MigrationOutcome::DatabaseTooNew);}TEST_CASE(version_4_database_migrates_to_the_latest_schema)diff --git a/UI/Qt/Application.cpp b/UI/Qt/Application.cppindex 869ac59b649..b173c4ea48f 100644--- a/UI/Qt/Application.cpp+++ b/UI/Qt/Application.cpp@@ -7,10 +7,12 @@#include <AK/Hex.h>#include <LibCore/ArgsParser.h>#include <LibCore/Environment.h>+#include <LibCore/EventLoop.h>#include <LibCore/GeolocationProvider.h>#include <LibCore/Process.h>#include <LibCore/Socket.h>#include <LibCore/System.h>+#include <LibDatabase/Database.h>#include <LibIPC/Encoder.h>#include <LibIPC/Transport.h>#include <LibURL/InternalURLs.h>@@ -37,7 +39,6 @@# include <LibWebView/NotificationBackendFreedesktop.h>#endif#include <LibWebView/NoOpNotificationBackend.h>-#include <LibWebView/SessionStore.h>#include <LibWebView/Translator.h>#include <LibWebView/URL.h>#include <LibWebView/Utilities.h>@@ -53,7 +54,7 @@#include <UI/Qt/PlainText.h>#include <UI/Qt/ProcessManagerWindow.h>#include <UI/Qt/RemoteDownloads.h>-#include <UI/Qt/RemoteSession.h>+#include <UI/Qt/SessionStore.h>#include <UI/Qt/StringUtils.h>#include <UI/Qt/Tab.h>#include <UI/Qt/Theme.h>@@ -505,7 +506,7 @@ public:m_reopen_recently_closed_tab_action->setText("&Reopen Closed Tab");auto* active_window = Application::the().active_window_if_any();- auto& session = active_window ? active_window->session() : RemoteSession::of(WebView::IsPrivate::No);+ auto& session = active_window ? active_window->session() : Application::session_store(WebView::IsPrivate::No);m_reopen_recently_closed_tab_action->setEnabled(session.has_closed_units());}@@ -798,6 +799,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);// 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();@@ -905,7 +907,20 @@ Application::~Application()// NB: The application tears down its processes as it goes, which must happen after the QApplication is gone, and// with nothing left here to call back into.ScopeGuard tear_down_hub = [this] {- // NB: The views go along with the windows that showed them, and their timers need the QApplication.+#if !defined(AK_OS_WINDOWS)+ // No event loop runs the handlers during teardown, so a signal from here on takes its default action again.+ for (auto handler : m_session_signal_handlers)+ Core::EventLoop::unregister_signal(handler);+#endif++ // Only a normal exit gets this far, after every window is gone. A crash, or the Hub going away, ends this+ // process at once, so it never records a clean exit.+ if (m_session_store) {+ m_session_store->flush_dirty_state();+ m_session_store->mark_clean_exit();+ }++ // NB: The views go along with the windows that showed them, and their timers need the QApplication.#ifndef LADYBIRD_HUB_IN_OWN_PROCESSif (m_hub)m_hub->destroy_all_views();@@ -972,6 +987,7 @@ void Application::create_platform_actions()m_settings = make<WebView::Settings>(WebView::Settings::create_from_json(WebView::Application::settings().serialize_json()));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());m_application_actions = make<ApplicationActions>(ApplicationActions::PageOptions {.user_agent = hub.user_agent_string(),.navigator_compatibility_mode = hub.navigator_compatibility_mode(),@@ -1182,15 +1198,87 @@ void Application::present_window(BrowserWindow& window, WindowConfiguration cons}}-WebView::SessionLaunchPolicy Application::launch_restore_policy() const+SessionLaunchPolicy Application::launch_restore_policy() const{// Without the setting, only pinned tabs come back; with it, every window and tab does.if (Application::settings().restore_previous_session())- return WebView::SessionLaunchPolicy::Everything;- return WebView::SessionLaunchPolicy::PinnedOnly;+ return SessionLaunchPolicy::Everything;+ return SessionLaunchPolicy::PinnedOnly;}-static WindowConfiguration window_configuration_for(WebView::SessionWindowGeometry const& geometry)+void Application::create_session_store(ByteString const& data_directory, bool persists_sessions)+{+ auto session_store = [&]() -> ErrorOr<NonnullOwnPtr<SessionStore>> {+ if (!persists_sessions)+ return SessionStore::create();++ // Fall back without modifying the existing Sessions database.+ auto session_database = TRY(Database::Database::create(data_directory, "Sessions"sv, { .foreign_keys = Database::Database::ForeignKeys::Yes }));+ if (TRY(SessionStore::migrate_schema(session_database)) != Database::MigrationOutcome::Success)+ return Error::from_string_literal("Sessions database was created by a newer Ladybird version");+ return SessionStore::create(session_database, launch_restore_policy());+ }();+ if (session_store.is_error()) {+ dbgln("Sessions will not be persisted this session: {}", session_store.error());+ m_session_store = SessionStore::create();+ } else {+ m_session_store = session_store.release_value();+ }++ m_session_store->on_closed_units_changed = [this] {+ on_recently_closed_entries_changed();+ };++#if !defined(AK_OS_WINDOWS) && defined(LADYBIRD_HUB_IN_OWN_PROCESS)+ // A run stopped by SIGINT or SIGTERM ends like a quit, rather than like a crash: It saves the session, leaves its+ // windows for the next launch to recover, and records a clean exit. The Hub hears of a signal sent to it alone, and+ // passes it on.+ if (m_session_store->is_persistent()) {+ for (auto signal_number : { SIGINT, SIGTERM }) {+ m_session_signal_handlers.append(Core::EventLoop::register_signal(signal_number, [this](int) {+ quit_for_signal();+ }));+ }+ }+#endif+}++SessionStore& Application::session_store(WebView::IsPrivate is_private)+{+ if (is_private == WebView::IsPrivate::No)+ return *s_the->m_session_store;++ // NB: Private windows keep nothing for the next run, and the next private session starts with nothing.+ if (!s_the->m_private_session_store)+ s_the->m_private_session_store = SessionStore::create();+ return *s_the->m_private_session_store;+}++void Application::did_clear_history_since(UnixDateTime since)+{+ for (auto* store : { m_session_store.ptr(), m_private_session_store.ptr() }) {+ if (!store)+ continue;+ if (auto result = store->remove_entries_accessed_since(since); result.is_error())+ dbgln("Unable to remove closed session entries: {}", result.error());+ }+ on_recently_closed_entries_changed();+}++void Application::quit_for_signal()+{+ if (m_quit_is_finishing)+ return;++ // The windows stay open in the session store, for the next launch to recover.+ // NB: QApplication::quit() would ask the windows to close first, which their pages may refuse. A signal does not+ // wait for them, so this ends the event loop directly.+ m_quit_is_finishing = true;+ session_store(WebView::IsPrivate::No).application_quitting();+ Core::EventLoop::current().quit(0);+}++static WindowConfiguration window_configuration_for(SessionWindowGeometry const& geometry){QRect rect { geometry.x, geometry.y, geometry.width, geometry.height };@@ -1216,7 +1304,7 @@ static WindowConfiguration window_configuration_for(WebView::SessionWindowGeometBrowserWindow* Application::restore_previous_session(WindowConfiguration const& frontmost_window_configuration){- auto plan = RemoteSession::of(WebView::IsPrivate::No).take_launch_plan();+ auto plan = session_store(WebView::IsPrivate::No).take_launch_plan();BrowserWindow* frontmost_window = nullptr;for (size_t i = 0; i < plan.size(); ++i) {@@ -1236,13 +1324,13 @@ BrowserWindow* Application::restore_previous_session(WindowConfiguration const&void Application::offer_to_restore_unexpectedly_closed_tabs(BrowserWindow& window){- auto& session_store = RemoteSession::of(WebView::IsPrivate::No);- if (session_store.consecutive_unclean_exits() == 0)+ auto& store = session_store(WebView::IsPrivate::No);+ if (store.consecutive_unclean_exits() == 0)return;- Vector<WebView::SessionWindowId> unit_ids;+ Vector<SessionWindowId> unit_ids;size_t tab_count = 0;- for (auto const& unit : session_store.recently_closed_units(NumericLimits<size_t>::max())) {+ for (auto const& unit : store.recently_closed_units(NumericLimits<size_t>::max())) {if (!unit.from_startup_recovery)continue;unit_ids.append(unit.id);@@ -1398,6 +1486,13 @@ void Application::finish_private_session_restart()}HubConnection::the().async_reset_private_browsing_session();++ // Views pending deferred deletion may still report their history, and the replacement store reuses their ids.+ RemoteView::for_each([](RemoteView& view) {+ if (view.is_private() == WebView::IsPrivate::Yes)+ view.clear_session_tab_id();+ });+ m_private_session_store = nullptr;open_new_window(WebView::IsPrivate::Yes);for (auto const& window : windows) {@@ -1432,10 +1527,10 @@ void Application::focus_location_editor()tab->focus_location_editor();}-void Application::reopen_recently_closed_tab(BrowserWindow* target_window, Optional<WebView::SessionWindowId> unit_id, ReopenClosedWindow reopen_closed_window)+void Application::reopen_recently_closed_tab(BrowserWindow* target_window, Optional<SessionWindowId> unit_id, ReopenClosedWindow reopen_closed_window){auto is_private = target_window ? target_window->is_private() : WebView::IsPrivate::No;- auto& session = target_window ? target_window->session() : RemoteSession::of(WebView::IsPrivate::No);+ auto& session = target_window ? target_window->session() : session_store(WebView::IsPrivate::No);auto closed_unit = unit_id.has_value() ? session.take_closed_unit(*unit_id) : session.take_most_recently_closed();if (closed_unit.is_error()) {dbgln("Unable to reopen the most recently closed session unit: {}", closed_unit.error());@@ -1611,7 +1706,7 @@ void Application::finish_quit()// The session store hears of the quit only once every window has agreed, so a canceled quit never reaches it. In// quitting mode, it keeps each window that closes as an open one, for the next launch to recover.m_quit_is_finishing = true;- RemoteSession::of(WebView::IsPrivate::No).application_quitting();+ session_store(WebView::IsPrivate::No).application_quitting();// Each window's pages agreed, so it closes at once; the active window goes last, so no close activates another.auto windows = visible_browser_windows_active_first(m_active_window);diff --git a/UI/Qt/Application.h b/UI/Qt/Application.hindex 5bc27a6bb7e..dde3cfa8641 100644--- a/UI/Qt/Application.h+++ b/UI/Qt/Application.h@@ -88,6 +88,9 @@ public:static Bookmarks& bookmarks() { return *s_the->m_bookmarks; }static BookmarkStore& bookmark_store() { return *s_the->m_bookmark_store; }+ // 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);+virtual ~Application() override;Function<void(URL::URL)> on_open_file;@@ -101,7 +104,7 @@ public:// After the last run ended unexpectedly, offers to restore the tabs it left open that didn't come back by themselves.void offer_to_restore_unexpectedly_closed_tabs(BrowserWindow&);void open_startup_tabs(BrowserWindow&, Vector<URL::URL> const&);- WebView::SessionLaunchPolicy launch_restore_policy() const;+ SessionLaunchPolicy launch_restore_policy() const;void open_new_tab();void open_new_window(WebView::IsPrivate);@@ -110,7 +113,7 @@ public:InTargetWindow,};// Reopens the given closed tab or window, or else the one closed most recently.- void reopen_recently_closed_tab(BrowserWindow* target_window, Optional<WebView::SessionWindowId> = {}, ReopenClosedWindow = ReopenClosedWindow::InNewWindow);+ void reopen_recently_closed_tab(BrowserWindow* target_window, Optional<SessionWindowId> = {}, ReopenClosedWindow = ReopenClosedWindow::InNewWindow);void open_file();void restart_private_browsing_session();@@ -262,6 +265,9 @@ private:void did_enable_devtools() const;void did_disable_devtools() const;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 quit_for_signal();static Application* s_the;@@ -289,6 +295,9 @@ private:OwnPtr<WebView::Translator> m_translator;OwnPtr<WebView::Settings> m_settings;OwnPtr<BookmarkStore> m_bookmark_store;+ OwnPtr<SessionStore> m_session_store;+ OwnPtr<SessionStore> m_private_session_store;+ Vector<int> m_session_signal_handlers;OwnPtr<Bookmarks> m_bookmarks;OwnPtr<ApplicationActions> m_application_actions;RefPtr<HubConnection> m_hub_connection;diff --git a/UI/Qt/BrowserWindow.cpp b/UI/Qt/BrowserWindow.cppindex c510c8fdf4c..edda5003b09 100644--- a/UI/Qt/BrowserWindow.cpp+++ b/UI/Qt/BrowserWindow.cpp@@ -16,7 +16,6 @@#include <LibCore/EventLoop.h>#include <LibWebView/Application.h>#include <LibWebView/HistoryStore.h>-#include <LibWebView/SessionStore.h>#include <LibWebView/URL.h>#include <UI/Qt/Application.h>#include <UI/Qt/BrowserWindow.h>@@ -30,7 +29,7 @@#include <UI/Qt/Motion.h>#include <UI/Qt/Popover.h>#include <UI/Qt/RemoteDownloads.h>-#include <UI/Qt/RemoteSession.h>+#include <UI/Qt/SessionStore.h>#include <UI/Qt/StringUtils.h>#include <UI/Qt/SystemAppearance.h>#if defined(AK_OS_MACOS)@@ -340,7 +339,7 @@ static QIcon const& app_icon(WebView::IsPrivate is_private)return cached_icon;}-BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, IsPopupWindow is_popup_window, WebView::IsPrivate is_private, Optional<u64> hub_view_id, Optional<WebView::SessionWindowId> restored_session_window_id)+BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, IsPopupWindow is_popup_window, WebView::IsPrivate is_private, Optional<u64> hub_view_id, Optional<SessionWindowId> restored_session_window_id): WebView::SettingsObserver(Application::settings()), m_is_private(is_private), m_tabs_container(new TabWidget(is_private, this))@@ -785,7 +784,7 @@ void BrowserWindow::open_history_entry_in_new_tab(Tab& source_tab, int delta, Weduplicate_tab(source_tab, activate_tab, *step);}-void BrowserWindow::restore_tabs(Vector<WebView::RestoredSessionTab> const& tabs, i64 active_tab_index)+void BrowserWindow::restore_tabs(Vector<RestoredSessionTab> const& tabs, i64 active_tab_index){if (tabs.is_empty())return;@@ -800,11 +799,25 @@ void BrowserWindow::restore_tabs(Vector<WebView::RestoredSessionTab> const& tabs}}-Tab& BrowserWindow::create_restored_tab(WebView::RestoredSessionTab const& restored, int index, bool defer)+SessionStore& BrowserWindow::session() const+{+ return Application::session_store(m_is_private);+}++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+}++Tab& BrowserWindow::create_restored_tab(RestoredSessionTab const& restored, int index, bool defer){if (defer) {// Until the tab loads, it shows what browsing history knows about its page.- auto entry = session().entry_for_url(restored.url);+ auto entry = history_entry_for_url(restored.url);DeferredTab deferred_tab {.session_tab_id = restored.tab_id,.url = restored.url,@@ -913,11 +926,11 @@ void BrowserWindow::initialize_tab(Tab* tab){if (m_session_window_id.has_value() && !tab->session_tab_id().has_value()) {auto insertion_index = tab_index(tab);- WebView::SessionStore::TabOpened opened {+ SessionStore::TabOpened opened {.window_id = m_session_window_id,.initial_url = {},.insertion_index = insertion_index >= 0 ? Optional<i64> { insertion_index } : Optional<i64> {},- .is_active = m_current_tab == tab ? WebView::SessionStore::IsActive::Yes : WebView::SessionStore::IsActive::No,+ .is_active = m_current_tab == tab ? SessionStore::IsActive::Yes : SessionStore::IsActive::No,};auto session_tab_id = session().tab_opened(AK::move(opened));if (session_tab_id.is_error())@@ -1001,7 +1014,7 @@ void BrowserWindow::adopt_tab(Tab& tab, int index)if (moved_tab_id.has_value()) {if (m_session_window_id.has_value()) {- WebView::SessionStore::TabMoved moved {+ SessionStore::TabMoved moved {.tab_id = *moved_tab_id,.new_window_id = *m_session_window_id,.ordinal = index,@@ -1144,15 +1157,15 @@ Tab* BrowserWindow::activate_tab_with_url(URL::URL const& url, URL::ExcludeFragmbool BrowserWindow::definitely_close_tab(int index){- return close_tab(index, WebView::SessionStore::KeepForReopening::Yes);+ return close_tab(index, SessionStore::KeepForReopening::Yes);}void BrowserWindow::close_tab_without_keeping_it(int index){- (void)close_tab(index, WebView::SessionStore::KeepForReopening::No);+ (void)close_tab(index, SessionStore::KeepForReopening::No);}-bool BrowserWindow::close_tab(int index, WebView::SessionStore::KeepForReopening keep_for_reopening)+bool BrowserWindow::close_tab(int index, SessionStore::KeepForReopening keep_for_reopening){cancel_window_close_preflight();@@ -1164,7 +1177,7 @@ bool BrowserWindow::close_tab(int index, WebView::SessionStore::KeepForReopeningauto* tab = m_tabs_container->tab(index);m_tabs_container->remove_tab(index);if (auto session_tab_id = tab->session_tab_id(); session_tab_id.has_value()) {- WebView::SessionStore::TabClosed closed {+ SessionStore::TabClosed closed {.tab_id = *session_tab_id,.closed_at = UnixDateTime::now(),.keep_for_reopening = keep_for_reopening,@@ -1266,14 +1279,14 @@ void BrowserWindow::sync_session_tab_order()if (!m_session_window_id.has_value())return;- Vector<WebView::SessionTabId> tab_order;+ Vector<SessionTabId> tab_order;tab_order.ensure_capacity(m_tabs_container->count());for (int i = 0; i < m_tabs_container->count(); ++i) {if (auto session_tab_id = m_tabs_container->tab(i)->session_tab_id(); session_tab_id.has_value())tab_order.append(*session_tab_id);}- WebView::SessionStore::TabOrderChanged changed {+ SessionStore::TabOrderChanged changed {.window_id = *m_session_window_id,.ordered_tabs = AK::move(tab_order),};@@ -2064,7 +2077,7 @@ void BrowserWindow::closeEvent(QCloseEvent* event)QMainWindow::closeEvent(event);if (event->isAccepted() && m_session_window_id.has_value()) {- WebView::SessionStore::WindowClosing closing {+ SessionStore::WindowClosing closing {.window_id = *m_session_window_id,.active_tab_index = active_tab_index,.closed_at = UnixDateTime::now(),@@ -2136,7 +2149,7 @@ void BrowserWindow::report_session_window_geometry()// A maximized window keeps the geometry it had before, for when it's restored.auto rect = isMaximized() ? normalGeometry() : geometry();- WebView::SessionWindowGeometry window_geometry {+ SessionWindowGeometry window_geometry {.x = rect.x(),.y = rect.y(),.width = rect.width(),diff --git a/UI/Qt/BrowserWindow.h b/UI/Qt/BrowserWindow.hindex 89eaa987208..b524a9bf481 100644--- a/UI/Qt/BrowserWindow.h+++ b/UI/Qt/BrowserWindow.h@@ -14,10 +14,9 @@#include <LibWebCommon/Page/PageId.h>#include <LibWebView/BrowsingSession.h>#include <LibWebView/Forward.h>-#include <LibWebView/SessionStore.h>#include <LibWebView/Settings.h>#include <UI/Qt/FullscreenDebounce.h>-#include <UI/Qt/RemoteSession.h>+#include <UI/Qt/SessionStore.h>#include <UI/Qt/Tab.h>#include <UI/Qt/TabBar.h>#include <UI/Qt/WindowCloseCoordinator.h>@@ -150,13 +149,14 @@ public:int m_index { 0 };};- BrowserWindow(Vector<URL::URL> const& initial_urls, IsPopupWindow is_popup_window = IsPopupWindow::No, WebView::IsPrivate = WebView::IsPrivate::No, Optional<u64> hub_view_id = {}, Optional<WebView::SessionWindowId> restored_session_window_id = {});+ BrowserWindow(Vector<URL::URL> const& initial_urls, IsPopupWindow is_popup_window = IsPopupWindow::No, WebView::IsPrivate = WebView::IsPrivate::No, Optional<u64> hub_view_id = {}, Optional<SessionWindowId> restored_session_window_id = {});virtual ~BrowserWindow() override;WebContentView& view() const { return m_current_tab->view(); }WebView::IsPrivate is_private() const { return m_is_private; }- RemoteSession& session() const { return RemoteSession::of(m_is_private); }- Optional<WebView::SessionWindowId> session_window_id() const { return m_session_window_id; }+ SessionStore& session() const;+ Optional<WebView::HistoryEntry> history_entry_for_url(URL::URL const&) const;+ Optional<SessionWindowId> session_window_id() const { return m_session_window_id; }int tab_count() { return m_tabs_container->count(); }int tab_index(Tab*);@@ -180,7 +180,7 @@ public:void open_history_entry_in_new_tab(Tab&, int delta, Web::HTML::ActivateTab);void update_tab_audio_button(Tab&);// Opens a window's restored tabs, keeping the session rows the store re-adopted for them.- void restore_tabs(Vector<WebView::RestoredSessionTab> const&, i64 active_tab_index);+ void restore_tabs(Vector<RestoredSessionTab> const&, i64 active_tab_index);Tab* current_tab() const { return m_current_tab; }Tab* activate_tab_with_url(URL::URL const&, URL::ExcludeFragment);// Asks every tab's page if the window may close, without closing it, and reports the answer. Once the pages agree,@@ -260,7 +260,7 @@ public slots:void exit_fullscreen();private:- bool close_tab(int index, WebView::SessionStore::KeepForReopening);+ bool close_tab(int index, SessionStore::KeepForReopening);virtual bool event(QEvent*) override;virtual bool eventFilter(QObject*, QEvent*) override;virtual void resizeEvent(QResizeEvent*) override;@@ -273,7 +273,7 @@ private:virtual void appearance_changed() override;virtual void config_variable_changed(WebView::ConfigVariableID) override;- Tab& create_restored_tab(WebView::RestoredSessionTab const&, int index, bool defer);+ Tab& create_restored_tab(RestoredSessionTab const&, int index, bool defer);void initialize_tab(Tab*);void initialize_tab_view(Tab*);void uninitialize_tab(Tab*);@@ -347,7 +347,7 @@ private:IsPopupWindow m_is_popup_window { IsPopupWindow::No };- Optional<WebView::SessionWindowId> m_session_window_id;+ Optional<SessionWindowId> m_session_window_id;size_t m_failed_download_count { 0 };size_t m_acknowledged_failed_download_count { 0 };Optional<i64> m_window_close_active_tab_index;diff --git a/UI/Qt/CMakeLists.txt b/UI/Qt/CMakeLists.txtindex 39e3f0cf897..51334e4b8b8 100644--- a/UI/Qt/CMakeLists.txt+++ b/UI/Qt/CMakeLists.txt@@ -49,13 +49,14 @@ add_library(ladybird_impl STATICPopover.cppProcessManagerWindow.cppRemoteDownloads.cpp- RemoteSession.cppRemoteSuggestionProvider.cppRemoteView.cppReportReview.cppRestoreSessionCard.cppScreenshotSelectionOverlay.cppScreenshotViewer.cpp+ SessionHistorySnapshotStorage.cpp+ SessionStore.cppSelectDropdown.cppSiteSettingsPopover.cppStringUtils.cpp@@ -78,7 +79,7 @@ if (NOT APPLE AND NOT WIN32 AND NOT ANDROID)endif()target_link_libraries(ladybird_impl PUBLIC Qt::Core Qt::Gui Qt::Widgets)-target_link_libraries(ladybird_impl PRIVATE LibFileSystem LibUnicode)+target_link_libraries(ladybird_impl PRIVATE LibDatabase LibFileSystem LibUnicode)if (TARGET Qt6::Positioning)target_sources(ladybird_impl PRIVATE GeolocationProviderQt.cpp GeolocationProviderQt.h)diff --git a/UI/Qt/HubConnection.cpp b/UI/Qt/HubConnection.cppindex 3160d2d1d09..3591284ca5e 100644--- a/UI/Qt/HubConnection.cpp+++ b/UI/Qt/HubConnection.cpp@@ -272,9 +272,14 @@ void HubConnection::app_update_tabs_display()Application::the().update_tabs_display();}-void HubConnection::app_on_recently_closed_entries_changed()+void HubConnection::app_did_clear_history_since(UnixDateTime since){- Application::the().on_recently_closed_entries_changed();+ Application::the().did_clear_history_since(since);+}++void HubConnection::app_quit_for_signal()+{+ Application::the().quit_for_signal();}void HubConnection::app_did_enable_devtools()@@ -653,6 +658,12 @@ void HubConnection::view_request_context_menu(u64 view_id, WebView::ContextMenuRview->did_request_context_menu(request);}+void HubConnection::view_session_history_changed(u64 view_id, WebView::SessionHistorySnapshot history, URL::URL url)+{+ if (auto* view = RemoteView::find(view_id))+ view->did_change_session_history(move(history), move(url));+}+void HubConnection::view_did_make_link_to_highlight(u64 view_id, Optional<URL::URL> url){if (auto* view = RemoteView::find(view_id))diff --git a/UI/Qt/HubConnection.h b/UI/Qt/HubConnection.hindex 86747fe2b4e..5d6ad43d11b 100644--- a/UI/Qt/HubConnection.h+++ b/UI/Qt/HubConnection.h@@ -101,7 +101,8 @@ private:virtual void app_set_clipboard_text(String text, WebView::Application::ClipboardType type) override;virtual void app_insert_clipboard_item(Web::Clipboard::SystemClipboardItem item) override;virtual void app_update_tabs_display() override;- virtual void app_on_recently_closed_entries_changed() override;+ virtual void app_did_clear_history_since(UnixDateTime since) override;+ virtual void app_quit_for_signal() override;virtual void app_did_enable_devtools() override;virtual void app_did_disable_devtools() override;virtual void app_open_urls_in_new_tabs(Vector<URL::URL> urls) override;@@ -120,6 +121,7 @@ private: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_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/RemoteSession.cpp b/UI/Qt/RemoteSession.cppdeleted file mode 100644index 0c5e1276adb..00000000000--- a/UI/Qt/RemoteSession.cpp+++ /dev/null@@ -1,96 +0,0 @@-/*- * Copyright (c) 2026-present, the Ladybird developers.- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <UI/Qt/HubConnection.h>-#include <UI/Qt/RemoteSession.h>--#ifndef LADYBIRD_HUB_IN_OWN_PROCESS-# include <LibWebView/Application.h>-# include <LibWebView/BrowsingSession.h>-#endif--namespace Ladybird {--RemoteSession& RemoteSession::of(WebView::IsPrivate is_private)-{- static RemoteSession s_regular { WebView::IsPrivate::No };- static RemoteSession s_private { WebView::IsPrivate::Yes };- return is_private == WebView::IsPrivate::Yes ? s_private : s_regular;-}--#ifdef LADYBIRD_HUB_IN_OWN_PROCESS-static ErrorOr<void> error_unless(bool succeeded)-{- if (!succeeded)- return Error::from_string_literal("The session store could not do that");- return {};-}--template<typename Value>-static ErrorOr<Value> value_or_error(Optional<Value> value)-{- if (!value.has_value())- return Error::from_string_literal("The session store could not do that");- return value.release_value();-}--ErrorOr<WebView::SessionWindowId> RemoteSession::window_opened() { return value_or_error(HubConnection::the().session_window_opened(m_is_private)); }-ErrorOr<void> RemoteSession::window_closing(WebView::SessionStore::WindowClosing closing) { return error_unless(HubConnection::the().session_window_closing(m_is_private, move(closing))); }-void RemoteSession::window_activated(WebView::SessionWindowId id) { HubConnection::the().async_session_window_activated(m_is_private, id); }-void RemoteSession::window_geometry_changed(WebView::SessionWindowId id, WebView::SessionWindowGeometry geometry) { HubConnection::the().async_session_window_geometry_changed(m_is_private, id, geometry); }-ErrorOr<WebView::SessionTabId> RemoteSession::tab_opened(WebView::SessionStore::TabOpened opened)-{- // NB: A new tab has no URL yet, and that cannot go over IPC. The store treats it as about:blank anyway.- if (opened.initial_url.scheme().is_empty())- opened.initial_url = URL::about_blank();- return value_or_error(HubConnection::the().session_tab_opened(m_is_private, move(opened)));-}-ErrorOr<void> RemoteSession::tab_closed(WebView::SessionStore::TabClosed closed) { return error_unless(HubConnection::the().session_tab_closed(m_is_private, move(closed))); }-void RemoteSession::tab_detached(WebView::SessionTabId id) { HubConnection::the().async_session_tab_detached(m_is_private, id); }-void RemoteSession::tab_moved(WebView::SessionStore::TabMoved moved) { HubConnection::the().async_session_tab_moved(m_is_private, move(moved)); }-void RemoteSession::tab_order_changed(WebView::SessionStore::TabOrderChanged changed) { HubConnection::the().async_session_tab_order_changed(m_is_private, move(changed)); }-ErrorOr<void> RemoteSession::tab_pinned_changed(WebView::SessionTabId id, bool pinned) { return error_unless(HubConnection::the().session_tab_pinned_changed(m_is_private, id, pinned)); }-void RemoteSession::active_tab_changed(WebView::SessionTabId id) { HubConnection::the().async_session_active_tab_changed(m_is_private, id); }-void RemoteSession::application_quitting() { HubConnection::the().async_session_application_quitting(m_is_private); }-void RemoteSession::application_quit_aborted() { HubConnection::the().async_session_application_quit_aborted(m_is_private); }-u32 RemoteSession::consecutive_unclean_exits() const { return HubConnection::the().session_consecutive_unclean_exits(m_is_private); }-bool RemoteSession::has_closed_units() const { return HubConnection::the().session_has_closed_units(m_is_private); }-ErrorOr<Optional<WebView::ClosedSessionUnit>> RemoteSession::take_most_recently_closed() { return HubConnection::the().session_take_most_recently_closed(m_is_private); }-Vector<WebView::RecentlyClosedSessionUnit> RemoteSession::recently_closed_units(size_t limit) const { return HubConnection::the().session_recently_closed_units(m_is_private, limit); }-ErrorOr<Optional<WebView::ClosedSessionUnit>> RemoteSession::take_closed_unit(WebView::SessionWindowId id) { return HubConnection::the().session_take_closed_unit(m_is_private, id); }-Vector<WebView::RestoredSessionWindow> RemoteSession::take_launch_plan() { return HubConnection::the().session_take_launch_plan(m_is_private); }-Optional<WebView::SessionHistorySnapshot> RemoteSession::load_tab_history(WebView::SessionTabId id) { return HubConnection::the().session_load_tab_history(m_is_private, id); }-Optional<WebView::HistoryEntry> RemoteSession::entry_for_url(URL::URL const& url) const { return HubConnection::the().history_entry_for_url(m_is_private, url); }-#else-static WebView::SessionStore& store_of(WebView::IsPrivate is_private)-{- return *WebView::Application::session_for_new_view(is_private)->session_store;-}--ErrorOr<WebView::SessionWindowId> RemoteSession::window_opened() { return store_of(m_is_private).window_opened(); }-ErrorOr<void> RemoteSession::window_closing(WebView::SessionStore::WindowClosing closing) { return store_of(m_is_private).window_closing(move(closing)); }-void RemoteSession::window_activated(WebView::SessionWindowId id) { store_of(m_is_private).window_activated(id); }-void RemoteSession::window_geometry_changed(WebView::SessionWindowId id, WebView::SessionWindowGeometry geometry) { store_of(m_is_private).window_geometry_changed(id, geometry); }-ErrorOr<WebView::SessionTabId> RemoteSession::tab_opened(WebView::SessionStore::TabOpened opened) { return store_of(m_is_private).tab_opened(move(opened)); }-ErrorOr<void> RemoteSession::tab_closed(WebView::SessionStore::TabClosed closed) { return store_of(m_is_private).tab_closed(move(closed)); }-void RemoteSession::tab_detached(WebView::SessionTabId id) { store_of(m_is_private).tab_detached(id); }-void RemoteSession::tab_moved(WebView::SessionStore::TabMoved moved) { store_of(m_is_private).tab_moved(move(moved)); }-void RemoteSession::tab_order_changed(WebView::SessionStore::TabOrderChanged changed) { store_of(m_is_private).tab_order_changed(move(changed)); }-ErrorOr<void> RemoteSession::tab_pinned_changed(WebView::SessionTabId id, bool pinned) { return store_of(m_is_private).tab_pinned_changed(id, pinned); }-void RemoteSession::active_tab_changed(WebView::SessionTabId id) { store_of(m_is_private).active_tab_changed(id); }-void RemoteSession::application_quitting() { store_of(m_is_private).application_quitting(); }-void RemoteSession::application_quit_aborted() { store_of(m_is_private).application_quit_aborted(); }-u32 RemoteSession::consecutive_unclean_exits() const { return store_of(m_is_private).consecutive_unclean_exits(); }-bool RemoteSession::has_closed_units() const { return store_of(m_is_private).has_closed_units(); }-ErrorOr<Optional<WebView::ClosedSessionUnit>> RemoteSession::take_most_recently_closed() { return store_of(m_is_private).take_most_recently_closed(); }-Vector<WebView::RecentlyClosedSessionUnit> RemoteSession::recently_closed_units(size_t limit) const { return store_of(m_is_private).recently_closed_units(limit); }-ErrorOr<Optional<WebView::ClosedSessionUnit>> RemoteSession::take_closed_unit(WebView::SessionWindowId id) { return store_of(m_is_private).take_closed_unit(id); }-Vector<WebView::RestoredSessionWindow> RemoteSession::take_launch_plan() { return store_of(m_is_private).take_launch_plan(); }-Optional<WebView::SessionHistorySnapshot> RemoteSession::load_tab_history(WebView::SessionTabId id) { return store_of(m_is_private).load_tab_history(id); }-Optional<WebView::HistoryEntry> RemoteSession::entry_for_url(URL::URL const& url) const { return WebView::Application::session_for_new_view(m_is_private)->history_store->entry_for_url(url); }-#endif--}diff --git a/UI/Qt/RemoteSession.h b/UI/Qt/RemoteSession.hdeleted file mode 100644index 65a155a8fb3..00000000000--- a/UI/Qt/RemoteSession.h+++ /dev/null@@ -1,56 +0,0 @@-/*- * Copyright (c) 2026-present, the Ladybird developers.- *- * SPDX-License-Identifier: BSD-2-Clause- */--#pragma once--#include <LibWebView/BrowsingSession.h>-#include <LibWebView/Forward.h>-#include <LibWebView/HistoryStore.h>-#include <LibWebView/SessionStore.h>--namespace Ladybird {--// What the UI asks of the session of its windows, whose store lives in the Hub.-class RemoteSession {-public:- static RemoteSession& of(WebView::IsPrivate);-- WebView::IsPrivate is_private() const { return m_is_private; }-- ErrorOr<WebView::SessionWindowId> window_opened();- ErrorOr<void> window_closing(WebView::SessionStore::WindowClosing);- void window_activated(WebView::SessionWindowId);- void window_geometry_changed(WebView::SessionWindowId, WebView::SessionWindowGeometry);- ErrorOr<WebView::SessionTabId> tab_opened(WebView::SessionStore::TabOpened);- ErrorOr<void> tab_closed(WebView::SessionStore::TabClosed);- void tab_detached(WebView::SessionTabId);- void tab_moved(WebView::SessionStore::TabMoved);- void tab_order_changed(WebView::SessionStore::TabOrderChanged);- ErrorOr<void> tab_pinned_changed(WebView::SessionTabId, bool pinned);- void active_tab_changed(WebView::SessionTabId);- void application_quitting();- void application_quit_aborted();- u32 consecutive_unclean_exits() const;-- bool has_closed_units() const;- ErrorOr<Optional<WebView::ClosedSessionUnit>> take_most_recently_closed();- Vector<WebView::RecentlyClosedSessionUnit> recently_closed_units(size_t limit) const;- ErrorOr<Optional<WebView::ClosedSessionUnit>> take_closed_unit(WebView::SessionWindowId);- Vector<WebView::RestoredSessionWindow> take_launch_plan();- Optional<WebView::SessionHistorySnapshot> load_tab_history(WebView::SessionTabId);-- Optional<WebView::HistoryEntry> entry_for_url(URL::URL const&) const;--private:- explicit RemoteSession(WebView::IsPrivate is_private)- : m_is_private(is_private)- {- }-- WebView::IsPrivate m_is_private { WebView::IsPrivate::No };-};--}diff --git a/UI/Qt/RemoteView.cpp b/UI/Qt/RemoteView.cppindex 847c5d5945e..25d270718a5 100644--- a/UI/Qt/RemoteView.cpp+++ b/UI/Qt/RemoteView.cpp@@ -395,6 +395,20 @@ RemoteView* RemoteView::find(u64 view_id)return s_views.get(view_id).value_or(nullptr);}+void RemoteView::for_each(Function<void(RemoteView&)> const& callback)+{+ for (auto& [view_id, view] : s_views)+ callback(*view);+}++void RemoteView::did_change_session_history(WebView::SessionHistorySnapshot history, URL::URL url)+{+ // NB: A report the Hub sent before we stopped asking for them may still arrive.+ if (!m_session_tab_id.has_value())+ return;+ Application::session_store(m_is_private).update_tab_state({ .tab_id = *m_session_tab_id, .history = move(history), .url = move(url) });+}+// 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.hindex 1dbf34a95a2..bcbbc50e7f2 100644--- a/UI/Qt/RemoteView.h+++ b/UI/Qt/RemoteView.h@@ -13,6 +13,7 @@#include <LibWebView/WebCompatReport.h>#include <UI/Qt/BookmarkStore.h>#include <UI/Qt/HubConnection.h>+#include <UI/Qt/SessionStore.h>namespace Ladybird {@@ -31,6 +32,7 @@ public:virtual ~RemoteView();static RemoteView* find(u64 view_id);+ static void for_each(Function<void(RemoteView&)> const&);void did_request_context_menu(WebView::ContextMenuRequest const&);void did_make_link_to_highlight(Optional<URL::URL>);@@ -107,17 +109,18 @@ public:};void download_url(URL::URL const& url, PromptForPath prompt_for_path, Optional<String> const& image_mime_type = {}) { HubConnection::the().async_view_download_url(view_id(), url, prompt_for_path == PromptForPath::Yes, image_mime_type); }Vector<WebView::HistoryEntry> recent_history_entries(size_t limit) const;- Optional<WebView::SessionTabId> session_tab_id() const { return m_session_tab_id; }- void set_session_tab_id(WebView::SessionTabId session_tab_id)+ Optional<SessionTabId> session_tab_id() const { return m_session_tab_id; }+ void set_session_tab_id(SessionTabId session_tab_id){m_session_tab_id = session_tab_id;- HubConnection::the().async_view_set_session_tab_id(view_id(), session_tab_id);+ HubConnection::the().async_view_set_reports_session_history(view_id(), true);}void clear_session_tab_id(){m_session_tab_id = {};- HubConnection::the().async_view_set_session_tab_id(view_id(), {});+ HubConnection::the().async_view_set_reports_session_history(view_id(), false);}+ void did_change_session_history(WebView::SessionHistorySnapshot, URL::URL);void zoom_in() { HubConnection::the().async_view_zoom_in(view_id()); }void zoom_out() { HubConnection::the().async_view_zoom_out(view_id()); }void reset_zoom() { HubConnection::the().async_view_reset_zoom(view_id()); }@@ -268,7 +271,7 @@ private:WebView::IsPrivate m_is_private { WebView::IsPrivate::No };double m_device_pixel_ratio { 1.0 };Optional<u64> m_display_id;- Optional<WebView::SessionTabId> m_session_tab_id;+ Optional<SessionTabId> m_session_tab_id;bool m_scales_frames_to_fit { false };Hub::ViewState m_state;HashMap<u64, NavigationListener> m_navigation_listeners;diff --git a/Libraries/LibWebView/SessionHistorySnapshotStorage.cpp b/UI/Qt/SessionHistorySnapshotStorage.cppsimilarity index 98%rename from Libraries/LibWebView/SessionHistorySnapshotStorage.cpprename to UI/Qt/SessionHistorySnapshotStorage.cppindex b2047d171d9..431723f03c4 100644--- a/Libraries/LibWebView/SessionHistorySnapshotStorage.cpp+++ b/UI/Qt/SessionHistorySnapshotStorage.cpp@@ -13,9 +13,9 @@#include <LibWebCommon/ContentSecurityPolicy/SerializedPolicy.h>#include <LibWebCommon/HTML/DocumentStateClient.h>#include <LibWebCommon/HTML/SerializedPolicyContainer.h>-#include <LibWebView/SessionHistorySnapshotStorage.h>+#include <UI/Qt/SessionHistorySnapshotStorage.h>-namespace WebView {+namespace Ladybird {// Schema-stable tags for PersistedOrigin::kind. These values are persisted; never reorder or reuse them.enum class OriginKind : i64 {@@ -794,7 +794,7 @@ static ErrorOr<void> store_policy_container(Database::Database& database, Sessiostatic ErrorOr<void> validate_entries_storable(Vector<Web::HTML::SessionHistoryEntryDescriptor> const& entries, size_t depth, SnapshotRowTotals& totals){- if (depth > MAX_NESTED_HISTORY_DEPTH)+ if (depth > WebView::MAX_NESTED_HISTORY_DEPTH)return Error::from_string_literal("Session history nests deeper than the supported budget");for (auto const& entry : entries) {@@ -833,11 +833,11 @@ static ErrorOr<void> validate_entries_storable(Vector<Web::HTML::SessionHistoryEreturn {};}-ErrorOr<void> validate_session_history_snapshot_storable(SessionHistorySnapshot const& snapshot)+ErrorOr<void> validate_session_history_snapshot_storable(WebView::SessionHistorySnapshot const& snapshot){SnapshotRowTotals totals;TRY(validate_entries_storable(snapshot.entries, 0, totals));- return validate_snapshot_is_restorable(snapshot.entries, snapshot.used_steps, snapshot.current_used_step_index);+ return WebView::validate_snapshot_is_restorable(snapshot.entries, snapshot.used_steps, snapshot.current_used_step_index);}static ErrorOr<void> store_history_entries(Database::Database& database, SessionHistorySnapshotStatements const& statements, i64 tab_id, i64 history_id, Vector<Web::HTML::SessionHistoryEntryDescriptor> const& entries)@@ -925,7 +925,7 @@ static ErrorOr<void> store_history_entries(Database::Database& database, Sessionreturn {};}-ErrorOr<void> store_session_history_snapshot(Database::Database& database, SessionHistorySnapshotStatements const& statements, i64 tab_id, SessionHistorySnapshot const& snapshot)+ErrorOr<void> store_session_history_snapshot(Database::Database& database, SessionHistorySnapshotStatements const& statements, i64 tab_id, WebView::SessionHistorySnapshot const& snapshot){TRY(validate_session_history_snapshot_storable(snapshot));@@ -1338,7 +1338,7 @@ struct HistoryTreeLoadState {static ErrorOr<Vector<Web::HTML::SessionHistoryEntryDescriptor>> load_history_entry_tree(HistoryTreeLoadState& state, i64 history_id, size_t depth){- if (depth > MAX_NESTED_HISTORY_DEPTH)+ if (depth > WebView::MAX_NESTED_HISTORY_DEPTH)return Error::from_string_literal("Session history nests deeper than the supported budget");if (!state.unvisited_histories.remove(history_id))return Error::from_string_literal("Session history has an unreachable nested history");@@ -1378,7 +1378,7 @@ static ErrorOr<Vector<Web::HTML::SessionHistoryEntryDescriptor>> load_history_enreturn entries;}-ErrorOr<SessionHistorySnapshot> load_session_history_snapshot(Database::Database& database, SessionHistorySnapshotStatements const& statements, i64 tab_id, size_t current_used_step_index)+ErrorOr<WebView::SessionHistorySnapshot> load_session_history_snapshot(Database::Database& database, SessionHistorySnapshotStatements const& statements, i64 tab_id, size_t current_used_step_index){SnapshotRowTotals totals;auto used_step_rows = TRY(database.try_collect_bound_statement<UsedStepRow>(@@ -1499,7 +1499,7 @@ ErrorOr<SessionHistorySnapshot> load_session_history_snapshot(Database::Databasefor (auto history_id : history_ids)state.unvisited_histories.set(history_id);- SessionHistorySnapshot snapshot;+ WebView::SessionHistorySnapshot snapshot;if (!history_ids.is_empty()) {Optional<i64> root_history_id;for (auto history_id : history_ids) {@@ -1522,7 +1522,7 @@ ErrorOr<SessionHistorySnapshot> load_session_history_snapshot(Database::Databaseif (current_used_step_index >= snapshot.used_steps.size())return Error::from_string_literal("Session history current step index is out of range");- TRY(validate_snapshot_is_restorable(snapshot.entries, snapshot.used_steps, snapshot.current_used_step_index));+ TRY(WebView::validate_snapshot_is_restorable(snapshot.entries, snapshot.used_steps, snapshot.current_used_step_index));return snapshot;}diff --git a/Libraries/LibWebView/SessionHistorySnapshotStorage.h b/UI/Qt/SessionHistorySnapshotStorage.hsimilarity index 51%rename from Libraries/LibWebView/SessionHistorySnapshotStorage.hrename to UI/Qt/SessionHistorySnapshotStorage.hindex 7a8743bbc4a..2cf78abc39a 100644--- a/Libraries/LibWebView/SessionHistorySnapshotStorage.h+++ b/UI/Qt/SessionHistorySnapshotStorage.h@@ -20,10 +20,9 @@#include <LibWebCommon/HTML/SessionHistoryEntryDescriptor.h>#include <LibWebCommon/ReferrerPolicy/ReferrerPolicy.h>#include <LibWebCommon/UpgradeInsecureRequests/InsecureRequestsPolicy.h>-#include <LibWebView/Export.h>#include <LibWebView/SessionHistory.h>-namespace WebView {+namespace Ladybird {// Column form of an Optional<URL::Origin>, richer than the lossy Origin::serialize() (which drops the// tuple domain and renders opaque origins as "null").@@ -36,19 +35,19 @@ struct PersistedOrigin {Optional<String> domain {};};-WEBVIEW_API PersistedOrigin encode_origin(Optional<URL::Origin> const&);-WEBVIEW_API ErrorOr<Optional<URL::Origin>> decode_origin(PersistedOrigin const&);+PersistedOrigin encode_origin(Optional<URL::Origin> const&);+ErrorOr<Optional<URL::Origin>> decode_origin(PersistedOrigin const&);struct PersistedReferrer {i64 kind { 0 };Optional<String> url {};};-WEBVIEW_API PersistedReferrer encode_referrer(Web::Fetch::Infrastructure::RequestReferrerType const&);-WEBVIEW_API ErrorOr<Web::Fetch::Infrastructure::RequestReferrerType> decode_referrer(PersistedReferrer const&);+PersistedReferrer encode_referrer(Web::Fetch::Infrastructure::RequestReferrerType const&);+ErrorOr<Web::Fetch::Infrastructure::RequestReferrerType> decode_referrer(PersistedReferrer const&);-WEBVIEW_API i64 encode_referrer_policy(Web::ReferrerPolicy::ReferrerPolicy);-WEBVIEW_API ErrorOr<Web::ReferrerPolicy::ReferrerPolicy> decode_referrer_policy(i64 tag);+i64 encode_referrer_policy(Web::ReferrerPolicy::ReferrerPolicy);+ErrorOr<Web::ReferrerPolicy::ReferrerPolicy> decode_referrer_policy(i64 tag);struct PersistedResource {i64 kind { 0 };@@ -56,23 +55,23 @@ struct PersistedResource {};// v1 does not persist POST bodies: a POST resource encodes as Empty, so decode never yields one.-WEBVIEW_API PersistedResource encode_resource(Web::HTML::DocumentResource const&);-WEBVIEW_API ErrorOr<Web::HTML::DocumentResource> decode_resource(PersistedResource const&);+PersistedResource encode_resource(Web::HTML::DocumentResource const&);+ErrorOr<Web::HTML::DocumentResource> decode_resource(PersistedResource const&);-WEBVIEW_API i64 encode_scroll_restoration_mode(Web::HTML::ScrollRestorationMode);-WEBVIEW_API ErrorOr<Web::HTML::ScrollRestorationMode> decode_scroll_restoration_mode(i64 tag);+i64 encode_scroll_restoration_mode(Web::HTML::ScrollRestorationMode);+ErrorOr<Web::HTML::ScrollRestorationMode> decode_scroll_restoration_mode(i64 tag);-WEBVIEW_API i64 encode_embedder_policy_value(Web::HTML::EmbedderPolicyValue);-WEBVIEW_API ErrorOr<Web::HTML::EmbedderPolicyValue> decode_embedder_policy_value(i64 tag);+i64 encode_embedder_policy_value(Web::HTML::EmbedderPolicyValue);+ErrorOr<Web::HTML::EmbedderPolicyValue> decode_embedder_policy_value(i64 tag);-WEBVIEW_API i64 encode_csp_disposition(Web::Bindings::SecurityPolicyViolationEventDisposition);-WEBVIEW_API ErrorOr<Web::Bindings::SecurityPolicyViolationEventDisposition> decode_csp_disposition(i64 tag);+i64 encode_csp_disposition(Web::Bindings::SecurityPolicyViolationEventDisposition);+ErrorOr<Web::Bindings::SecurityPolicyViolationEventDisposition> decode_csp_disposition(i64 tag);-WEBVIEW_API i64 encode_csp_source(Web::ContentSecurityPolicy::PolicySource);-WEBVIEW_API ErrorOr<Web::ContentSecurityPolicy::PolicySource> decode_csp_source(i64 tag);+i64 encode_csp_source(Web::ContentSecurityPolicy::PolicySource);+ErrorOr<Web::ContentSecurityPolicy::PolicySource> decode_csp_source(i64 tag);-WEBVIEW_API i64 encode_insecure_requests_policy(Web::UpgradeInsecureRequests::InsecureRequestsPolicy);-WEBVIEW_API ErrorOr<Web::UpgradeInsecureRequests::InsecureRequestsPolicy> decode_insecure_requests_policy(i64 tag);+i64 encode_insecure_requests_policy(Web::UpgradeInsecureRequests::InsecureRequestsPolicy);+ErrorOr<Web::UpgradeInsecureRequests::InsecureRequestsPolicy> decode_insecure_requests_policy(i64 tag);struct SessionHistorySnapshotStatements {Database::StatementID insert_history;@@ -97,13 +96,13 @@ struct SessionHistorySnapshotStatements {Database::StatementID delete_used_steps;};-WEBVIEW_API ErrorOr<SessionHistorySnapshotStatements> prepare_session_history_snapshot_statements(Database::Database&);+ErrorOr<SessionHistorySnapshotStatements> prepare_session_history_snapshot_statements(Database::Database&);-WEBVIEW_API ErrorOr<void> validate_session_history_snapshot_storable(SessionHistorySnapshot const&);+ErrorOr<void> validate_session_history_snapshot_storable(WebView::SessionHistorySnapshot const&);// Validates before writing; the caller owns the transaction.-WEBVIEW_API ErrorOr<void> store_session_history_snapshot(Database::Database&, SessionHistorySnapshotStatements const&, i64 tab_id, SessionHistorySnapshot const&);-WEBVIEW_API ErrorOr<SessionHistorySnapshot> load_session_history_snapshot(Database::Database&, SessionHistorySnapshotStatements const&, i64 tab_id, size_t current_used_step_index);-WEBVIEW_API ErrorOr<void> delete_session_history_snapshot(Database::Database&, SessionHistorySnapshotStatements const&, i64 tab_id);+ErrorOr<void> store_session_history_snapshot(Database::Database&, SessionHistorySnapshotStatements const&, i64 tab_id, WebView::SessionHistorySnapshot const&);+ErrorOr<WebView::SessionHistorySnapshot> load_session_history_snapshot(Database::Database&, SessionHistorySnapshotStatements const&, i64 tab_id, size_t current_used_step_index);+ErrorOr<void> delete_session_history_snapshot(Database::Database&, SessionHistorySnapshotStatements const&, i64 tab_id);}diff --git a/Libraries/LibWebView/SessionStore.cpp b/UI/Qt/SessionStore.cppsimilarity index 98%rename from Libraries/LibWebView/SessionStore.cpprename to UI/Qt/SessionStore.cppindex b36cf210549..6e7bf58dce8 100644--- a/Libraries/LibWebView/SessionStore.cpp+++ b/UI/Qt/SessionStore.cpp@@ -14,9 +14,9 @@#include <LibURL/Parser.h>#include <LibWebCommon/HTML/SessionHistoryEntryDescriptor.h>#include <LibWebView/HistoryDebug.h>-#include <LibWebView/SessionStore.h>+#include <UI/Qt/SessionStore.h>-namespace WebView {+namespace Ladybird {static constexpr u32 SESSIONS_SCHEMA_BASELINE_VERSION = 1u;static constexpr u32 SESSIONS_SCHEMA_USER_AGENT_INITIATED_VERSION = 2u;@@ -414,7 +414,7 @@ Optional<size_t> SessionStore::TransientStorage::tab_index(SessionTabId tab_id)return window->tabs.find_first_index(tab_id);}-void SessionStore::TransientStorage::set_tab_state(SessionTabId tab_id, Optional<SessionHistorySnapshot> history, URL::URL url, bool dirty)+void SessionStore::TransientStorage::set_tab_state(SessionTabId tab_id, Optional<WebView::SessionHistorySnapshot> history, URL::URL url, bool dirty){auto tab = m_tabs.find(tab_id);if (tab == m_tabs.end())@@ -640,7 +640,7 @@ static String persistable_active_url(URL::URL const& url)auto serialized = url.serialize();if (serialized.byte_count() <= MAX_ACTIVE_URL_BYTES)return serialized;- if (history_debug_enabled())+ if (WebView::history_debug_enabled())dbgln("[History] Active URL exceeds the persisted cap; storing about:blank");return URL::about_blank().serialize();}@@ -1174,7 +1174,7 @@ ErrorOr<SessionStore::IdAllocators> SessionStore::PersistedStorage::create_id_al};}-ErrorOr<SessionHistorySnapshot> SessionStore::PersistedStorage::load_tab_snapshot(SessionTabId tab_id, size_t current_used_step_index)+ErrorOr<WebView::SessionHistorySnapshot> SessionStore::PersistedStorage::load_tab_snapshot(SessionTabId tab_id, size_t current_used_step_index){return load_session_history_snapshot(database, statements.snapshot_statements, tab_id, current_used_step_index);}@@ -1347,7 +1347,7 @@ ErrorOr<Vector<ClosedSessionTab>> SessionStore::PersistedStorage::take_closed_unauto history = load_session_history_snapshot(database, statements.snapshot_statements, tab_row.tab_id, tab_row.current_used_step_index);tabs.append({.active_url = tab_row.active_url,- .history = history.is_error() ? Optional<SessionHistorySnapshot> {} : Optional<SessionHistorySnapshot> { history.release_value() },+ .history = history.is_error() ? Optional<WebView::SessionHistorySnapshot> {} : Optional<WebView::SessionHistorySnapshot> { history.release_value() },.pinned = tab_row.pinned,});}@@ -1364,13 +1364,13 @@ static UnixDateTime canonicalized_to_milliseconds(UnixDateTime time)return UnixDateTime::from_milliseconds_since_epoch(time.milliseconds_since_epoch());}-static bool is_storable(Optional<SessionHistorySnapshot> const& history)+static bool is_storable(Optional<WebView::SessionHistorySnapshot> const& history){if (!history.has_value())return false;auto result = validate_session_history_snapshot_storable(*history);- if (result.is_error() && history_debug_enabled())+ if (result.is_error() && WebView::history_debug_enabled())dbgln("[History] Session snapshot degrades to URL-only: {}", result.error());return !result.is_error();}@@ -1488,7 +1488,7 @@ static bool session_history_nested_history_descriptors_match(Vector<Web::HTML::Sreturn true;}-static bool snapshots_match(Optional<SessionHistorySnapshot> const& a, Optional<SessionHistorySnapshot> const& b)+static bool snapshots_match(Optional<WebView::SessionHistorySnapshot> const& a, Optional<WebView::SessionHistorySnapshot> const& b){if (a.has_value() != b.has_value())return false;@@ -1671,7 +1671,7 @@ ErrorOr<SessionWindowId> SessionStore::window_opened()TRY(m_persisted_storage->insert_open_window(window_id));// A window that opens after the last one closed means the closed one no longer counts as left open. The window// is already tracked by now, so a failed clear is logged rather than failing the open.- if (auto result = m_persisted_storage->clear_restore_at_launch(); result.is_error() && history_debug_enabled())+ if (auto result = m_persisted_storage->clear_restore_at_launch(); result.is_error() && WebView::history_debug_enabled())dbgln("[History] Failed to clear the restore-at-launch flag: {}", result.error());}for (auto& pending : m_pending_window_closes)@@ -1865,7 +1865,7 @@ void SessionStore::append_closed_tab_unit(PendingTabClose const& pending).active_url = pending.tab.url,.tab_id = pending.tab_id,.current_used_step_index = mirror_step_index,- .history = m_persisted_storage.has_value() ? Optional<SessionHistorySnapshot> {} : pending.tab.history,+ .history = m_persisted_storage.has_value() ? Optional<WebView::SessionHistorySnapshot> {} : pending.tab.history,.pinned = pending.tab.pinned,});m_transient_storage.append_closed_unit(move(unit));@@ -1893,7 +1893,7 @@ void SessionStore::append_closed_window_unit(PendingWindowClose const& pending).active_url = member.tab.url,.tab_id = member.tab_id,.current_used_step_index = mirror_step_index,- .history = m_persisted_storage.has_value() ? Optional<SessionHistorySnapshot> {} : member.tab.history,+ .history = m_persisted_storage.has_value() ? Optional<WebView::SessionHistorySnapshot> {} : member.tab.history,.pinned = member.tab.pinned,});}@@ -2024,7 +2024,7 @@ ErrorOr<void> SessionStore::tab_closed(TabClosed closed)auto close_sequence = m_close_sequence_allocator.allocate();if (close_sequence.is_error()) {auto result = discard_without_undo();- if (history_debug_enabled())+ if (WebView::history_debug_enabled())dbgln("[History] Tab closed without undo: {}", close_sequence.error());return result;}@@ -2034,7 +2034,7 @@ ErrorOr<void> SessionStore::tab_closed(TabClosed closed)auto unit_id = m_session_id_allocator.allocate();if (unit_id.is_error()) {auto result = discard_without_undo();- if (history_debug_enabled())+ if (WebView::history_debug_enabled())dbgln("[History] Tab closed without undo: {}", unit_id.error());return result;}@@ -2159,7 +2159,7 @@ ErrorOr<void> SessionStore::window_closing(WindowClosing closing)m_pending_window_closes.append(move(close));}m_transient_storage.remove_window(closing.window_id);- if (history_debug_enabled())+ if (WebView::history_debug_enabled())dbgln("[History] Window closed without undo: {}", close_sequence.error());return result;}@@ -2236,7 +2236,7 @@ Vector<RestoredSessionWindow> SessionStore::take_launch_plan()return move(m_launch_plan);}-Optional<SessionHistorySnapshot> SessionStore::load_tab_history(SessionTabId tab_id)+Optional<WebView::SessionHistorySnapshot> SessionStore::load_tab_history(SessionTabId tab_id){auto const* tab = m_transient_storage.find_tab(tab_id);if (!tab)@@ -2246,7 +2246,7 @@ Optional<SessionHistorySnapshot> SessionStore::load_tab_history(SessionTabId tabauto snapshot = m_persisted_storage->load_tab_snapshot(tab_id, tab->current_used_step_index);if (snapshot.is_error()) {- if (history_debug_enabled())+ if (WebView::history_debug_enabled())dbgln("[History] Failed to load tab {} history: {}", tab_id, snapshot.error());return {};}diff --git a/Libraries/LibWebView/SessionStore.h b/UI/Qt/SessionStore.hsimilarity index 96%rename from Libraries/LibWebView/SessionStore.hrename to UI/Qt/SessionStore.hindex fa7932bbf09..f3f3119607a 100644--- a/Libraries/LibWebView/SessionStore.h+++ b/UI/Qt/SessionStore.h@@ -16,11 +16,10 @@#include <LibCore/Timer.h>#include <LibDatabase/Database.h>#include <LibURL/URL.h>-#include <LibWebView/Export.h>#include <LibWebView/SessionHistory.h>-#include <LibWebView/SessionHistorySnapshotStorage.h>+#include <UI/Qt/SessionHistorySnapshotStorage.h>-namespace WebView {+namespace Ladybird {using SessionWindowId = i64;using SessionTabId = i64;@@ -39,7 +38,7 @@ struct SessionWindowGeometry {struct ClosedSessionTab {URL::URL active_url;- Optional<SessionHistorySnapshot> history;+ Optional<WebView::SessionHistorySnapshot> history;bool pinned { false };};@@ -96,7 +95,7 @@ struct RestoredSessionWindow {// Persists live windows and tabs plus a bounded recently-closed stack. State updates coalesce; lifecycle mutations// write through. At startup, recovery hands the windows the last run left open to the frontend, or to the closed stack,// as its launch policy says.-class WEBVIEW_API SessionStore {+class SessionStore {AK_MAKE_NONCOPYABLE(SessionStore);AK_MAKE_NONMOVABLE(SessionStore);@@ -117,7 +116,7 @@ public:struct TabStateUpdate {SessionTabId tab_id { 0 };- Optional<SessionHistorySnapshot> history;+ Optional<WebView::SessionHistorySnapshot> history;URL::URL url;};@@ -195,7 +194,7 @@ public:Vector<RestoredSessionWindow> take_launch_plan();// A tab's history: the store's own copy if it holds a newer one than the tab's rows, and otherwise the rows'.- Optional<SessionHistorySnapshot> load_tab_history(SessionTabId);+ Optional<WebView::SessionHistorySnapshot> load_tab_history(SessionTabId);void flush_dirty_state();@@ -273,7 +272,7 @@ private:size_t current_used_step_index { 0 };// The pending flush payload in persisted mode, dropped once flushed; the storage itself in// transient mode.- Optional<SessionHistorySnapshot> history;+ Optional<WebView::SessionHistorySnapshot> history;bool dirty { false };bool pinned { false };};@@ -291,7 +290,7 @@ private:i64 tab_id { 0 };size_t current_used_step_index { 0 };// Transient mode captures the snapshot at demotion; persisted mode loads it on reopen.- Optional<SessionHistorySnapshot> history;+ Optional<WebView::SessionHistorySnapshot> history;bool pinned { false };};@@ -321,7 +320,7 @@ private:URL::URL url;i64 current_used_step_index { 0 };SnapshotDisposition snapshot_disposition { SnapshotDisposition::Preserve };- SessionHistorySnapshot const* snapshot { nullptr };+ WebView::SessionHistorySnapshot const* snapshot { nullptr };bool pinned { false };};@@ -434,7 +433,7 @@ private:ErrorOr<void> write_lifecycle(bool clean_exit, u32 consecutive_unclean_exits);ErrorOr<IdAllocators> create_id_allocators();- ErrorOr<SessionHistorySnapshot> load_tab_snapshot(SessionTabId, size_t current_used_step_index);+ ErrorOr<WebView::SessionHistorySnapshot> load_tab_snapshot(SessionTabId, size_t current_used_step_index);ErrorOr<Vector<ClosedUnit>> load_closed_units();ErrorOr<Vector<ClosedSessionTab>> take_closed_unit(SessionWindowId);@@ -489,7 +488,7 @@ private:Optional<size_t> tab_index(SessionTabId) const;size_t window_count() const { return m_windows.size(); }- void set_tab_state(SessionTabId, Optional<SessionHistorySnapshot>, URL::URL, bool dirty);+ void set_tab_state(SessionTabId, Optional<WebView::SessionHistorySnapshot>, URL::URL, bool dirty);bool set_tab_pinned(SessionTabId, bool pinned);void mark_tab_flushed(SessionTabId, size_t current_used_step_index);void set_active_tab(SessionTabId);diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cppindex 6b6b1b76257..b0ec8ed55ac 100644--- a/UI/Qt/Tab.cpp+++ b/UI/Qt/Tab.cpp@@ -28,7 +28,6 @@#include <UI/Qt/Icon.h>#include <UI/Qt/JavaScriptDialog.h>#include <UI/Qt/LadybirdButton.h>-#include <UI/Qt/RemoteSession.h>#if defined(AK_OS_MACOS)# include <UI/Qt/MacWindow.h>#endif@@ -1014,7 +1013,7 @@ URL::URL Tab::url() constreturn view().url();}-Optional<WebView::SessionTabId> Tab::session_tab_id() const+Optional<SessionTabId> Tab::session_tab_id() const{// A loaded tab's view holds the ID it reports its state under.if (is_loaded())@@ -1022,7 +1021,7 @@ Optional<WebView::SessionTabId> Tab::session_tab_id() constreturn m_session_tab_id;}-void Tab::set_session_tab_id(WebView::SessionTabId session_tab_id)+void Tab::set_session_tab_id(SessionTabId session_tab_id){m_session_tab_id = session_tab_id;if (is_loaded())diff --git a/UI/Qt/Tab.h b/UI/Qt/Tab.hindex 41f1c45633a..799370eaff7 100644--- a/UI/Qt/Tab.h+++ b/UI/Qt/Tab.h@@ -17,12 +17,12 @@#include <LibWebCommon/Page/PageId.h>#include <LibWebCommon/Page/ScreenWakeLockState.h>#include <LibWebView/FileDownloader.h>-#include <LibWebView/SessionStore.h>#include <LibWebView/Settings.h>#include <LibWebView/TabPerformanceStats.h>#include <UI/Qt/FindInPageWidget.h>#include <UI/Qt/LocationEdit.h>#include <UI/Qt/PermissionPromptPopover.h>+#include <UI/Qt/SessionStore.h>#include <UI/Qt/WebContentView.h>#include <QBoxLayout>@@ -74,7 +74,7 @@ signals:// What a restored tab shows until it's selected: It has no view, and so no WebContent process, until then.struct DeferredTab {- WebView::SessionTabId session_tab_id { 0 };+ SessionTabId session_tab_id { 0 };URL::URL url;QString title;QIcon favicon;@@ -111,8 +111,8 @@ public:URL::URL url() const;- Optional<WebView::SessionTabId> session_tab_id() const;- void set_session_tab_id(WebView::SessionTabId);+ Optional<SessionTabId> session_tab_id() const;+ void set_session_tab_id(SessionTabId);void clear_session_tab_id();// A page that has never had a real size must be sized while hidden, so that it doesn't load into Qt's placeholder@@ -281,7 +281,7 @@ private:bool m_window_is_closing { false };bool m_is_pinned { false };- Optional<WebView::SessionTabId> m_session_tab_id;+ Optional<SessionTabId> m_session_tab_id;Optional<DeferredTab> m_deferred_tab;};diff --git a/UI/Qt/TabBar.cpp b/UI/Qt/TabBar.cppindex 4fd81a3724d..bda12052f28 100644--- a/UI/Qt/TabBar.cpp+++ b/UI/Qt/TabBar.cpp@@ -13,7 +13,6 @@#include <AK/kmalloc.h>#include <LibCore/EventLoop.h>#include <LibWebView/HistoryStore.h>-#include <LibWebView/SessionStore.h>#include <UI/Qt/AllTabsPopover.h>#include <UI/Qt/Application.h>#include <UI/Qt/ApplicationActions.h>@@ -22,7 +21,7 @@#include <UI/Qt/ChromeStyle.h>#include <UI/Qt/Icon.h>#include <UI/Qt/LadybirdButton.h>-#include <UI/Qt/RemoteSession.h>+#include <UI/Qt/SessionStore.h>#if defined(AK_OS_MACOS)# include <UI/Qt/MacWindow.h>#endif@@ -4656,7 +4655,7 @@ void TabWidget::update_all_tabs_entries()auto& session = browser_window->session();auto now = UnixDateTime::now();for (auto const& unit : session.recently_closed_units(RECENTLY_CLOSED_LIMIT)) {- auto entry = session.entry_for_url(unit.active_url);+ auto entry = browser_window->history_entry_for_url(unit.active_url);auto title = entry.has_value() && entry->title.has_value() && !entry->title->is_empty() ? qstring_from_ak_string(*entry->title) : qstring_from_ak_string(unit.active_url.serialize());if (unit.was_window)title = unit.tab_count == 1 ? QStringLiteral("Window with 1 tab") : qformatted("Window with {} tabs", unit.tab_count);diff --git a/UI/Qt/TabBar.h b/UI/Qt/TabBar.hindex 837dd6424b4..399b702308c 100644--- a/UI/Qt/TabBar.h+++ b/UI/Qt/TabBar.h@@ -442,7 +442,7 @@ private:QToolButton* m_all_tabs_button { nullptr };AllTabsPopover* m_all_tabs_popover { nullptr };bool m_all_tabs_entries_update_is_pending { false };- Vector<WebView::SessionWindowId> m_recently_closed_unit_ids;+ Vector<SessionWindowId> m_recently_closed_unit_ids;LadybirdButton* m_ladybird_button { nullptr };// The Ladybird button and the all-tabs button after it, which move together.QWidget* m_ladybird_buttons { nullptr };diff --git a/UI/Qt/main.cpp b/UI/Qt/main.cppindex d867aa4ae05..5792537ae23 100644--- a/UI/Qt/main.cpp+++ b/UI/Qt/main.cpp@@ -116,7 +116,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)if (auto* restored_window = app->restore_previous_session(configuration)) {// A whole restored session replaces the usual startup tab, so only the URLs the user passed open with it.// With only pinned tabs restored, the usual startup tabs open after them.- auto restored_everything = app->launch_restore_policy() == WebView::SessionLaunchPolicy::Everything;+ auto restored_everything = app->launch_restore_policy() == Ladybird::SessionLaunchPolicy::Everything;if (!restored_everything || !browser_options.raw_urls.is_empty())app->open_startup_tabs(*restored_window, browser_options.urls);app->offer_to_restore_unexpectedly_closed_tabs(*restored_window);