From c46bea479c1cbf9bb9a30cbecaaa10c85a4ba321 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 18 Jun 2024 19:11:51 +0300 Subject: [PATCH] Everywhere: Hand pid of new process to client in launch_server_process() Allows WebContentClient to get pid of WebContent process right after creation, so there is no window between forking and notify_process_information() IPC response, when client doesn't know the pid. --- Ladybird/HelperProcess.cpp | 3 +++ Userland/Libraries/LibWebView/WebContentClient.cpp | 7 ------- Userland/Libraries/LibWebView/WebContentClient.h | 3 ++- Userland/Services/WebContent/ConnectionFromClient.cpp | 1 - Userland/Services/WebContent/WebContentClient.ipc | 2 -- 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Ladybird/HelperProcess.cpp b/Ladybird/HelperProcess.cpp index 54d3431ffd9..4d3c2c17d6a 100644 --- a/Ladybird/HelperProcess.cpp +++ b/Ladybird/HelperProcess.cpp @@ -48,6 +48,9 @@ static ErrorOr> launch_server_process( if (!result.is_error()) { auto process = result.release_value(); + if constexpr (requires { process.client->set_pid(pid_t {}); }) + process.client->set_pid(process.process.pid()); + if (register_with_process_manager == RegisterWithProcessManager::Yes) WebView::ProcessManager::the().add_process(WebView::process_type_from_name(server_name), process.process.pid()); diff --git a/Userland/Libraries/LibWebView/WebContentClient.cpp b/Userland/Libraries/LibWebView/WebContentClient.cpp index ad3099c3507..10b6dafab0f 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.cpp +++ b/Userland/Libraries/LibWebView/WebContentClient.cpp @@ -34,13 +34,6 @@ void WebContentClient::unregister_view(u64 page_id) m_views.remove(page_id); } -void WebContentClient::notify_process_information(WebView::ProcessHandle const& handle) -{ - 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) { if (auto view = view_for_page_id(page_id); view.has_value()) diff --git a/Userland/Libraries/LibWebView/WebContentClient.h b/Userland/Libraries/LibWebView/WebContentClient.h index e771081f510..1c59667e124 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.h +++ b/Userland/Libraries/LibWebView/WebContentClient.h @@ -33,10 +33,11 @@ public: Function on_web_content_process_crash; + void set_pid(pid_t pid) { m_process_handle.pid = pid; } + private: virtual void die() override; - virtual void notify_process_information(WebView::ProcessHandle const&) override; virtual void did_paint(u64 page_id, Gfx::IntRect const&, i32) override; virtual void did_finish_loading(u64 page_id, URL::URL const&) override; virtual void did_request_navigate_back(u64 page_id) override; diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index cf94cca371f..d35072fd667 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -55,7 +55,6 @@ ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr sock , m_page_host(PageHost::create(*this)) { m_input_event_queue_timer = Web::Platform::Timer::create_single_shot(0, [this] { process_next_input_event(); }); - async_notify_process_information({ ::getpid() }); } ConnectionFromClient::~ConnectionFromClient() = default; diff --git a/Userland/Services/WebContent/WebContentClient.ipc b/Userland/Services/WebContent/WebContentClient.ipc index 404475452ea..3ec9d8ef7b5 100644 --- a/Userland/Services/WebContent/WebContentClient.ipc +++ b/Userland/Services/WebContent/WebContentClient.ipc @@ -17,8 +17,6 @@ endpoint WebContentClient { - notify_process_information(WebView::ProcessHandle handle) =| - did_start_loading(u64 page_id, URL::URL url, bool is_redirect) =| did_finish_loading(u64 page_id, URL::URL url) =| did_request_navigate_back(u64 page_id) =|