Skip to content

Truly independent web browser

Hub+LibWebView+UI/Qt: Show both the UI and the Hub in the Task Manager

Andreas Klinga3f0c115edc9
diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cpp
index a0b3337fdb0..6b782e6bc19 100644
--- a/Libraries/LibWebView/Application.cpp
+++ b/Libraries/LibWebView/Application.cpp
@@ -2422,7 +2422,9 @@ void Application::process_did_exit(Process&& process, Optional<int>)
}
break;
case ProcessType::Browser:
- dbgln("Invalid process type to be dying: Browser");
+ case ProcessType::UI:
+ case ProcessType::Hub:
+ dbgln("Invalid process type to be dying: {}", process_name_from_type(process.type()));
VERIFY_NOT_REACHED();
}
diff --git a/Libraries/LibWebView/ProcessManager.cpp b/Libraries/LibWebView/ProcessManager.cpp
index 7d134094eb9..1ad21f2b0db 100644
--- a/Libraries/LibWebView/ProcessManager.cpp
+++ b/Libraries/LibWebView/ProcessManager.cpp
@@ -17,6 +17,10 @@ ProcessType process_type_from_name(StringView name)
{
if (name == "Browser"sv)
return ProcessType::Browser;
+ if (name == "UI"sv)
+ return ProcessType::UI;
+ if (name == "Hub"sv)
+ return ProcessType::Hub;
if (name == "Compositor"sv)
return ProcessType::Compositor;
if (name == "WebContent"sv)
@@ -43,6 +47,10 @@ StringView process_name_from_type(ProcessType type)
switch (type) {
case ProcessType::Browser:
return "Browser"sv;
+ case ProcessType::UI:
+ return "UI"sv;
+ case ProcessType::Hub:
+ return "Hub"sv;
case ProcessType::Compositor:
return "Compositor"sv;
case ProcessType::WebContent:
diff --git a/Libraries/LibWebView/ProcessType.h b/Libraries/LibWebView/ProcessType.h
index 376c07eb9bf..f9f2d31b29d 100644
--- a/Libraries/LibWebView/ProcessType.h
+++ b/Libraries/LibWebView/ProcessType.h
@@ -11,7 +11,10 @@
namespace WebView {
enum class ProcessType : u8 {
+ // The UI and the Hub in one process, or the Hub with no UI.
Browser,
+ UI,
+ Hub,
Compositor,
WebContent,
RequestServer,
diff --git a/Meta/Generators/generate-build-information.py b/Meta/Generators/generate-build-information.py
index b8453cb0099..26662d4af6a 100755
--- a/Meta/Generators/generate-build-information.py
+++ b/Meta/Generators/generate-build-information.py
@@ -124,6 +124,8 @@ inline void append_build_information_for_process(StringBuilder& builder, Process
switch (type) {{
case ProcessType::Browser:
+ case ProcessType::UI:
+ case ProcessType::Hub:
break;
"""
diff --git a/Services/Hub/ConnectionFromUI.cpp b/Services/Hub/ConnectionFromUI.cpp
index 54c79d14726..7a5cf4e0af8 100644
--- a/Services/Hub/ConnectionFromUI.cpp
+++ b/Services/Hub/ConnectionFromUI.cpp
@@ -611,7 +611,12 @@ void ConnectionFromUI::ui_info_changed(Hub::UIInfo info)
Messages::HubServer::ProcessSnapshotsResponse ConnectionFromUI::process_snapshots()
{
- return WebView::process_snapshots(Application::process_manager());
+ auto snapshots = WebView::process_snapshots(Application::process_manager());
+ for (auto& snapshot : snapshots) {
+ if (snapshot.type == WebView::ProcessType::Browser)
+ snapshot.type = WebView::ProcessType::Hub;
+ }
+ return snapshots;
}
Messages::HubServer::TerminateProcessResponse ConnectionFromUI::terminate_process(u64 child_id)
diff --git a/UI/Qt/Application.cpp b/UI/Qt/Application.cpp
index 8c081072aeb..b534a8fb4af 100644
--- a/UI/Qt/Application.cpp
+++ b/UI/Qt/Application.cpp
@@ -750,6 +750,27 @@ ErrorOr<void> Application::connect_to_hub(Main::Arguments const& arguments)
return {};
}
+Vector<WebView::ProcessSnapshot> Application::process_snapshots()
+{
+ auto snapshots = HubConnection::the().process_snapshots();
+
+ // NB: The Hub knows the processes that it launched. Only this one can always tell how it is doing itself.
+ if (m_ui_process_statistics.processes.is_empty())
+ m_ui_process_statistics.processes.append(make<Core::Platform::ProcessInfo>(Core::System::getpid()));
+ if (auto result = Core::Platform::update_process_statistics(m_ui_process_statistics); result.is_error())
+ dbgln("Unable to update the UI's process statistics: {}", result.error());
+
+ auto const& statistics = *m_ui_process_statistics.processes.first();
+ WebView::ProcessSnapshot snapshot;
+ snapshot.child_id = NumericLimits<u64>::max();
+ snapshot.pid = statistics.pid;
+ snapshot.type = WebView::ProcessType::UI;
+ snapshot.cpu_percent = statistics.cpu_percent;
+ snapshot.memory_usage_bytes = statistics.memory_usage_bytes;
+ snapshots.append(move(snapshot));
+ return snapshots;
+}
+
bool Application::has_translator() const { return m_has_translator; }
Optional<int> Application::exit_status_if_done() const { return m_exit_status_if_done; }
@@ -817,7 +838,7 @@ void Application::show_process_manager()
if (!m_process_manager_window) {
m_process_manager_window = make<ProcessManagerWindow>(ProcessManagerWindow::Source {
#ifdef LADYBIRD_HUB_IN_OWN_PROCESS
- .take_snapshots = [] { return HubConnection::the().process_snapshots(); },
+ .take_snapshots = [this] { return process_snapshots(); },
.end_process = [](u64 child_id) { return HubConnection::the().terminate_process(child_id); },
#else
.take_snapshots = [] { return WebView::process_snapshots(WebView::Application::process_manager()); },
diff --git a/UI/Qt/Application.h b/UI/Qt/Application.h
index 819bc6bd378..bdcad0b3afc 100644
--- a/UI/Qt/Application.h
+++ b/UI/Qt/Application.h
@@ -11,11 +11,13 @@
#include <AK/Platform.h>
#include <Hub/Application.h>
#include <Hub/ConnectionFromUI.h>
+#include <LibCore/Platform/ProcessStatistics.h>
#include <LibURL/URL.h>
#include <LibWebCommon/Page/PageId.h>
#include <LibWebView/Application.h>
#include <LibWebView/BrowsingSession.h>
#include <LibWebView/CrashReportOutbox.h>
+#include <LibWebView/ProcessSnapshot.h>
#include <UI/Qt/BrowserWindow.h>
#include <UI/Qt/HubConnection.h>
@@ -259,6 +261,7 @@ private:
#ifdef LADYBIRD_HUB_IN_OWN_PROCESS
ErrorOr<void> connect_to_hub(Main::Arguments const&);
Hub::UIInfo current_ui_info() const;
+ Vector<WebView::ProcessSnapshot> process_snapshots();
// NB: QApplication holds on to these by reference, so they must live as long as it does.
Main::Arguments m_arguments_for_qt;
@@ -267,6 +270,7 @@ private:
WebView::BrowserOptions m_browser_options;
bool m_has_translator { false };
Optional<int> m_exit_status_if_done;
+ Core::Platform::ProcessStatistics m_ui_process_statistics;
#else
OwnPtr<Hub::Application> m_hub;
RefPtr<Hub::ConnectionFromUI> m_connection_from_ui;
diff --git a/UI/Qt/Icon.cpp b/UI/Qt/Icon.cpp
index d6a7dfaa064..6a681b74be7 100644
--- a/UI/Qt/Icon.cpp
+++ b/UI/Qt/Icon.cpp
@@ -302,6 +302,7 @@ static constexpr auto GLOBE_ICON_PATH = "M7.5 1.5a6 6 0 1 1 0 12a6 6 0 1 1 0-12z
static constexpr auto MOON_ICON_PATH = "M13.39 9.15A6 6 0 1 1 6.54 2.08a5 5 0 0 0 6.85 7.07z"sv;
static constexpr auto DOCUMENT_ICON_PATH = "M3.5 1.5h5l4 4v9h-9zM8.5 1.5v4h4"sv;
static constexpr auto COMPOSITOR_ICON_PATH = "M5.5 6.5h9v7h-9zM5.5 9.5h-4v-7h9v4"sv;
+static constexpr auto HUB_ICON_PATH = "M7.5 5.5a2 2 0 1 1 0 4a2 2 0 1 1 0-4zM7.5 1.5a1 1 0 1 1 0 2a1 1 0 1 1 0-2zM7.5 11.5a1 1 0 1 1 0 2a1 1 0 1 1 0-2zM2.5 6.5a1 1 0 1 1 0 2a1 1 0 1 1 0-2zM12.5 6.5a1 1 0 1 1 0 2a1 1 0 1 1 0-2zM7.5 3.5v2M7.5 9.5v2M3.5 7.5h2M9.5 7.5h2"sv;
static constexpr auto IMAGE_ICON_PATH = "M2.5 2.5h11a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1v-9a1 1 0 0 1 1-1zM1.5 11.5l3.5-3.5 5.5 5.5M9.5 9.5l2-2 3 3M10.5 5.5v.01"sv;
static constexpr auto FOLDER_ICON_PATH = "M2.5 2.5h3l2 2h6a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1v-9a1 1 0 0 1 1-1z"sv;
static constexpr auto FEEDBACK_ICON_PATH = "M3.5 1.5h8a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2h-4l-3 3v-3h-1a2 2 0 0 1-2-2v-6a2 2 0 0 1 2-2zM7.5 3.5v3M7.5 8.5v.01"sv;
@@ -355,6 +356,8 @@ static StringView chrome_icon_path(ChromeIcon icon)
return GLOBE_ICON_PATH;
case ChromeIcon::Compositor:
return COMPOSITOR_ICON_PATH;
+ case ChromeIcon::Hub:
+ return HUB_ICON_PATH;
case ChromeIcon::Image:
return IMAGE_ICON_PATH;
case ChromeIcon::Download:
diff --git a/UI/Qt/Icon.h b/UI/Qt/Icon.h
index 1aa09cf244b..d6f28d06210 100644
--- a/UI/Qt/Icon.h
+++ b/UI/Qt/Icon.h
@@ -51,6 +51,7 @@ enum class ChromeIcon {
Document,
Network,
Compositor,
+ Hub,
Image,
Warning,
Pause,
diff --git a/UI/Qt/ProcessManagerWindow.cpp b/UI/Qt/ProcessManagerWindow.cpp
index 9a6c041365c..0f87bd20cd1 100644
--- a/UI/Qt/ProcessManagerWindow.cpp
+++ b/UI/Qt/ProcessManagerWindow.cpp
@@ -347,6 +347,12 @@ private:
}
+// The processes that are the browser itself, which cannot go without taking everything else with them.
+static bool is_browser_process(WebView::ProcessType type)
+{
+ return first_is_one_of(type, WebView::ProcessType::Browser, WebView::ProcessType::UI, WebView::ProcessType::Hub);
+}
+
ProcessManagerWindow::ProcessManagerWindow(Source source)
: m_source(AK::move(source))
{
@@ -576,6 +582,7 @@ QTreeWidget::item {{
m_document_icon = create_chrome_icon(ChromeIcon::Document, panel.body);
m_network_icon = create_chrome_icon(ChromeIcon::Network, panel.body);
m_compositor_icon = create_chrome_icon(ChromeIcon::Compositor, panel.body);
+ m_hub_icon = create_chrome_icon(ChromeIcon::Hub, panel.body);
m_image_icon = create_chrome_icon(ChromeIcon::Image, panel.body);
m_service_icon = create_chrome_icon(ChromeIcon::WindowRestore, panel.body);
auto search_icon = create_chrome_icon(ChromeIcon::Search, panel.muted);
@@ -733,8 +740,10 @@ void ProcessManagerWindow::refresh()
item->setText(Name, name);
item->setToolTip(Name, name);
switch (process.type) {
- case WebView::ProcessType::Browser: {
- item->setIcon(Name, m_browser_icon);
+ case WebView::ProcessType::Browser:
+ case WebView::ProcessType::UI:
+ case WebView::ProcessType::Hub: {
+ item->setIcon(Name, process.type == WebView::ProcessType::Hub ? m_hub_icon : m_browser_icon);
auto font = item->font(Name);
font.setWeight(QFont::DemiBold);
item->setFont(Name, font);
@@ -817,17 +826,19 @@ void ProcessManagerWindow::refresh()
}
};
- // The browser comes first among its own processes, whatever the order.
+ // The browser comes first among its own processes, whatever the order, with the UI ahead of the Hub.
Vector<QTreeWidgetItem*> own_items;
- QTreeWidgetItem* browser_item = nullptr;
+ Vector<QTreeWidgetItem*> browser_items;
for (auto const* process : own_processes) {
auto* item = make_process_item(*process, true);
- if (process->type == WebView::ProcessType::Browser)
- browser_item = item;
+ if (process->type == WebView::ProcessType::UI)
+ browser_items.prepend(item);
+ else if (is_browser_process(process->type))
+ browser_items.append(item);
else
own_items.append(item);
}
- if (browser_item) {
+ for (auto* browser_item : browser_items) {
m_processes->addTopLevelItem(browser_item);
if (selected_child_id.isValid() && browser_item->data(PID, ChildIDRole) == selected_child_id)
item_to_select = browser_item;
@@ -973,7 +984,7 @@ void ProcessManagerWindow::update_actions()
}
auto process_type = m_process_types.get(item->data(PID, ChildIDRole).toULongLong());
m_copy_pid_action->setEnabled(process_type.has_value());
- m_end_action->setEnabled(process_type.has_value() && *process_type != WebView::ProcessType::Browser);
+ m_end_action->setEnabled(process_type.has_value() && !is_browser_process(*process_type));
}
void ProcessManagerWindow::end_selection()
diff --git a/UI/Qt/ProcessManagerWindow.h b/UI/Qt/ProcessManagerWindow.h
index 7cc6dbd962a..c7aedf1e779 100644
--- a/UI/Qt/ProcessManagerWindow.h
+++ b/UI/Qt/ProcessManagerWindow.h
@@ -90,6 +90,7 @@ private:
QIcon m_document_icon;
QIcon m_network_icon;
QIcon m_compositor_icon;
+ QIcon m_hub_icon;
QIcon m_image_icon;
QIcon m_service_icon;
HashMap<String, QIcon> m_favicons;