Truly independent web browser
LibWebView+Base: List the registered WebUI pages on about:about
Luke Wilde29d3ebb91fd2
diff --git a/Base/res/ladybird/about-pages/about.html b/Base/res/ladybird/about-pages/about.htmlindex c2dbe0d6f03..25305ba6484 100644--- a/Base/res/ladybird/about-pages/about.html+++ b/Base/res/ladybird/about-pages/about.html@@ -35,18 +35,45 @@a:hover {text-decoration: underline;}++ .page-title {+ margin-left: 8px;+ color: var(--secondary-text-color);+ }</style></head><body><h1>List of About URLs</h1>- <ul>- <li><a href="about:about">about:about</a></li>- <li><a href="about:bookmarks">about:bookmarks</a></li>- <li><a href="about:crashes">about:crashes</a></li>- <li><a href="about:licenses">about:licenses</a></li>- <li><a href="about:settings">about:settings</a></li>- <li><a href="about:support">about:support</a></li>- <li><a href="about:version">about:version</a></li>- </ul>+ <ul id="page-list"></ul>++ <script>+ const pageList = document.querySelector("#page-list");++ document.addEventListener("WebUIMessage", event => {+ if (event.detail.name !== "loadPages") return;++ const pages = event.detail.data.toSorted((a, b) => a.host.localeCompare(b.host));++ pageList.replaceChildren(+ ...pages.map(page => {+ const url = `about:${page.host}`;++ const link = document.createElement("a");+ link.href = url;+ link.textContent = url;++ const title = document.createElement("span");+ title.className = "page-title";+ title.textContent = page.title;++ const item = document.createElement("li");+ item.append(link, title);+ return item;+ })+ );+ });++ document.addEventListener("WebUILoaded", () => ladybird.sendMessage("loadPages"));+ </script></body></html>diff --git a/Libraries/LibWebView/CMakeLists.txt b/Libraries/LibWebView/CMakeLists.txtindex c90782e5457..6a86dcd562d 100644--- a/Libraries/LibWebView/CMakeLists.txt+++ b/Libraries/LibWebView/CMakeLists.txt@@ -97,6 +97,7 @@ set(SOURCESWebDriverBiDiNetwork.cppWebDriverBrowserConnection.cppWebUI.cpp+ WebUI/AboutUI.cppWebUI/ApplicationWebUI.cppWebUI/CrashReportsUI.cppWebUI/SupportUI.cppdiff --git a/Libraries/LibWebView/WebUI.cpp b/Libraries/LibWebView/WebUI.cppindex a17fa9228ea..1b736f93ed2 100644--- a/Libraries/LibWebView/WebUI.cpp+++ b/Libraries/LibWebView/WebUI.cpp@@ -10,6 +10,7 @@#include <LibWebView/WebContentClient.h>#include <LibWebView/WebContentPage.h>#include <LibWebView/WebUI.h>+#include <LibWebView/WebUI/AboutUI.h>#include <LibWebView/WebUI/ApplicationWebUI.h>#include <LibWebView/WebUI/CrashReportsUI.h>#include <LibWebView/WebUI/SettingsUI.h>@@ -18,7 +19,7 @@namespace WebView {static constexpr auto s_pages = to_array<WebUI::Page>({- { "about"sv, "About URLs"sv, WebUI::PageType::Static },+ { "about"sv, "About URLs"sv, WebUI::PageType::Dynamic },{ "crashes"sv, "Crash Reports"sv, WebUI::PageType::Dynamic },{ "licenses"sv, "Licenses"sv, WebUI::PageType::Static },{ "newtab"sv, "New Tab"sv, WebUI::PageType::Static },@@ -92,6 +93,8 @@ ErrorOr<RefPtr<WebUI>> WebUI::create(WebContentClient& client, Web::PageId page_if (page->type == PageType::Application)web_ui = TRY(create_web_ui<ApplicationWebUI>(client, page_id, move(host)));+ else if (page->host == "about"sv)+ web_ui = TRY(create_web_ui<AboutUI>(client, page_id, move(host)));else if (page->host == "crashes"sv)web_ui = TRY(create_web_ui<CrashReportsUI>(client, page_id, move(host)));else if (page->host.is_one_of("settings"sv, "welcome"sv))diff --git a/Libraries/LibWebView/WebUI/AboutUI.cpp b/Libraries/LibWebView/WebUI/AboutUI.cppnew file mode 100644index 00000000000..e3d55bbda33--- /dev/null+++ b/Libraries/LibWebView/WebUI/AboutUI.cpp@@ -0,0 +1,37 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#include <AK/JsonArray.h>+#include <AK/JsonObject.h>+#include <LibWebView/WebUI/AboutUI.h>++namespace WebView {++void AboutUI::register_interfaces()+{+ register_interface("loadPages"sv, [this](auto const&) {+ load_pages();+ });+}++void AboutUI::load_pages()+{+ auto pages = WebUI::pages();++ JsonArray page_list;+ page_list.ensure_capacity(pages.size());++ for (auto const& page : pages) {+ JsonObject entry;+ entry.set("host"sv, page.host);+ entry.set("title"sv, page.title);+ page_list.must_append(move(entry));+ }++ async_send_message("loadPages"sv, move(page_list));+}++}diff --git a/Libraries/LibWebView/WebUI/AboutUI.h b/Libraries/LibWebView/WebUI/AboutUI.hnew file mode 100644index 00000000000..b25a6a65b76--- /dev/null+++ b/Libraries/LibWebView/WebUI/AboutUI.h@@ -0,0 +1,23 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#pragma once++#include <LibWebView/WebUI.h>++namespace WebView {++// about:about, which lists every page in WebUI::pages().+class AboutUI final : public WebUI {+ WEB_UI(AboutUI);++private:+ virtual void register_interfaces() override;++ void load_pages();+};++}