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.
This commit is contained in:
Andrew Kaster 2024-06-26 13:43:45 -06:00 committed by Andrew Kaster
parent 7c607a4749
commit 54f66c574c
Notes: sideshowbarker 2024-07-16 21:34:08 +09:00
2 changed files with 17 additions and 1 deletions

View File

@ -11,7 +11,7 @@
namespace WebView {
static HashTable<WebContentClient*> s_clients;
HashTable<WebContentClient*> WebContentClient::s_clients;
Optional<ViewImplementation&> WebContentClient::view_for_pid_and_page_id(pid_t pid, u64 page_id)
{

View File

@ -28,6 +28,11 @@ class WebContentClient final
public:
static Optional<ViewImplementation&> view_for_pid_and_page_id(pid_t pid, u64 page_id);
template<CallableAs<IterationDecision, WebContentClient&> Callback>
static void for_each_client(Callback callback);
static size_t client_count() { return s_clients.size(); }
WebContentClient(NonnullOwnPtr<Core::LocalSocket>, ViewImplementation&);
~WebContentClient();
@ -121,6 +126,17 @@ private:
HashMap<u64, ViewImplementation*> m_views;
ProcessHandle m_process_handle;
static HashTable<WebContentClient*> s_clients;
};
template<CallableAs<IterationDecision, WebContentClient&> Callback>
void WebContentClient::for_each_client(Callback callback)
{
for (auto& it : s_clients) {
if (callback(*it) == IterationDecision::Break)
return;
}
}
}