From 54f66c574ca02a592490946149fd05bcc4e1e6ee Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Wed, 26 Jun 2024 13:43:45 -0600 Subject: [PATCH] LibWebView: Allow querying and iterating all extant WebContentClients This is mostly useful when some application-level logic needs to iterate over all child processes. A more robust Process abstraction would make this easier. --- .../Libraries/LibWebView/WebContentClient.cpp | 2 +- Userland/Libraries/LibWebView/WebContentClient.h | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWebView/WebContentClient.cpp b/Userland/Libraries/LibWebView/WebContentClient.cpp index edb4612257e..3b36a777bcf 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.cpp +++ b/Userland/Libraries/LibWebView/WebContentClient.cpp @@ -11,7 +11,7 @@ namespace WebView { -static HashTable s_clients; +HashTable WebContentClient::s_clients; Optional WebContentClient::view_for_pid_and_page_id(pid_t pid, u64 page_id) { diff --git a/Userland/Libraries/LibWebView/WebContentClient.h b/Userland/Libraries/LibWebView/WebContentClient.h index 6e2df157d06..3a21c5b75ad 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.h +++ b/Userland/Libraries/LibWebView/WebContentClient.h @@ -28,6 +28,11 @@ class WebContentClient final public: static Optional view_for_pid_and_page_id(pid_t pid, u64 page_id); + template Callback> + static void for_each_client(Callback callback); + + static size_t client_count() { return s_clients.size(); } + WebContentClient(NonnullOwnPtr, ViewImplementation&); ~WebContentClient(); @@ -121,6 +126,17 @@ private: HashMap m_views; ProcessHandle m_process_handle; + + static HashTable s_clients; }; +template Callback> +void WebContentClient::for_each_client(Callback callback) +{ + for (auto& it : s_clients) { + if (callback(*it) == IterationDecision::Break) + return; + } +} + }