Skip to content

Truly independent web browser

LibWebView+UI/Qt: Answer about:version in the UI

Andreas Kling0bfbd4d0ced3
diff --git a/Libraries/LibWebView/CMakeLists.txt b/Libraries/LibWebView/CMakeLists.txt
index 052798a5116..ed566d51a0e 100644
--- a/Libraries/LibWebView/CMakeLists.txt
+++ b/Libraries/LibWebView/CMakeLists.txt
@@ -96,7 +96,6 @@ set(SOURCES
WebUI/CrashReportsUI.cpp
WebUI/DownloadsUI.cpp
WebUI/SettingsUI.cpp
- WebUI/VersionUI.cpp
WebWorkerClient.cpp
WorkerAgentManager.cpp
)
diff --git a/Libraries/LibWebView/WebUI.cpp b/Libraries/LibWebView/WebUI.cpp
index 11fa4cb934e..a9c9fc819a8 100644
--- a/Libraries/LibWebView/WebUI.cpp
+++ b/Libraries/LibWebView/WebUI.cpp
@@ -14,7 +14,6 @@
#include <LibWebView/WebUI/CrashReportsUI.h>
#include <LibWebView/WebUI/DownloadsUI.h>
#include <LibWebView/WebUI/SettingsUI.h>
-#include <LibWebView/WebUI/VersionUI.h>
namespace WebView {
@@ -26,7 +25,6 @@ static constexpr auto s_pages = to_array<WebUI::Page>({
{ "newtab"sv, "New Tab"sv, WebUI::PageType::Static },
{ "settings"sv, "Settings"sv, WebUI::PageType::Dynamic },
{ "services"sv, "Services"sv, WebUI::PageType::Static },
- { "version"sv, "Version"sv, WebUI::PageType::Dynamic },
{ "welcome"sv, "Welcome"sv, WebUI::PageType::Dynamic },
});
@@ -101,8 +99,6 @@ ErrorOr<RefPtr<WebUI>> WebUI::create(WebContentClient& client, Web::PageId page_
web_ui = TRY(create_web_ui<DownloadsUI>(client, page_id, move(host)));
else if (page->host.is_one_of("settings"sv, "welcome"sv))
web_ui = TRY(create_web_ui<SettingsUI>(client, page_id, move(host)));
- else if (page->host == "version"sv)
- web_ui = TRY(create_web_ui<VersionUI>(client, page_id, move(host)));
VERIFY(web_ui);
web_ui->register_interfaces();
diff --git a/Libraries/LibWebView/WebUI/VersionUI.h b/Libraries/LibWebView/WebUI/VersionUI.h
deleted file mode 100644
index c89ed6b1ed0..00000000000
--- a/Libraries/LibWebView/WebUI/VersionUI.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (c) 2026, Tim Flynn <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <LibWebView/WebUI.h>
-
-namespace WebView {
-
-class VersionUI final : public WebUI {
- WEB_UI(VersionUI);
-
-private:
- virtual void register_interfaces() override;
-
- void load_version_info();
-};
-
-}
diff --git a/Tests/LibWebView/TestOmnibox.cpp b/Tests/LibWebView/TestOmnibox.cpp
index 111dcffe29e..e99ea3b599e 100644
--- a/Tests/LibWebView/TestOmnibox.cpp
+++ b/Tests/LibWebView/TestOmnibox.cpp
@@ -208,7 +208,6 @@ TEST_CASE(all_web_ui_pages_are_suggested)
"about:newtab"sv,
"about:settings"sv,
"about:services"sv,
- "about:version"sv,
"about:welcome"sv,
};
diff --git a/UI/Qt/Application.cpp b/UI/Qt/Application.cpp
index 80b3a660570..4b5b1c979ae 100644
--- a/UI/Qt/Application.cpp
+++ b/UI/Qt/Application.cpp
@@ -63,7 +63,9 @@
#include <UI/Qt/StringUtils.h>
#include <UI/Qt/Tab.h>
#include <UI/Qt/Theme.h>
+#include <UI/Qt/VersionPage.h>
#include <UI/Qt/WebContentView.h>
+#include <UI/Qt/WebUIPage.h>
#if defined(AK_OS_MACOS)
# include <UI/Qt/ApplicationIcon.h>
@@ -644,6 +646,7 @@ Application* Application::s_the = nullptr;
ErrorOr<NonnullOwnPtr<Application>> Application::create(Main::Arguments const& arguments)
{
auto application = adopt_own(*new Application);
+ application->m_command_line = MUST(String::join(' ', arguments.strings));
#ifdef LADYBIRD_HUB_IN_OWN_PROCESS
WebView::platform_init();
@@ -1023,9 +1026,14 @@ void Application::create_platform_actions()
if (auto* hub = HubConnection::the_if_connected())
hub->send_settings_changes(settings);
};
+ m_web_ui_pages = make<WebUIPages>();
m_bookmarks = make<Bookmarks>(*m_bookmark_store);
- if (auto* hub = HubConnection::the_if_connected())
- hub->async_add_web_ui_page("history"_string, "History"_string);
+ m_web_ui_pages->register_page("history"_string, "History"_string, [](u64 web_ui_id) -> NonnullOwnPtr<WebUIPage> {
+ return make<HistoryPage>(web_ui_id);
+ });
+ m_web_ui_pages->register_page("version"_string, "Version"_string, [](u64 web_ui_id) -> NonnullOwnPtr<WebUIPage> {
+ return make<VersionPage>(web_ui_id);
+ });
m_open_task_manager_action = WebView::Action::create("Open Task Manager"sv, WebView::ActionID::OpenTaskManager, [this]() {
show_process_manager();
@@ -1350,22 +1358,6 @@ void Application::remove_unreferenced_favicons(HashTable<String> referenced_hash
m_favicon_store->remove_unreferenced_favicons(referenced_hashes);
}
-void Application::history_page_opened(u64 web_ui_id)
-{
- m_history_pages.set(web_ui_id, make<HistoryPage>(web_ui_id));
-}
-
-void Application::history_page_received_message(u64 web_ui_id, String const& name, JsonValue const& data)
-{
- if (auto page = m_history_pages.get(web_ui_id); page.has_value())
- (*page)->received_message(name, data);
-}
-
-void Application::history_page_closed(u64 web_ui_id)
-{
- m_history_pages.remove(web_ui_id);
-}
-
SessionStore& Application::session_store(WebView::IsPrivate is_private)
{
if (is_private == WebView::IsPrivate::No)
diff --git a/UI/Qt/Application.h b/UI/Qt/Application.h
index 1e601f868e8..e6dd7839f4a 100644
--- a/UI/Qt/Application.h
+++ b/UI/Qt/Application.h
@@ -33,7 +33,7 @@ class QWidget;
namespace Ladybird {
-class HistoryPage;
+class WebUIPages;
class Bookmarks;
class ProcessManagerWindow;
@@ -105,9 +105,8 @@ public:
virtual WebView::Settings& autocomplete_settings() override { return *m_settings; }
virtual Function<void()> fetch_remote_suggestions(URL::URL const&, WebView::IsPrivate, Function<void(RemoteResponse)>) override;
- void history_page_opened(u64 web_ui_id);
- void history_page_received_message(u64 web_ui_id, String const& name, JsonValue const& data);
- void history_page_closed(u64 web_ui_id);
+ static WebUIPages& web_ui_pages() { return *s_the->m_web_ui_pages; }
+ String const& command_line() const { return m_command_line; }
virtual ~Application() override;
@@ -290,6 +289,8 @@ private:
static Application* s_the;
+ String m_command_line;
+
#ifdef LADYBIRD_HUB_IN_OWN_PROCESS
ErrorOr<void> connect_to_hub(Main::Arguments const&);
Hub::UIInfo current_ui_info() const;
@@ -321,9 +322,10 @@ private:
OwnPtr<WebView::HistoryStore> m_history_store;
OwnPtr<WebView::AutocompleteService> m_autocomplete_service;
bool m_should_remove_unreferenced_favicons { false };
- HashMap<u64, NonnullOwnPtr<HistoryPage>> m_history_pages;
Vector<int> m_session_signal_handlers;
OwnPtr<Bookmarks> m_bookmarks;
+ // NB: Declared after the stores and the bookmarks, so the pages that show them are gone first.
+ OwnPtr<WebUIPages> m_web_ui_pages;
OwnPtr<ApplicationActions> m_application_actions;
RefPtr<HubConnection> m_hub_connection;
OwnPtr<QApplication> m_application;
diff --git a/UI/Qt/Bookmarks.cpp b/UI/Qt/Bookmarks.cpp
index a9ab9babc00..d7cf529ae8f 100644
--- a/UI/Qt/Bookmarks.cpp
+++ b/UI/Qt/Bookmarks.cpp
@@ -32,8 +32,9 @@ Bookmarks::Bookmarks(BookmarkStore& store)
create_menus();
create_context_menus();
- if (auto* hub = HubConnection::the_if_connected())
- hub->async_add_web_ui_page("bookmarks"_string, "Bookmarks"_string);
+ Application::web_ui_pages().register_page("bookmarks"_string, "Bookmarks"_string, [](u64 web_ui_id) -> NonnullOwnPtr<WebUIPage> {
+ return make<BookmarksPage>(web_ui_id);
+ });
HashTable<String> favicon_hashes;
for (auto const& favicon_hash : m_store.favicon_hashes())
@@ -43,22 +44,6 @@ Bookmarks::Bookmarks(BookmarkStore& store)
Bookmarks::~Bookmarks() = default;
-void Bookmarks::page_opened(u64 web_ui_id)
-{
- m_pages.set(web_ui_id, make<BookmarksPage>(web_ui_id));
-}
-
-void Bookmarks::page_received_message(u64 web_ui_id, String const& name, JsonValue const& data)
-{
- if (auto* page = m_pages.get(web_ui_id).value_or(nullptr))
- page->received_message(name, data);
-}
-
-void Bookmarks::page_closed(u64 web_ui_id)
-{
- m_pages.remove(web_ui_id);
-}
-
void Bookmarks::bookmarks_changed()
{
read_missing_favicons();
diff --git a/UI/Qt/Bookmarks.h b/UI/Qt/Bookmarks.h
index b7a4043da67..4efd408fda7 100644
--- a/UI/Qt/Bookmarks.h
+++ b/UI/Qt/Bookmarks.h
@@ -19,8 +19,6 @@
namespace Ladybird {
-class BookmarksPage;
-
// Everything about bookmarks: they are a feature of this application, of which the Hub knows nothing.
class Bookmarks final
: public BookmarkStoreObserver
@@ -45,10 +43,6 @@ public:
void set_context_menu_item(Optional<String> item_id, Optional<String> target_folder_id, Optional<String> parent_folder_id);
void open_in_new_tab(String const& bookmark_id, Web::HTML::ActivateTab);
- void page_opened(u64 web_ui_id);
- void page_received_message(u64 web_ui_id, String const& name, JsonValue const& data);
- void page_closed(u64 web_ui_id);
-
private:
virtual void bookmarks_changed() override;
@@ -98,8 +92,6 @@ private:
// A favicon's hash is of its content, so what was read for a hash stays true.
HashMap<String, Optional<ByteBuffer>> m_favicons;
Vector<WebView::AutocompleteBookmark> m_autocomplete_bookmarks;
-
- HashMap<u64, NonnullOwnPtr<BookmarksPage>> m_pages;
};
}
diff --git a/UI/Qt/BookmarksPage.cpp b/UI/Qt/BookmarksPage.cpp
index dfdc06b2dd3..78dd09a1dc3 100644
--- a/UI/Qt/BookmarksPage.cpp
+++ b/UI/Qt/BookmarksPage.cpp
@@ -11,7 +11,6 @@
#include <UI/Qt/BookmarkStore.h>
#include <UI/Qt/Bookmarks.h>
#include <UI/Qt/BookmarksPage.h>
-#include <UI/Qt/HubConnection.h>
#include <UI/Qt/StringUtils.h>
#include <QFileDialog>
@@ -21,8 +20,8 @@
namespace Ladybird {
BookmarksPage::BookmarksPage(u64 web_ui_id)
- : BookmarkStoreObserver(Application::bookmark_store())
- , m_web_ui_id(web_ui_id)
+ : WebUIPage(web_ui_id)
+ , BookmarkStoreObserver(Application::bookmark_store())
{
}
@@ -54,7 +53,7 @@ void BookmarksPage::load_bookmarks()
auto items = Application::bookmark_store().serialize_items([](String const& favicon_hash) {
return Application::bookmarks().favicon_png(favicon_hash);
});
- HubConnection::the().async_send_web_ui_message(m_web_ui_id, "loadBookmarks"_string, move(items));
+ send_message("loadBookmarks"_string, move(items));
}
void BookmarksPage::move_item(JsonValue const& data)
diff --git a/UI/Qt/BookmarksPage.h b/UI/Qt/BookmarksPage.h
index ebd909a0cfd..64e9a398be8 100644
--- a/UI/Qt/BookmarksPage.h
+++ b/UI/Qt/BookmarksPage.h
@@ -6,20 +6,18 @@
#pragma once
-#include <AK/JsonValue.h>
-#include <AK/String.h>
#include <UI/Qt/BookmarkStore.h>
+#include <UI/Qt/WebUIPage.h>
namespace Ladybird {
-// One open about:bookmarks. The page reaches this through the Hub, which does not know what the page is about.
-class BookmarksPage final : public BookmarkStoreObserver {
+class BookmarksPage final
+ : public WebUIPage
+ , public BookmarkStoreObserver {
public:
- AK_ALLOC_WITH_KMALLOC;
-
explicit BookmarksPage(u64 web_ui_id);
- void received_message(String const& name, JsonValue const& data);
+ virtual void received_message(String const& name, JsonValue const& data) override;
private:
virtual void bookmarks_changed() override;
@@ -30,8 +28,6 @@ private:
void import_bookmarks(JsonValue const&);
void export_bookmarks(JsonValue const&);
void show_context_menu(JsonValue const&);
-
- u64 m_web_ui_id { 0 };
};
}
diff --git a/UI/Qt/CMakeLists.txt b/UI/Qt/CMakeLists.txt
index 737281c8032..8e4de2d2208 100644
--- a/UI/Qt/CMakeLists.txt
+++ b/UI/Qt/CMakeLists.txt
@@ -65,8 +65,10 @@ add_library(ladybird_impl STATIC
Tab.cpp
TabBar.cpp
Theme.cpp
+ VersionPage.cpp
WebCompatReportReview.cpp
WebContentView.cpp
+ WebUIPage.cpp
WindowCloseCoordinator.cpp
WindowControlButton.cpp
WindowControlsReveal.cpp
diff --git a/UI/Qt/HistoryPage.cpp b/UI/Qt/HistoryPage.cpp
index ad0bc82778d..b0ce8f80ecb 100644
--- a/UI/Qt/HistoryPage.cpp
+++ b/UI/Qt/HistoryPage.cpp
@@ -11,7 +11,6 @@
#include <LibWebView/HistoryStore.h>
#include <UI/Qt/Application.h>
#include <UI/Qt/HistoryPage.h>
-#include <UI/Qt/HubConnection.h>
#include <algorithm>
@@ -54,7 +53,7 @@ static JsonObject serialize_history_entry(WebView::HistoryEntry const& entry)
}
HistoryPage::HistoryPage(u64 web_ui_id)
- : m_web_ui_id(web_ui_id)
+ : WebUIPage(web_ui_id)
{
}
@@ -102,7 +101,7 @@ void HistoryPage::load_history_entries(JsonValue const& data)
result.set("hasMore"sv, has_more);
result.set("entries"sv, move(serialized_entries));
- HubConnection::the().async_send_web_ui_message(m_web_ui_id, "loadHistoryEntries"_string, move(result));
+ send_message("loadHistoryEntries"_string, move(result));
}
void HistoryPage::remove_history_entry(JsonValue const& data)
diff --git a/UI/Qt/HistoryPage.h b/UI/Qt/HistoryPage.h
index c8ef24b2afa..ce278554d30 100644
--- a/UI/Qt/HistoryPage.h
+++ b/UI/Qt/HistoryPage.h
@@ -6,26 +6,20 @@
#pragma once
-#include <AK/JsonValue.h>
-#include <AK/String.h>
+#include <UI/Qt/WebUIPage.h>
namespace Ladybird {
-// One open about:history. The page reaches this through the Hub, which does not know what the page is about.
-class HistoryPage {
+class HistoryPage final : public WebUIPage {
public:
- AK_ALLOC_WITH_KMALLOC;
-
explicit HistoryPage(u64 web_ui_id);
- void received_message(String const& name, JsonValue const& data);
+ virtual void received_message(String const& name, JsonValue const& data) override;
private:
void load_history_entries(JsonValue const&);
void remove_history_entry(JsonValue const&);
void forget_history_site(JsonValue const&);
-
- u64 m_web_ui_id { 0 };
};
}
diff --git a/UI/Qt/HubConnection.cpp b/UI/Qt/HubConnection.cpp
index cfacf4be543..f170f6201cc 100644
--- a/UI/Qt/HubConnection.cpp
+++ b/UI/Qt/HubConnection.cpp
@@ -10,11 +10,11 @@
#include <UI/Qt/Application.h>
#include <UI/Qt/ApplicationActions.h>
#include <UI/Qt/Bookmarks.h>
-#include <UI/Qt/BookmarksPage.h>
#include <UI/Qt/HubConnection.h>
#include <UI/Qt/RemoteDownloads.h>
#include <UI/Qt/RemoteView.h>
#include <UI/Qt/Tab.h>
+#include <UI/Qt/WebUIPage.h>
namespace Ladybird {
@@ -592,22 +592,17 @@ void HubConnection::app_open_new_window(Vector<URL::URL> urls)
void HubConnection::web_ui_opened(u64 web_ui_id, String host)
{
- if (host == "bookmarks"sv)
- Application::bookmarks().page_opened(web_ui_id);
- else if (host == "history"sv)
- Application::the().history_page_opened(web_ui_id);
+ Application::web_ui_pages().page_opened(web_ui_id, host);
}
void HubConnection::web_ui_message(u64 web_ui_id, String name, JsonValue data)
{
- Application::bookmarks().page_received_message(web_ui_id, name, data);
- Application::the().history_page_received_message(web_ui_id, name, data);
+ Application::web_ui_pages().page_received_message(web_ui_id, name, data);
}
void HubConnection::web_ui_closed(u64 web_ui_id)
{
- Application::bookmarks().page_closed(web_ui_id);
- Application::the().history_page_closed(web_ui_id);
+ Application::web_ui_pages().page_closed(web_ui_id);
}
void HubConnection::set_settings_from_hub(JsonValue const& settings)
diff --git a/Libraries/LibWebView/WebUI/VersionUI.cpp b/UI/Qt/VersionPage.cpp
similarity index 80%
rename from Libraries/LibWebView/WebUI/VersionUI.cpp
rename to UI/Qt/VersionPage.cpp
index 156c7bc284d..1760b34c493 100644
--- a/Libraries/LibWebView/WebUI/VersionUI.cpp
+++ b/UI/Qt/VersionPage.cpp
@@ -10,29 +10,28 @@
#include <LibCore/BrowserVersion.h>
#include <LibCore/System.h>
#include <LibWebCommon/Loader/UserAgent.h>
-#include <LibWebView/Application.h>
#include <LibWebView/BuildInformation.h>
-#include <LibWebView/WebUI/VersionUI.h>
+#include <UI/Qt/Application.h>
+#include <UI/Qt/VersionPage.h>
-namespace WebView {
+namespace Ladybird {
-void VersionUI::register_interfaces()
+void VersionPage::received_message(String const& name, JsonValue const&)
{
- register_interface("loadVersionInfo"sv, [this](auto const&) {
+ if (name == "loadVersionInfo"sv)
load_version_info();
- });
}
-void VersionUI::load_version_info()
+void VersionPage::load_version_info()
{
static NeverDestroyed<String> browser_name = String::from_utf8_without_validation({ BROWSER_NAME, __builtin_strlen(BROWSER_NAME) });
static NeverDestroyed<String> browser_version = String::from_utf8_without_validation({ BROWSER_VERSION, __builtin_strlen(BROWSER_VERSION) });
static NeverDestroyed<String> release_stage = String::from_utf8_without_validation({ BROWSER_RELEASE_STAGE, __builtin_strlen(BROWSER_RELEASE_STAGE) });
static NeverDestroyed<String> product_name = String::from_utf8_without_validation({ BROWSER_PRODUCT_NAME, __builtin_strlen(BROWSER_PRODUCT_NAME) });
- static NeverDestroyed<String> browser_commit = String::from_utf8_without_validation(LADYBIRD_COMMIT.bytes());
+ static NeverDestroyed<String> browser_commit = String::from_utf8_without_validation(WebView::LADYBIRD_COMMIT.bytes());
static NeverDestroyed<String> arch = String::from_utf8_without_validation({ CPU_STRING, __builtin_strlen(CPU_STRING) });
static NeverDestroyed<String> platform_name = String::from_utf8_without_validation({ OS_STRING, __builtin_strlen(OS_STRING) });
- static NeverDestroyed<String> command_line = MUST(String::join(' ', Application::the().command_line_arguments().strings));
+ static NeverDestroyed<String> command_line = Application::the().command_line();
static NeverDestroyed<String> executable_path = MUST(String::from_byte_string(MUST(Core::System::current_executable_path())));
JsonObject version_info;
@@ -46,7 +45,7 @@ void VersionUI::load_version_info()
version_info.set("commandLine"_string, *command_line);
version_info.set("executablePath"_string, *executable_path);
- async_send_message("renderVersionInfo"sv, version_info);
+ send_message("renderVersionInfo"_string, move(version_info));
}
}
diff --git a/UI/Qt/VersionPage.h b/UI/Qt/VersionPage.h
new file mode 100644
index 00000000000..9d23bc09ff0
--- /dev/null
+++ b/UI/Qt/VersionPage.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2026, Tim Flynn <[email protected]>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <UI/Qt/WebUIPage.h>
+
+namespace Ladybird {
+
+class VersionPage final : public WebUIPage {
+public:
+ explicit VersionPage(u64 web_ui_id)
+ : WebUIPage(web_ui_id)
+ {
+ }
+
+ virtual void received_message(String const& name, JsonValue const& data) override;
+
+private:
+ void load_version_info();
+};
+
+}
diff --git a/UI/Qt/WebUIPage.cpp b/UI/Qt/WebUIPage.cpp
new file mode 100644
index 00000000000..817e195533c
--- /dev/null
+++ b/UI/Qt/WebUIPage.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibWebView/WebUI.h>
+#include <UI/Qt/HubConnection.h>
+#include <UI/Qt/WebUIPage.h>
+
+namespace Ladybird {
+
+void WebUIPage::send_message(String name, JsonValue data) const
+{
+ if (auto* hub = HubConnection::the_if_connected())
+ hub->async_send_web_ui_message(m_web_ui_id, move(name), move(data));
+}
+
+void WebUIPages::register_page(String host, String title, Factory factory)
+{
+ // NB: The omnibox of this process suggests the pages too.
+ WebView::WebUI::add_application_page(host, title);
+ if (auto* hub = HubConnection::the_if_connected())
+ hub->async_add_web_ui_page(host, move(title));
+ m_factories.set(move(host), move(factory));
+}
+
+void WebUIPages::page_opened(u64 web_ui_id, String const& host)
+{
+ if (auto factory = m_factories.get(host); factory.has_value())
+ m_pages.set(web_ui_id, (*factory)(web_ui_id));
+}
+
+void WebUIPages::page_received_message(u64 web_ui_id, String const& name, JsonValue const& data)
+{
+ if (auto* page = m_pages.get(web_ui_id).value_or(nullptr))
+ page->received_message(name, data);
+}
+
+void WebUIPages::page_closed(u64 web_ui_id)
+{
+ m_pages.remove(web_ui_id);
+}
+
+}
diff --git a/UI/Qt/WebUIPage.h b/UI/Qt/WebUIPage.h
new file mode 100644
index 00000000000..46775ecb8cb
--- /dev/null
+++ b/UI/Qt/WebUIPage.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Function.h>
+#include <AK/HashMap.h>
+#include <AK/JsonValue.h>
+#include <AK/NonnullOwnPtr.h>
+#include <AK/String.h>
+
+namespace Ladybird {
+
+// One open page of the browser's own, such as about:history. The page reaches this through the Hub, which does not
+// know what the page is about.
+class WebUIPage {
+public:
+ AK_ALLOC_WITH_KMALLOC;
+
+ virtual ~WebUIPage() = default;
+
+ virtual void received_message(String const& name, JsonValue const& data) = 0;
+
+protected:
+ explicit WebUIPage(u64 web_ui_id)
+ : m_web_ui_id(web_ui_id)
+ {
+ }
+
+ u64 web_ui_id() const { return m_web_ui_id; }
+ void send_message(String name, JsonValue data) const;
+
+private:
+ u64 m_web_ui_id { 0 };
+};
+
+// The pages of the browser's own that the UI answers, and the ones of them that are open.
+class WebUIPages {
+public:
+ AK_ALLOC_WITH_KMALLOC;
+
+ using Factory = Function<NonnullOwnPtr<WebUIPage>(u64 web_ui_id)>;
+
+ // Makes about:<host> a page of the UI, which opens with a page made by the factory.
+ void register_page(String host, String title, Factory);
+
+ void page_opened(u64 web_ui_id, String const& host);
+ void page_received_message(u64 web_ui_id, String const& name, JsonValue const& data);
+ void page_closed(u64 web_ui_id);
+
+private:
+ HashMap<String, Factory> m_factories;
+ HashMap<u64, NonnullOwnPtr<WebUIPage>> m_pages;
+};
+
+}