From 02edd240aed003954c1ce9fef7e700998031844c Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sat, 6 Jan 2024 13:13:59 -0700 Subject: [PATCH] LibWeb+WebContent: Spawn Worker processes from the chrome Instead of spawning these processes from the WebContent process, we now create them in the Browser chrome. Part 1/N of "all processes are owned by the chrome". --- Ladybird/AppKit/UI/LadybirdWebViewBridge.cpp | 5 + Ladybird/HelperProcess.cpp | 5 + Ladybird/HelperProcess.h | 2 + Ladybird/Qt/WebContentView.cpp | 6 + Ladybird/WebWorker/main.cpp | 2 + .../Userland/Libraries/LibWebView/BUILD.gn | 1 + Userland/Applications/Browser/main.cpp | 1 + Userland/Libraries/LibWeb/Forward.h | 1 + .../Libraries/LibWeb/HTML/WorkerAgent.cpp | 104 +++--------------- Userland/Libraries/LibWeb/HTML/WorkerAgent.h | 10 +- Userland/Libraries/LibWeb/Page/Page.h | 3 + .../LibWeb/Worker/WebWorkerClient.cpp | 9 ++ .../Libraries/LibWeb/Worker/WebWorkerClient.h | 3 + Userland/Libraries/LibWebView/CMakeLists.txt | 1 + Userland/Libraries/LibWebView/Forward.h | 1 + .../LibWebView/OutOfProcessWebView.cpp | 6 + Userland/Libraries/LibWebView/SocketPair.cpp | 26 +++++ Userland/Libraries/LibWebView/SocketPair.h | 28 +++++ .../Libraries/LibWebView/ViewImplementation.h | 1 + .../Libraries/LibWebView/WebContentClient.cpp | 8 ++ .../Libraries/LibWebView/WebContentClient.h | 1 + Userland/Services/WebContent/PageClient.cpp | 12 ++ Userland/Services/WebContent/PageClient.h | 1 + .../Services/WebContent/WebContentClient.ipc | 3 + Userland/Services/WebContent/main.cpp | 1 - Userland/Utilities/headless-browser.cpp | 10 ++ 26 files changed, 152 insertions(+), 99 deletions(-) create mode 100644 Userland/Libraries/LibWebView/SocketPair.cpp create mode 100644 Userland/Libraries/LibWebView/SocketPair.h diff --git a/Ladybird/AppKit/UI/LadybirdWebViewBridge.cpp b/Ladybird/AppKit/UI/LadybirdWebViewBridge.cpp index 26ba08eab1..5200df0f4e 100644 --- a/Ladybird/AppKit/UI/LadybirdWebViewBridge.cpp +++ b/Ladybird/AppKit/UI/LadybirdWebViewBridge.cpp @@ -51,6 +51,11 @@ WebViewBridge::WebViewBridge(Vector screen_rects, float de if (on_scroll) on_scroll(to_widget_position(position)); }; + + on_request_worker_agent = []() { + auto worker_client = MUST(launch_web_worker_process(MUST(get_paths_for_helper_process("WebWorker"sv)))); + return worker_client->dup_sockets(); + }; } WebViewBridge::~WebViewBridge() = default; diff --git a/Ladybird/HelperProcess.cpp b/Ladybird/HelperProcess.cpp index c9f8ad67a4..2c055b0d91 100644 --- a/Ladybird/HelperProcess.cpp +++ b/Ladybird/HelperProcess.cpp @@ -152,6 +152,11 @@ ErrorOr> launch_image_decoder_process( return launch_generic_server_process(candidate_image_decoder_paths, ""sv, "ImageDecoder"sv); } +ErrorOr> launch_web_worker_process(ReadonlySpan candidate_web_worker_paths) +{ + return launch_generic_server_process(candidate_web_worker_paths, ""sv, "WebWorker"sv); +} + ErrorOr> launch_request_server_process(ReadonlySpan candidate_request_server_paths, StringView serenity_resource_root) { return launch_generic_server_process(candidate_request_server_paths, serenity_resource_root, "RequestServer"sv); diff --git a/Ladybird/HelperProcess.h b/Ladybird/HelperProcess.h index d22a32cd5f..72272dc291 100644 --- a/Ladybird/HelperProcess.h +++ b/Ladybird/HelperProcess.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -22,5 +23,6 @@ ErrorOr> launch_web_content_process( Ladybird::WebContentOptions const&); 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, StringView serenity_resource_root); ErrorOr> launch_web_socket_process(ReadonlySpan candidate_web_socket_paths, StringView serenity_resource_root); diff --git a/Ladybird/Qt/WebContentView.cpp b/Ladybird/Qt/WebContentView.cpp index bc7915e02d..b74aef9bf1 100644 --- a/Ladybird/Qt/WebContentView.cpp +++ b/Ladybird/Qt/WebContentView.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -113,6 +114,11 @@ WebContentView::WebContentView(WebContentOptions const& web_content_options, Str on_leave_tooltip_area = []() { QToolTip::hideText(); }; + + on_request_worker_agent = []() { + auto worker_client = MUST(launch_web_worker_process(MUST(get_paths_for_helper_process("WebWorker"sv)))); + return worker_client->dup_sockets(); + }; } WebContentView::~WebContentView() = default; diff --git a/Ladybird/WebWorker/main.cpp b/Ladybird/WebWorker/main.cpp index 6ff36a0a8c..51c382e85a 100644 --- a/Ladybird/WebWorker/main.cpp +++ b/Ladybird/WebWorker/main.cpp @@ -33,9 +33,11 @@ ErrorOr serenity_main(Main::Arguments arguments) AK::set_rich_debug_enabled(true); int fd_passing_socket { -1 }; + StringView serenity_resource_root; Core::ArgsParser args_parser; args_parser.add_option(fd_passing_socket, "File descriptor of the fd passing socket", "fd-passing-socket", 'c', "fd-passing-socket"); + args_parser.add_option(serenity_resource_root, "Absolute path to directory for serenity resources", "serenity-resource-root", 'r', "serenity-resource-root"); args_parser.parse(arguments); platform_init(); diff --git a/Meta/gn/secondary/Userland/Libraries/LibWebView/BUILD.gn b/Meta/gn/secondary/Userland/Libraries/LibWebView/BUILD.gn index 3046bb980c..dad1fbac77 100644 --- a/Meta/gn/secondary/Userland/Libraries/LibWebView/BUILD.gn +++ b/Meta/gn/secondary/Userland/Libraries/LibWebView/BUILD.gn @@ -123,6 +123,7 @@ shared_library("LibWebView") { "InspectorClient.cpp", "RequestServerAdapter.cpp", "SearchEngine.cpp", + "SocketPair.cpp", "SourceHighlighter.cpp", "URL.cpp", "UserAgent.cpp", diff --git a/Userland/Applications/Browser/main.cpp b/Userland/Applications/Browser/main.cpp index d3a2c3ed4b..b0f8751a10 100644 --- a/Userland/Applications/Browser/main.cpp +++ b/Userland/Applications/Browser/main.cpp @@ -119,6 +119,7 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::unveil("/tmp/session/%sid/portal/filesystemaccess", "rw")); TRY(Core::System::unveil("/tmp/session/%sid/portal/image", "rw")); TRY(Core::System::unveil("/tmp/session/%sid/portal/webcontent", "rw")); + TRY(Core::System::unveil("/tmp/session/%sid/portal/webworker", "rw")); TRY(Core::System::unveil("/tmp/session/%sid/portal/request", "rw")); TRY(Core::System::unveil("/tmp/session/%sid/portal/sql", "rw")); TRY(Core::System::unveil("/home", "rwc")); diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index de6b9f0bc8..7612fb1862 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -457,6 +457,7 @@ class Window; class WindowEnvironmentSettingsObject; class WindowProxy; class Worker; +class WorkerAgent; class WorkerDebugConsoleClient; class WorkerEnvironmentSettingsObject; class WorkerGlobalScope; diff --git a/Userland/Libraries/LibWeb/HTML/WorkerAgent.cpp b/Userland/Libraries/LibWeb/HTML/WorkerAgent.cpp index d657fca385..8b537a0c92 100644 --- a/Userland/Libraries/LibWeb/HTML/WorkerAgent.cpp +++ b/Userland/Libraries/LibWeb/HTML/WorkerAgent.cpp @@ -4,93 +4,11 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include -#include -#include +#include #include +#include #include -// FIXME: Deduplicate this code with ladybird!! - -#ifndef AK_OS_SERENITY -namespace { - -ErrorOr application_directory() -{ - auto current_executable_path = TRY(Core::System::current_executable_path()); - auto dirname = LexicalPath::dirname(current_executable_path); - return String::from_byte_string(dirname); -} - -ErrorOr> get_paths_for_helper_process(StringView process_name) -{ - auto application_path = TRY(application_directory()); - Vector paths; - - TRY(paths.try_append(TRY(String::formatted("{}/{}", application_path, process_name)))); - TRY(paths.try_append(TRY(String::formatted("./{}", process_name)))); - // NOTE: Add platform-specific paths here - return paths; -} - -ErrorOr> launch_web_worker_process(ReadonlySpan candidate_web_content_paths) -{ - int socket_fds[2] {}; - TRY(Core::System::socketpair(AF_LOCAL, SOCK_STREAM, 0, socket_fds)); - - int ui_fd = socket_fds[0]; - int wc_fd = socket_fds[1]; - - int fd_passing_socket_fds[2] {}; - TRY(Core::System::socketpair(AF_LOCAL, SOCK_STREAM, 0, fd_passing_socket_fds)); - - int ui_fd_passing_fd = fd_passing_socket_fds[0]; - int wc_fd_passing_fd = fd_passing_socket_fds[1]; - - if (auto child_pid = TRY(Core::System::fork()); child_pid == 0) { - TRY(Core::System::close(ui_fd_passing_fd)); - TRY(Core::System::close(ui_fd)); - - auto takeover_string = TRY(String::formatted("WebWorker:{}", wc_fd)); - TRY(Core::System::setenv("SOCKET_TAKEOVER"sv, takeover_string, true)); - - auto webcontent_fd_passing_socket_string = TRY(String::number(wc_fd_passing_fd)); - - ErrorOr result; - for (auto const& path : candidate_web_content_paths) { - if (Core::System::access(path, X_OK).is_error()) - continue; - - auto arguments = Vector { - path.bytes_as_string_view(), - "--fd-passing-socket"sv, - webcontent_fd_passing_socket_string - }; - - result = Core::System::exec(arguments[0], arguments.span(), Core::System::SearchInPath::Yes); - if (!result.is_error()) - break; - } - - if (result.is_error()) - warnln("Could not launch any of {}: {}", candidate_web_content_paths, result.error()); - VERIFY_NOT_REACHED(); - } - - TRY(Core::System::close(wc_fd_passing_fd)); - TRY(Core::System::close(wc_fd)); - - auto socket = TRY(Core::LocalSocket::adopt_fd(ui_fd)); - TRY(socket->set_blocking(true)); - - auto new_client = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Web::HTML::WebWorkerClient(move(socket)))); - new_client->set_fd_passing_socket(TRY(Core::LocalSocket::adopt_fd(ui_fd_passing_fd))); - - return new_client; -} -} -#endif - namespace Web::HTML { JS_DEFINE_ALLOCATOR(WorkerAgent); @@ -109,16 +27,20 @@ void WorkerAgent::initialize(JS::Realm& realm) m_message_port = MessagePort::create(realm); m_message_port->entangle_with(*m_outside_port); -#ifndef AK_OS_SERENITY - auto paths = MUST(get_paths_for_helper_process("WebWorker"sv)); - m_worker_ipc = MUST(launch_web_worker_process(paths)); -#else - m_worker_ipc = MUST(Web::HTML::WebWorkerClient::try_create()); -#endif - TransferDataHolder data_holder; MUST(m_message_port->transfer_steps(data_holder)); + // NOTE: This blocking IPC call may launch another process. + // If spinning the event loop for this can cause other javascript to execute, we're in trouble. + auto worker_ipc_sockets = Bindings::host_defined_page(realm).client().request_worker_agent(); + auto worker_socket = MUST(Core::LocalSocket::adopt_fd(worker_ipc_sockets.socket.take_fd())); + MUST(worker_socket->set_blocking(true)); + + auto fd_passing_socket = MUST(Core::LocalSocket::adopt_fd(worker_ipc_sockets.fd_passing_socket.take_fd())); + + m_worker_ipc = make_ref_counted(move(worker_socket)); + m_worker_ipc->set_fd_passing_socket(move(fd_passing_socket)); + m_worker_ipc->async_start_dedicated_worker(m_url, m_worker_options.type, m_worker_options.credentials, m_worker_options.name, move(data_holder)); } diff --git a/Userland/Libraries/LibWeb/HTML/WorkerAgent.h b/Userland/Libraries/LibWeb/HTML/WorkerAgent.h index 57f34078ae..14c84f4555 100644 --- a/Userland/Libraries/LibWeb/HTML/WorkerAgent.h +++ b/Userland/Libraries/LibWeb/HTML/WorkerAgent.h @@ -6,12 +6,8 @@ #pragma once -#include #include -#include #include -#include -#include #include namespace Web::HTML { @@ -22,14 +18,12 @@ struct WorkerOptions { String name { String {} }; }; -struct WorkerAgent : JS::Cell { +class WorkerAgent : public JS::Cell { JS_CELL(Agent, JS::Cell); JS_DECLARE_ALLOCATOR(WorkerAgent); WorkerAgent(AK::URL url, WorkerOptions const& options, JS::GCPtr outside_port); - RefPtr m_worker_ipc; - private: virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; @@ -39,6 +33,8 @@ private: JS::GCPtr m_message_port; JS::GCPtr m_outside_port; + + RefPtr m_worker_ipc; }; } diff --git a/Userland/Libraries/LibWeb/Page/Page.h b/Userland/Libraries/LibWeb/Page/Page.h index 4ccba1b3d9..32ab01a93c 100644 --- a/Userland/Libraries/LibWeb/Page/Page.h +++ b/Userland/Libraries/LibWeb/Page/Page.h @@ -34,6 +34,7 @@ #include #include #include +#include namespace Web { @@ -284,6 +285,8 @@ public: virtual void page_did_insert_clipboard_entry([[maybe_unused]] String data, [[maybe_unused]] String presentation_style, [[maybe_unused]] String mime_type) { } + virtual WebView::SocketPair request_worker_agent() { return { -1, -1 }; } + virtual void inspector_did_load() { } virtual void inspector_did_select_dom_node([[maybe_unused]] i32 node_id, [[maybe_unused]] Optional const& pseudo_element) { } virtual void inspector_did_set_dom_node_text([[maybe_unused]] i32 node_id, [[maybe_unused]] String const& text) { } diff --git a/Userland/Libraries/LibWeb/Worker/WebWorkerClient.cpp b/Userland/Libraries/LibWeb/Worker/WebWorkerClient.cpp index 0f98d4d7ae..02d85764b3 100644 --- a/Userland/Libraries/LibWeb/Worker/WebWorkerClient.cpp +++ b/Userland/Libraries/LibWeb/Worker/WebWorkerClient.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include namespace Web::HTML { @@ -18,4 +19,12 @@ WebWorkerClient::WebWorkerClient(NonnullOwnPtr socket) { } +WebView::SocketPair WebWorkerClient::dup_sockets() +{ + WebView::SocketPair pair; + pair.socket = MUST(Core::System::dup(socket().fd().value())); + pair.fd_passing_socket = MUST(Core::System::dup(fd_passing_socket().fd().value())); + return pair; +} + } diff --git a/Userland/Libraries/LibWeb/Worker/WebWorkerClient.h b/Userland/Libraries/LibWeb/Worker/WebWorkerClient.h index 1e5bb41257..5d3f51e917 100644 --- a/Userland/Libraries/LibWeb/Worker/WebWorkerClient.h +++ b/Userland/Libraries/LibWeb/Worker/WebWorkerClient.h @@ -10,6 +10,7 @@ #include #include #include +#include namespace Web::HTML { @@ -21,6 +22,8 @@ class WebWorkerClient final public: explicit WebWorkerClient(NonnullOwnPtr); + WebView::SocketPair dup_sockets(); + private: virtual void die() override; }; diff --git a/Userland/Libraries/LibWebView/CMakeLists.txt b/Userland/Libraries/LibWebView/CMakeLists.txt index 8eeac9b1d6..c866c5623c 100644 --- a/Userland/Libraries/LibWebView/CMakeLists.txt +++ b/Userland/Libraries/LibWebView/CMakeLists.txt @@ -8,6 +8,7 @@ set(SOURCES InspectorClient.cpp RequestServerAdapter.cpp SearchEngine.cpp + SocketPair.cpp SourceHighlighter.cpp URL.cpp UserAgent.cpp diff --git a/Userland/Libraries/LibWebView/Forward.h b/Userland/Libraries/LibWebView/Forward.h index b648b9be36..8334c88b15 100644 --- a/Userland/Libraries/LibWebView/Forward.h +++ b/Userland/Libraries/LibWebView/Forward.h @@ -21,6 +21,7 @@ class WebContentClient; struct Attribute; struct CookieStorageKey; struct SearchEngine; +struct SocketPair; } diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp index c706d78a0e..d57e62b926 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp @@ -17,6 +17,7 @@ #include #include #include +#include REGISTER_WIDGET(WebView, OutOfProcessWebView) @@ -71,6 +72,11 @@ OutOfProcessWebView::OutOfProcessWebView() on_finish_handling_input_event = [this](auto event_was_accepted) { did_finish_handling_input_event(event_was_accepted); }; + + on_request_worker_agent = []() { + auto worker_client = MUST(Web::HTML::WebWorkerClient::try_create()); + return worker_client->dup_sockets(); + }; } OutOfProcessWebView::~OutOfProcessWebView() = default; diff --git a/Userland/Libraries/LibWebView/SocketPair.cpp b/Userland/Libraries/LibWebView/SocketPair.cpp new file mode 100644 index 0000000000..d2600a0fb3 --- /dev/null +++ b/Userland/Libraries/LibWebView/SocketPair.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024, Andrew Kaster + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include + +template<> +ErrorOr IPC::encode(Encoder& encoder, WebView::SocketPair const& pair) +{ + TRY(encoder.encode(pair.socket)); + TRY(encoder.encode(pair.fd_passing_socket)); + return {}; +} + +template<> +ErrorOr IPC::decode(Decoder& decoder) +{ + auto socket = TRY(decoder.decode()); + auto fd_passing_socket = TRY(decoder.decode()); + + return WebView::SocketPair { move(socket), move(fd_passing_socket) }; +} diff --git a/Userland/Libraries/LibWebView/SocketPair.h b/Userland/Libraries/LibWebView/SocketPair.h new file mode 100644 index 0000000000..14aac2ebff --- /dev/null +++ b/Userland/Libraries/LibWebView/SocketPair.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024, Andrew Kaster + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace WebView { + +struct SocketPair { + IPC::File socket; + IPC::File fd_passing_socket; +}; + +} + +namespace IPC { + +template<> +ErrorOr encode(Encoder&, WebView::SocketPair const&); + +template<> +ErrorOr decode(Decoder&); + +} diff --git a/Userland/Libraries/LibWebView/ViewImplementation.h b/Userland/Libraries/LibWebView/ViewImplementation.h index 8eea56eac0..c50e480e29 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.h +++ b/Userland/Libraries/LibWebView/ViewImplementation.h @@ -177,6 +177,7 @@ public: Function const&)> on_inspector_replaced_dom_node_attribute; Function const&, Optional const&)> on_inspector_requested_dom_tree_context_menu; Function on_inspector_executed_console_script; + Function on_request_worker_agent; virtual Web::DevicePixelRect viewport_rect() const = 0; virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const = 0; diff --git a/Userland/Libraries/LibWebView/WebContentClient.cpp b/Userland/Libraries/LibWebView/WebContentClient.cpp index 0cee3a28be..6f033fa2fc 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.cpp +++ b/Userland/Libraries/LibWebView/WebContentClient.cpp @@ -478,4 +478,12 @@ void WebContentClient::inspector_did_execute_console_script(String const& script m_view.on_inspector_executed_console_script(script); } +Messages::WebContentClient::RequestWorkerAgentResponse WebContentClient::request_worker_agent() +{ + if (m_view.on_request_worker_agent) + return m_view.on_request_worker_agent(); + + return Messages::WebContentClient::RequestWorkerAgentResponse { WebView::SocketPair { -1, -1 } }; +} + } diff --git a/Userland/Libraries/LibWebView/WebContentClient.h b/Userland/Libraries/LibWebView/WebContentClient.h index 8edef728da..7aea70b724 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.h +++ b/Userland/Libraries/LibWebView/WebContentClient.h @@ -98,6 +98,7 @@ private: virtual void inspector_did_replace_dom_node_attribute(i32 node_id, String const& name, Vector const& replacement_attributes) override; virtual void inspector_did_request_dom_tree_context_menu(i32 node_id, Gfx::IntPoint position, String const& type, Optional const& tag, Optional const& attribute) override; virtual void inspector_did_execute_console_script(String const& script) override; + virtual Messages::WebContentClient::RequestWorkerAgentResponse request_worker_agent() override; ViewImplementation& m_view; }; diff --git a/Userland/Services/WebContent/PageClient.cpp b/Userland/Services/WebContent/PageClient.cpp index 7c1bf198b9..b15f9b4ec4 100644 --- a/Userland/Services/WebContent/PageClient.cpp +++ b/Userland/Services/WebContent/PageClient.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -561,6 +562,17 @@ void PageClient::page_did_insert_clipboard_entry(String data, String presentatio client().async_did_insert_clipboard_entry(move(data), move(presentation_style), move(mime_type)); } +WebView::SocketPair PageClient::request_worker_agent() +{ + auto response = client().send_sync_but_allow_failure(); + if (!response) { + dbgln("WebContent client disconnected during RequestWorkerAgent. Exiting peacefully."); + exit(0); + } + + return response->take_sockets(); +} + void PageClient::inspector_did_load() { client().async_inspector_did_load(); diff --git a/Userland/Services/WebContent/PageClient.h b/Userland/Services/WebContent/PageClient.h index e6d2350453..2c0589c353 100644 --- a/Userland/Services/WebContent/PageClient.h +++ b/Userland/Services/WebContent/PageClient.h @@ -128,6 +128,7 @@ private: virtual void page_did_finish_text_test() override; virtual void page_did_change_theme_color(Gfx::Color color) override; virtual void page_did_insert_clipboard_entry(String data, String presentation_style, String mime_type) override; + virtual WebView::SocketPair request_worker_agent() override; virtual void inspector_did_load() override; virtual void inspector_did_select_dom_node(i32 node_id, Optional const& pseudo_element) override; virtual void inspector_did_set_dom_node_text(i32 node_id, String const& text) override; diff --git a/Userland/Services/WebContent/WebContentClient.ipc b/Userland/Services/WebContent/WebContentClient.ipc index ea4cb5a482..1050f25e00 100644 --- a/Userland/Services/WebContent/WebContentClient.ipc +++ b/Userland/Services/WebContent/WebContentClient.ipc @@ -9,6 +9,7 @@ #include #include #include +#include endpoint WebContentClient { @@ -78,6 +79,8 @@ endpoint WebContentClient did_finish_text_test() =| + request_worker_agent() => (WebView::SocketPair sockets) // FIXME: Add required attributes to select a SharedWorker Agent + inspector_did_load() =| inspector_did_select_dom_node(i32 node_id, Optional pseudo_element) =| inspector_did_set_dom_node_text(i32 node_id, String text) =| diff --git a/Userland/Services/WebContent/main.cpp b/Userland/Services/WebContent/main.cpp index 4c42e971ed..6f793174f2 100644 --- a/Userland/Services/WebContent/main.cpp +++ b/Userland/Services/WebContent/main.cpp @@ -41,7 +41,6 @@ ErrorOr serenity_main(Main::Arguments) TRY(Core::System::unveil("/tmp/session/%sid/portal/request", "rw")); TRY(Core::System::unveil("/tmp/session/%sid/portal/image", "rw")); TRY(Core::System::unveil("/tmp/session/%sid/portal/websocket", "rw")); - TRY(Core::System::unveil("/tmp/session/%sid/portal/webworker", "rw")); TRY(Core::System::unveil(nullptr, nullptr)); Web::Platform::EventLoopPlugin::install(*new Web::Platform::EventLoopPluginSerenity); diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp index 051e18b449..88d1a5b579 100644 --- a/Userland/Utilities/headless-browser.cpp +++ b/Userland/Utilities/headless-browser.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -169,6 +170,15 @@ private: on_set_cookie = [this](auto const& url, auto const& cookie, auto source) { m_cookie_jar.set_cookie(url, cookie, source); }; + + on_request_worker_agent = []() { +#if defined(AK_OS_SERENITY) + auto worker_client = MUST(Web::HTML::WebWorkerClient::try_create()); +#else + auto worker_client = MUST(launch_web_worker_process(MUST(get_paths_for_helper_process("WebWorker"sv)))); +#endif + return worker_client->dup_sockets(); + }; } void update_zoom() override { }