From 652dde50226ae683e6a9a0c59a6c1e2c176be76d Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 13 Nov 2024 16:04:33 -0500 Subject: [PATCH] LibWebView+UI: Acquire the paths to helper processes inside LibWebView We no longer need to acquire these paths from the UI and pass them into LibWebView - we can figure out these paths internally. --- Libraries/LibWebView/Application.cpp | 8 ++------ Libraries/LibWebView/HelperProcess.cpp | 18 +++++++++--------- Libraries/LibWebView/HelperProcess.h | 9 +++------ UI/AppKit/Interface/LadybirdWebView.mm | 3 +-- UI/AppKit/Interface/LadybirdWebViewBridge.cpp | 6 +----- UI/Headless/HeadlessWebView.cpp | 8 ++------ UI/Qt/WebContentView.cpp | 8 ++------ 7 files changed, 20 insertions(+), 40 deletions(-) diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cpp index 423470ea20e..376fa29b60f 100644 --- a/Libraries/LibWebView/Application.cpp +++ b/Libraries/LibWebView/Application.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include namespace WebView { @@ -180,16 +179,13 @@ ErrorOr Application::launch_services() ErrorOr Application::launch_request_server() { // FIXME: Create an abstraction to re-spawn the RequestServer and re-hook up its client hooks to each tab on crash - auto paths = TRY(get_paths_for_helper_process("RequestServer"sv)); - m_request_server_client = TRY(launch_request_server_process(paths)); - + m_request_server_client = TRY(launch_request_server_process()); return {}; } ErrorOr Application::launch_image_decoder_server() { - auto paths = TRY(get_paths_for_helper_process("ImageDecoder"sv)); - m_image_decoder_client = TRY(launch_image_decoder_process(paths)); + m_image_decoder_client = TRY(launch_image_decoder_process()); m_image_decoder_client->on_death = [this]() { m_image_decoder_client = nullptr; diff --git a/Libraries/LibWebView/HelperProcess.cpp b/Libraries/LibWebView/HelperProcess.cpp index 94c711712cd..f59abe243c8 100644 --- a/Libraries/LibWebView/HelperProcess.cpp +++ b/Libraries/LibWebView/HelperProcess.cpp @@ -15,13 +15,14 @@ namespace WebView { template static ErrorOr> launch_server_process( StringView server_name, - ReadonlySpan candidate_server_paths, Vector arguments, ClientArguments&&... client_arguments) { auto process_type = WebView::process_type_from_name(server_name); auto const& chrome_options = WebView::Application::chrome_options(); + auto candidate_server_paths = TRY(get_paths_for_helper_process(server_name)); + if (chrome_options.profile_helper_process == process_type) { arguments.prepend({ "--tool=callgrind"sv, @@ -75,7 +76,6 @@ static ErrorOr> launch_server_process( ErrorOr> launch_web_content_process( WebView::ViewImplementation& view, - ReadonlySpan candidate_web_content_paths, IPC::File image_decoder_socket, Optional request_server_socket) { @@ -121,10 +121,10 @@ ErrorOr> launch_web_content_process( arguments.append("--image-decoder-socket"sv); arguments.append(ByteString::number(image_decoder_socket.fd())); - return launch_server_process("WebContent"sv, candidate_web_content_paths, move(arguments), view); + return launch_server_process("WebContent"sv, move(arguments), view); } -ErrorOr> launch_image_decoder_process(ReadonlySpan candidate_image_decoder_paths) +ErrorOr> launch_image_decoder_process() { Vector arguments; if (auto server = mach_server_name(); server.has_value()) { @@ -132,10 +132,10 @@ ErrorOr> launch_image_decoder_process( arguments.append(server.value()); } - return launch_server_process("ImageDecoder"sv, candidate_image_decoder_paths, arguments); + return launch_server_process("ImageDecoder"sv, arguments); } -ErrorOr> launch_web_worker_process(ReadonlySpan candidate_web_worker_paths) +ErrorOr> launch_web_worker_process() { Vector arguments; @@ -143,10 +143,10 @@ ErrorOr> launch_web_worker_process(Rea arguments.append("--request-server-socket"sv); arguments.append(ByteString::number(socket.fd())); - return launch_server_process("WebWorker"sv, candidate_web_worker_paths, move(arguments)); + return launch_server_process("WebWorker"sv, move(arguments)); } -ErrorOr> launch_request_server_process(ReadonlySpan candidate_request_server_paths) +ErrorOr> launch_request_server_process() { Vector arguments; @@ -163,7 +163,7 @@ ErrorOr> launch_request_server_process(Re arguments.append(server.value()); } - return launch_server_process("RequestServer"sv, candidate_request_server_paths, move(arguments)); + return launch_server_process("RequestServer"sv, move(arguments)); } ErrorOr connect_new_request_server_client() diff --git a/Libraries/LibWebView/HelperProcess.h b/Libraries/LibWebView/HelperProcess.h index 2d7a8b88c6e..a0a66a0eb34 100644 --- a/Libraries/LibWebView/HelperProcess.h +++ b/Libraries/LibWebView/HelperProcess.h @@ -8,8 +8,6 @@ #include #include -#include -#include #include #include #include @@ -20,13 +18,12 @@ namespace WebView { ErrorOr> launch_web_content_process( WebView::ViewImplementation& view, - ReadonlySpan candidate_web_content_paths, IPC::File image_decoder_socket, Optional request_server_socket = {}); -ErrorOr> launch_image_decoder_process(ReadonlySpan candidate_image_decoder_paths); -ErrorOr> launch_web_worker_process(ReadonlySpan candidate_web_worker_paths); -ErrorOr> launch_request_server_process(ReadonlySpan candidate_request_server_paths); +ErrorOr> launch_image_decoder_process(); +ErrorOr> launch_web_worker_process(); +ErrorOr> launch_request_server_process(); ErrorOr connect_new_request_server_client(); ErrorOr connect_new_image_decoder_client(); diff --git a/UI/AppKit/Interface/LadybirdWebView.mm b/UI/AppKit/Interface/LadybirdWebView.mm index 28085b40280..631ae6e0a7f 100644 --- a/UI/AppKit/Interface/LadybirdWebView.mm +++ b/UI/AppKit/Interface/LadybirdWebView.mm @@ -16,7 +16,6 @@ #include #include #include -#include #import #import @@ -347,7 +346,7 @@ static void copy_data_to_clipboard(StringView data, NSPasteboardType pasteboard_ }; m_web_view_bridge->on_request_worker_agent = []() { - auto worker_client = MUST(WebView::launch_web_worker_process(MUST(WebView::get_paths_for_helper_process("WebWorker"sv)))); + auto worker_client = MUST(WebView::launch_web_worker_process()); return worker_client->clone_transport(); }; diff --git a/UI/AppKit/Interface/LadybirdWebViewBridge.cpp b/UI/AppKit/Interface/LadybirdWebViewBridge.cpp index e6570c04d53..b05b74896dc 100644 --- a/UI/AppKit/Interface/LadybirdWebViewBridge.cpp +++ b/UI/AppKit/Interface/LadybirdWebViewBridge.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #import @@ -151,10 +150,7 @@ void WebViewBridge::initialize_client(CreateNewClient create_new_client) auto request_server_socket = WebView::connect_new_request_server_client().release_value_but_fixme_should_propagate_errors(); auto image_decoder_socket = WebView::connect_new_image_decoder_client().release_value_but_fixme_should_propagate_errors(); - auto candidate_web_content_paths = WebView::get_paths_for_helper_process("WebContent"sv).release_value_but_fixme_should_propagate_errors(); - auto new_client = launch_web_content_process(*this, candidate_web_content_paths, AK::move(image_decoder_socket), AK::move(request_server_socket)).release_value_but_fixme_should_propagate_errors(); - - m_client_state.client = new_client; + m_client_state.client = launch_web_content_process(*this, AK::move(image_decoder_socket), AK::move(request_server_socket)).release_value_but_fixme_should_propagate_errors(); } else { m_client_state.client->register_view(m_client_state.page_index, *this); } diff --git a/UI/Headless/HeadlessWebView.cpp b/UI/Headless/HeadlessWebView.cpp index 4e0460c8d29..8116a9b858d 100644 --- a/UI/Headless/HeadlessWebView.cpp +++ b/UI/Headless/HeadlessWebView.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include @@ -32,9 +31,7 @@ HeadlessWebView::HeadlessWebView(Core::AnonymousBuffer theme, Web::DevicePixelSi }; on_request_worker_agent = []() { - auto web_worker_paths = MUST(WebView::get_paths_for_helper_process("WebWorker"sv)); - auto worker_client = MUST(WebView::launch_web_worker_process(web_worker_paths)); - + auto worker_client = MUST(WebView::launch_web_worker_process()); return worker_client->clone_transport(); }; @@ -165,8 +162,7 @@ void HeadlessWebView::initialize_client(CreateNewClient create_new_client) auto request_server_socket = WebView::connect_new_request_server_client().release_value_but_fixme_should_propagate_errors(); auto image_decoder_socket = WebView::connect_new_image_decoder_client().release_value_but_fixme_should_propagate_errors(); - auto web_content_paths = WebView::get_paths_for_helper_process("WebContent"sv).release_value_but_fixme_should_propagate_errors(); - m_client_state.client = WebView::launch_web_content_process(*this, web_content_paths, move(image_decoder_socket), move(request_server_socket)).release_value_but_fixme_should_propagate_errors(); + m_client_state.client = WebView::launch_web_content_process(*this, move(image_decoder_socket), move(request_server_socket)).release_value_but_fixme_should_propagate_errors(); } else { m_client_state.client->register_view(m_client_state.page_index, *this); } diff --git a/UI/Qt/WebContentView.cpp b/UI/Qt/WebContentView.cpp index f5a41b553ca..a3f871458d3 100644 --- a/UI/Qt/WebContentView.cpp +++ b/UI/Qt/WebContentView.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -128,7 +127,7 @@ WebContentView::WebContentView(QWidget* window, RefPtrclone_transport(); }; @@ -632,10 +631,7 @@ void WebContentView::initialize_client(WebView::ViewImplementation::CreateNewCli auto request_server_socket = WebView::connect_new_request_server_client().release_value_but_fixme_should_propagate_errors(); auto image_decoder_socket = WebView::connect_new_image_decoder_client().release_value_but_fixme_should_propagate_errors(); - auto candidate_web_content_paths = WebView::get_paths_for_helper_process("WebContent"sv).release_value_but_fixme_should_propagate_errors(); - auto new_client = launch_web_content_process(*this, candidate_web_content_paths, AK::move(image_decoder_socket), AK::move(request_server_socket)).release_value_but_fixme_should_propagate_errors(); - - m_client_state.client = new_client; + m_client_state.client = launch_web_content_process(*this, AK::move(image_decoder_socket), AK::move(request_server_socket)).release_value_but_fixme_should_propagate_errors(); } else { m_client_state.client->register_view(m_client_state.page_index, *this); }