From 2851c05dee47ff377d811b54fb404e3b6afaa8c1 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 22 Apr 2024 14:11:46 -0400 Subject: [PATCH] LibWebView: Display each tab's title in the Task Manager This allows us to more easily differentiate between WebContent processes in the Task Manager at a glance. --- Userland/Libraries/LibWebView/ProcessInfo.h | 3 +++ Userland/Libraries/LibWebView/ProcessManager.cpp | 4 +++- Userland/Libraries/LibWebView/WebContentClient.cpp | 7 +++++++ Userland/Libraries/LibWebView/WebContentClient.h | 2 ++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWebView/ProcessInfo.h b/Userland/Libraries/LibWebView/ProcessInfo.h index 5cf5c62479a..55f25edb6bb 100644 --- a/Userland/Libraries/LibWebView/ProcessInfo.h +++ b/Userland/Libraries/LibWebView/ProcessInfo.h @@ -6,6 +6,8 @@ #pragma once +#include +#include #include #include @@ -34,6 +36,7 @@ struct ProcessInfo : public Core::Platform::ProcessInfo { } ProcessType type { ProcessType::WebContent }; + Optional title; }; } diff --git a/Userland/Libraries/LibWebView/ProcessManager.cpp b/Userland/Libraries/LibWebView/ProcessManager.cpp index 2881499369a..9a50b28cf97 100644 --- a/Userland/Libraries/LibWebView/ProcessManager.cpp +++ b/Userland/Libraries/LibWebView/ProcessManager.cpp @@ -197,7 +197,7 @@ String ProcessManager::generate_html() - + @@ -210,6 +210,8 @@ String ProcessManager::generate_html() builder.append(""sv); builder.append(""sv); builder.append("
TypeName PID Memory Usage CPU %
"sv); builder.append(WebView::process_name_from_type(process.type)); + if (process.title.has_value()) + builder.appendff(" - {}", *process.title); builder.append(""sv); builder.append(MUST(String::number(process.pid))); diff --git a/Userland/Libraries/LibWebView/WebContentClient.cpp b/Userland/Libraries/LibWebView/WebContentClient.cpp index 5d91e516b2a..03c55aff7b8 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.cpp +++ b/Userland/Libraries/LibWebView/WebContentClient.cpp @@ -38,6 +38,7 @@ void WebContentClient::notify_process_information(WebView::ProcessHandle const& { dbgln_if(SPAM_DEBUG, "handle: WebContentClient::NotifyProcessInformation! pid={}", handle.pid); ProcessManager::the().add_process(ProcessType::WebContent, handle.pid); + m_process_handle = handle; } void WebContentClient::did_paint(u64 page_id, Gfx::IntRect const& rect, i32 bitmap_id) @@ -48,6 +49,9 @@ void WebContentClient::did_paint(u64 page_id, Gfx::IntRect const& rect, i32 bitm void WebContentClient::did_start_loading(u64 page_id, URL::URL const& url, bool is_redirect) { + if (auto* process = WebView::ProcessManager::the().find_process(m_process_handle.pid)) + process->title.clear(); + if (auto view = view_for_page_id(page_id); view.has_value()) { view->set_url({}, url); @@ -121,6 +125,9 @@ void WebContentClient::did_layout(u64 page_id, Gfx::IntSize content_size) void WebContentClient::did_change_title(u64 page_id, ByteString const& title) { + if (auto* process = WebView::ProcessManager::the().find_process(m_process_handle.pid)) + process->title = MUST(String::from_byte_string(title)); + if (auto view = view_for_page_id(page_id); view.has_value()) { if (!view->on_title_change) return; diff --git a/Userland/Libraries/LibWebView/WebContentClient.h b/Userland/Libraries/LibWebView/WebContentClient.h index 274d294268c..36752692a76 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.h +++ b/Userland/Libraries/LibWebView/WebContentClient.h @@ -115,6 +115,8 @@ private: // FIXME: Does a HashMap holding references make sense? HashMap m_views; + + ProcessHandle m_process_handle; }; }