From 5e1d678bae0d4b32f3010fa992abc691a52be30c Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Wed, 17 Apr 2024 18:44:39 -0600 Subject: [PATCH] Ladybird+Userland: Remove use of unnecessary fd passing socket concept Now that LibIPC is using SCM_RIGHTS properly, we can go back to only having one socket laying around when needing to transfer fds to peers. --- Ladybird/AppKit/Application/Application.h | 4 +- Ladybird/AppKit/Application/Application.mm | 2 +- .../AppKit/Application/ApplicationBridge.cpp | 8 +-- .../AppKit/Application/ApplicationBridge.h | 4 +- Ladybird/HelperProcess.cpp | 69 +++++-------------- Ladybird/HelperProcess.h | 5 +- Ladybird/ImageDecoder/main.cpp | 15 +--- Ladybird/Qt/WebContentView.cpp | 11 ++- Ladybird/RequestServer/main.cpp | 4 -- Ladybird/WebContent/main.cpp | 14 +--- Ladybird/WebWorker/main.cpp | 14 +--- .../Userland/Libraries/LibWebView/BUILD.gn | 1 - Userland/Libraries/LibIPC/Connection.h | 2 - .../Libraries/LibWeb/HTML/MessagePort.cpp | 16 ----- Userland/Libraries/LibWeb/HTML/MessagePort.h | 1 - .../Libraries/LibWeb/HTML/WorkerAgent.cpp | 7 +- Userland/Libraries/LibWeb/Page/Page.h | 3 +- .../LibWeb/Worker/WebWorkerClient.cpp | 7 +- .../Libraries/LibWeb/Worker/WebWorkerClient.h | 3 +- Userland/Libraries/LibWebView/CMakeLists.txt | 1 - Userland/Libraries/LibWebView/Forward.h | 1 - .../LibWebView/OutOfProcessWebView.cpp | 2 +- Userland/Libraries/LibWebView/SocketPair.cpp | 26 ------- Userland/Libraries/LibWebView/SocketPair.h | 28 -------- .../Libraries/LibWebView/ViewImplementation.h | 2 +- .../Libraries/LibWebView/WebContentClient.cpp | 2 +- .../RequestServer/ConnectionFromClient.cpp | 27 +------- .../Services/RequestServer/RequestServer.ipc | 2 +- Userland/Services/WebContent/PageClient.cpp | 5 +- Userland/Services/WebContent/PageClient.h | 2 +- .../Services/WebContent/WebContentClient.ipc | 3 +- Userland/Utilities/headless-browser.cpp | 6 +- 32 files changed, 61 insertions(+), 236 deletions(-) delete mode 100644 Userland/Libraries/LibWebView/SocketPair.cpp delete mode 100644 Userland/Libraries/LibWebView/SocketPair.h diff --git a/Ladybird/AppKit/Application/Application.h b/Ladybird/AppKit/Application/Application.h index dc4c561af5c..111eeb6997a 100644 --- a/Ladybird/AppKit/Application/Application.h +++ b/Ladybird/AppKit/Application/Application.h @@ -8,8 +8,8 @@ #include #include +#include #include -#include #import @@ -23,6 +23,6 @@ class WebViewBridge; - (ErrorOr)launchRequestServer:(Vector const&)certificates; - (ErrorOr>)launchWebContent:(Ladybird::WebViewBridge&)web_view_bridge; -- (ErrorOr)launchWebWorker; +- (ErrorOr)launchWebWorker; @end diff --git a/Ladybird/AppKit/Application/Application.mm b/Ladybird/AppKit/Application/Application.mm index 3682ed82a2c..3844759d1c8 100644 --- a/Ladybird/AppKit/Application/Application.mm +++ b/Ladybird/AppKit/Application/Application.mm @@ -45,7 +45,7 @@ return m_application_bridge->launch_web_content(web_view_bridge); } -- (ErrorOr)launchWebWorker +- (ErrorOr)launchWebWorker { return m_application_bridge->launch_web_worker(); } diff --git a/Ladybird/AppKit/Application/ApplicationBridge.cpp b/Ladybird/AppKit/Application/ApplicationBridge.cpp index d9f092ed3de..1b248692fd9 100644 --- a/Ladybird/AppKit/Application/ApplicationBridge.cpp +++ b/Ladybird/AppKit/Application/ApplicationBridge.cpp @@ -40,20 +40,20 @@ ErrorOr ApplicationBridge::launch_request_server(Vector const& ErrorOr> ApplicationBridge::launch_web_content(WebViewBridge& web_view_bridge) { // FIXME: Fail to open the tab, rather than crashing the whole application if this fails - auto request_server_sockets = TRY(connect_new_request_server_client(*m_impl->request_server_client)); + auto request_server_socket = TRY(connect_new_request_server_client(*m_impl->request_server_client)); auto web_content_paths = TRY(get_paths_for_helper_process("WebContent"sv)); - auto web_content = TRY(launch_web_content_process(web_view_bridge, web_content_paths, web_view_bridge.web_content_options(), move(request_server_sockets))); + auto web_content = TRY(launch_web_content_process(web_view_bridge, web_content_paths, web_view_bridge.web_content_options(), move(request_server_socket))); return web_content; } -ErrorOr ApplicationBridge::launch_web_worker() +ErrorOr ApplicationBridge::launch_web_worker() { auto web_worker_paths = TRY(get_paths_for_helper_process("WebWorker"sv)); auto worker_client = TRY(launch_web_worker_process(web_worker_paths, *m_impl->request_server_client)); - return worker_client->dup_sockets(); + return worker_client->dup_socket(); } } diff --git a/Ladybird/AppKit/Application/ApplicationBridge.h b/Ladybird/AppKit/Application/ApplicationBridge.h index 4ce44b0b5c4..7978343272c 100644 --- a/Ladybird/AppKit/Application/ApplicationBridge.h +++ b/Ladybird/AppKit/Application/ApplicationBridge.h @@ -8,8 +8,8 @@ #include #include +#include #include -#include namespace Ladybird { @@ -23,7 +23,7 @@ public: ErrorOr launch_request_server(Vector const& certificates); ErrorOr> launch_web_content(WebViewBridge&); - ErrorOr launch_web_worker(); + ErrorOr launch_web_worker(); private: NonnullOwnPtr m_impl; diff --git a/Ladybird/HelperProcess.cpp b/Ladybird/HelperProcess.cpp index 08cd69d9f94..a677e7aee73 100644 --- a/Ladybird/HelperProcess.cpp +++ b/Ladybird/HelperProcess.cpp @@ -13,7 +13,7 @@ ErrorOr> launch_web_content_process( WebView::ViewImplementation& view, ReadonlySpan candidate_web_content_paths, Ladybird::WebContentOptions const& web_content_options, - Optional request_server_sockets) + Optional request_server_socket) { int socket_fds[2] {}; TRY(Core::System::socketpair(AF_LOCAL, SOCK_STREAM, 0, socket_fds)); @@ -21,22 +21,13 @@ ErrorOr> launch_web_content_process( 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]; - auto child_pid = TRY(Core::System::fork()); if (child_pid == 0) { - TRY(Core::System::close(ui_fd_passing_fd)); TRY(Core::System::close(ui_fd)); auto takeover_string = TRY(String::formatted("WebContent:{}", wc_fd)); TRY(Core::Environment::set("SOCKET_TAKEOVER"sv, takeover_string, Core::Environment::Overwrite::Yes)); - auto webcontent_fd_passing_socket_string = TRY(String::number(wc_fd_passing_fd)); - ErrorOr result; for (auto const& path : candidate_web_content_paths) { constexpr auto callgrind_prefix_length = 3; @@ -53,8 +44,6 @@ ErrorOr> launch_web_content_process( web_content_options.command_line, "--executable-path"sv, web_content_options.executable_path, - "--webcontent-fd-passing-socket"sv, - webcontent_fd_passing_socket_string }; if (web_content_options.enable_callgrind_profiling == Ladybird::EnableCallgrindProfiling::No) arguments.remove(0, callgrind_prefix_length); @@ -74,14 +63,11 @@ ErrorOr> launch_web_content_process( arguments.append("--mach-server-name"sv); arguments.append(server.value()); } - Vector fd_strings; - if (request_server_sockets.has_value()) { + String fd_string; + if (request_server_socket.has_value()) { arguments.append("--request-server-socket"sv); - fd_strings.append(MUST(String::number(request_server_sockets->socket.fd()))); - arguments.append(fd_strings.last()); - arguments.append("--request-server-fd-passing-socket"sv); - fd_strings.append(MUST(String::number(request_server_sockets->fd_passing_socket.fd()))); - arguments.append(fd_strings.last()); + fd_string = MUST(String::number(request_server_socket->fd())); + arguments.append(fd_string.bytes_as_string_view()); } result = Core::System::exec(arguments[0], arguments.span(), Core::System::SearchInPath::Yes); @@ -94,14 +80,12 @@ ErrorOr> launch_web_content_process( 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) WebView::WebContentClient(move(socket), view))); - new_client->set_fd_passing_socket(TRY(Core::LocalSocket::adopt_fd(ui_fd_passing_fd))); if (web_content_options.enable_callgrind_profiling == Ladybird::EnableCallgrindProfiling::Yes) { dbgln(); @@ -122,22 +106,13 @@ ErrorOr> launch_generic_server_process(ReadonlySpan result; for (auto const& path : candidate_server_paths) { @@ -146,8 +121,6 @@ ErrorOr> launch_generic_server_process(ReadonlySpan { path.view(), - "--fd-passing-socket"sv, - fd_passing_socket_string, }; if (!extra_arguments.is_empty()) @@ -164,13 +137,11 @@ ErrorOr> launch_generic_server_process(ReadonlySpanset_blocking(true)); auto new_client = TRY(try_make_ref_counted(move(socket))); - new_client->set_fd_passing_socket(TRY(Core::LocalSocket::adopt_fd(ui_fd_passing_fd))); WebView::ProcessManager::the().add_process(WebView::process_type_from_name(server_name), child_pid); @@ -184,17 +155,13 @@ ErrorOr> launch_image_decoder_process( ErrorOr> launch_web_worker_process(ReadonlySpan candidate_web_worker_paths, NonnullRefPtr request_client) { - auto request_server_sockets = TRY(connect_new_request_server_client(move(request_client))); + auto socket = TRY(connect_new_request_server_client(move(request_client))); Vector arguments; - Vector fd_strings; + String fd_string = MUST(String::number(socket.fd())); arguments.append("--request-server-socket"sv); - fd_strings.append(MUST(String::number(request_server_sockets.socket.fd()))); - arguments.append(fd_strings.last()); - arguments.append("--request-server-fd-passing-socket"sv); - fd_strings.append(MUST(String::number(request_server_sockets.fd_passing_socket.fd()))); - arguments.append(fd_strings.last()); + arguments.append(fd_string.bytes_as_string_view()); return launch_generic_server_process(candidate_web_worker_paths, "WebWorker"sv, move(arguments)); } @@ -215,23 +182,21 @@ ErrorOr> launch_request_server_process(Re return launch_generic_server_process(candidate_request_server_paths, "RequestServer"sv, move(arguments)); } -ErrorOr connect_new_request_server_client(Protocol::RequestClient& client) +ErrorOr connect_new_request_server_client(Protocol::RequestClient& client) { - auto new_sockets = client.send_sync_but_allow_failure(); - if (!new_sockets) + auto new_socket = client.send_sync_but_allow_failure(); + if (!new_socket) return Error::from_string_literal("Failed to connect to RequestServer"); - auto socket = new_sockets->take_client_socket(); - auto fd_passing_socket = new_sockets->take_client_fd_passing_socket(); + auto socket = new_socket->take_client_socket(); // FIXME: IPC::Files transferred over the wire are always set O_CLOEXEC during decoding. // Perhaps we should add an option to IPC::File to allow the receiver to decide whether to // make it O_CLOEXEC or not. Or an attribute in the .ipc file? - for (auto fd : { socket.fd(), fd_passing_socket.fd() }) { - auto fd_flags = MUST(Core::System::fcntl(fd, F_GETFD)); - fd_flags &= ~FD_CLOEXEC; - MUST(Core::System::fcntl(fd, F_SETFD, fd_flags)); - } + auto fd = socket.fd(); + auto fd_flags = MUST(Core::System::fcntl(fd, F_GETFD)); + fd_flags &= ~FD_CLOEXEC; + MUST(Core::System::fcntl(fd, F_SETFD, fd_flags)); - return WebView::SocketPair { move(socket), move(fd_passing_socket) }; + return socket; } diff --git a/Ladybird/HelperProcess.h b/Ladybird/HelperProcess.h index 890d71ab5b9..bce225c9b48 100644 --- a/Ladybird/HelperProcess.h +++ b/Ladybird/HelperProcess.h @@ -14,7 +14,6 @@ #include #include #include -#include #include #include @@ -22,10 +21,10 @@ ErrorOr> launch_web_content_process( WebView::ViewImplementation& view, ReadonlySpan candidate_web_content_paths, Ladybird::WebContentOptions const&, - Optional request_server_sockets = {}); + Optional request_server_socket = {}); ErrorOr> launch_image_decoder_process(ReadonlySpan candidate_image_decoder_paths); ErrorOr> launch_web_worker_process(ReadonlySpan candidate_web_worker_paths, NonnullRefPtr); ErrorOr> launch_request_server_process(ReadonlySpan candidate_request_server_paths, StringView serenity_resource_root, Vector const& certificates); -ErrorOr connect_new_request_server_client(Protocol::RequestClient&); +ErrorOr connect_new_request_server_client(Protocol::RequestClient&); diff --git a/Ladybird/ImageDecoder/main.cpp b/Ladybird/ImageDecoder/main.cpp index b9288e995ca..5ccfb9314be 100644 --- a/Ladybird/ImageDecoder/main.cpp +++ b/Ladybird/ImageDecoder/main.cpp @@ -12,24 +12,13 @@ #include #include -ErrorOr serenity_main(Main::Arguments arguments) +ErrorOr serenity_main(Main::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); - Core::EventLoop event_loop; auto client = TRY(IPC::take_over_accepted_client_from_system_server()); - client->set_fd_passing_socket(TRY(Core::LocalSocket::adopt_fd(fd_passing_socket))); - auto result = event_loop.exec(); - - return result; + return event_loop.exec(); } diff --git a/Ladybird/Qt/WebContentView.cpp b/Ladybird/Qt/WebContentView.cpp index a007d8af45a..4dc69775406 100644 --- a/Ladybird/Qt/WebContentView.cpp +++ b/Ladybird/Qt/WebContentView.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -125,7 +124,7 @@ WebContentView::WebContentView(QWidget* window, WebContentOptions const& web_con on_request_worker_agent = []() { auto& request_server_client = static_cast(QApplication::instance())->request_server_client; auto worker_client = MUST(launch_web_worker_process(MUST(get_paths_for_helper_process("WebWorker"sv)), *request_server_client)); - return worker_client->dup_sockets(); + return worker_client->dup_socket(); }; } @@ -534,17 +533,17 @@ void WebContentView::initialize_client(WebView::ViewImplementation::CreateNewCli if (create_new_client == CreateNewClient::Yes) { m_client_state = {}; - Optional request_server_sockets; + Optional request_server_socket; if (m_web_content_options.use_lagom_networking == UseLagomNetworking::Yes) { auto& protocol = static_cast(QApplication::instance())->request_server_client; // FIXME: Fail to open the tab, rather than crashing the whole application if this fails - auto sockets = connect_new_request_server_client(*protocol).release_value_but_fixme_should_propagate_errors(); - request_server_sockets = AK::move(sockets); + auto socket = connect_new_request_server_client(*protocol).release_value_but_fixme_should_propagate_errors(); + request_server_socket = AK::move(socket); } auto candidate_web_content_paths = 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, m_web_content_options, AK::move(request_server_sockets)).release_value_but_fixme_should_propagate_errors(); + auto new_client = launch_web_content_process(*this, candidate_web_content_paths, m_web_content_options, AK::move(request_server_socket)).release_value_but_fixme_should_propagate_errors(); m_client_state.client = new_client; } else { diff --git a/Ladybird/RequestServer/main.cpp b/Ladybird/RequestServer/main.cpp index 0678a0e7bb8..48d28b2e55a 100644 --- a/Ladybird/RequestServer/main.cpp +++ b/Ladybird/RequestServer/main.cpp @@ -20,7 +20,6 @@ #include #include -// FIXME: Share b/w RequestServer and WebSocket ErrorOr find_certificates(StringView serenity_resource_root) { auto cert_path = ByteString::formatted("{}/ladybird/cacert.pem", serenity_resource_root); @@ -33,12 +32,10 @@ ErrorOr serenity_main(Main::Arguments arguments) { AK::set_rich_debug_enabled(true); - int fd_passing_socket { -1 }; StringView serenity_resource_root; Vector certificates; 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(certificates, "Path to a certificate file", "certificate", 'C', "certificate"); 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); @@ -56,7 +53,6 @@ ErrorOr serenity_main(Main::Arguments arguments) RequestServer::HttpsProtocol::install(); auto client = TRY(IPC::take_over_accepted_client_from_system_server()); - client->set_fd_passing_socket(TRY(Core::LocalSocket::adopt_fd(fd_passing_socket))); return event_loop.exec(); } diff --git a/Ladybird/WebContent/main.cpp b/Ladybird/WebContent/main.cpp index 77f5f45b642..6d6367bb232 100644 --- a/Ladybird/WebContent/main.cpp +++ b/Ladybird/WebContent/main.cpp @@ -51,7 +51,7 @@ static ErrorOr load_content_filters(); static ErrorOr load_autoplay_allowlist(); -static ErrorOr initialize_lagom_networking(int request_server_socket, int request_server_fd_passing_socket); +static ErrorOr initialize_lagom_networking(int request_server_socket); namespace JS { extern bool g_log_all_js_exceptions; @@ -92,9 +92,7 @@ ErrorOr serenity_main(Main::Arguments arguments) StringView executable_path {}; StringView mach_server_name {}; Vector certificates; - int webcontent_fd_passing_socket { -1 }; int request_server_socket { -1 }; - int request_server_fd_passing_socket { -1 }; bool is_layout_test_mode = false; bool use_lagom_networking = false; bool use_gpu_painting = false; @@ -105,9 +103,7 @@ ErrorOr serenity_main(Main::Arguments arguments) Core::ArgsParser args_parser; args_parser.add_option(command_line, "Chrome process command line", "command-line", 0, "command_line"); args_parser.add_option(executable_path, "Chrome process executable path", "executable-path", 0, "executable_path"); - args_parser.add_option(webcontent_fd_passing_socket, "File descriptor of the passing socket for the WebContent connection", "webcontent-fd-passing-socket", 'c', "webcontent_fd_passing_socket"); args_parser.add_option(request_server_socket, "File descriptor of the socket for the RequestServer connection", "request-server-socket", 'r', "request_server_socket"); - args_parser.add_option(request_server_fd_passing_socket, "File descriptor of the fd passing socket for the RequestServer connection", "request-server-fd-passing-socket", 'f', "request_server_fd_passing_socket"); args_parser.add_option(is_layout_test_mode, "Is layout test mode", "layout-test-mode", 0); args_parser.add_option(use_lagom_networking, "Enable Lagom servers for networking", "use-lagom-networking", 0); args_parser.add_option(use_gpu_painting, "Enable GPU painting", "use-gpu-painting", 0); @@ -139,12 +135,10 @@ ErrorOr serenity_main(Main::Arguments arguments) Web::ResourceLoader::initialize(Ladybird::RequestManagerQt::create()); else #endif - TRY(initialize_lagom_networking(request_server_socket, request_server_fd_passing_socket)); + TRY(initialize_lagom_networking(request_server_socket)); Web::HTML::Window::set_internals_object_exposed(is_layout_test_mode); - VERIFY(webcontent_fd_passing_socket >= 0); - Web::Platform::FontPlugin::install(*new Ladybird::FontPlugin(is_layout_test_mode)); TRY(Web::Bindings::initialize_main_thread_vm()); @@ -167,7 +161,6 @@ ErrorOr serenity_main(Main::Arguments arguments) auto webcontent_socket = TRY(Core::take_over_socket_from_system_server("WebContent"sv)); auto webcontent_client = TRY(WebContent::ConnectionFromClient::try_create(move(webcontent_socket))); - webcontent_client->set_fd_passing_socket(TRY(Core::LocalSocket::adopt_fd(webcontent_fd_passing_socket))); return event_loop.exec(); } @@ -220,13 +213,12 @@ static ErrorOr load_autoplay_allowlist() return {}; } -ErrorOr initialize_lagom_networking(int request_server_socket, int request_server_fd_passing_socket) +ErrorOr initialize_lagom_networking(int request_server_socket) { auto socket = TRY(Core::LocalSocket::adopt_fd(request_server_socket)); TRY(socket->set_blocking(true)); auto new_client = TRY(try_make_ref_counted(move(socket))); - new_client->set_fd_passing_socket(TRY(Core::LocalSocket::adopt_fd(request_server_fd_passing_socket))); Web::ResourceLoader::initialize(TRY(WebView::RequestServerAdapter::try_create(move(new_client)))); return {}; diff --git a/Ladybird/WebWorker/main.cpp b/Ladybird/WebWorker/main.cpp index 059bdc5e5c7..8b00164e6b8 100644 --- a/Ladybird/WebWorker/main.cpp +++ b/Ladybird/WebWorker/main.cpp @@ -26,21 +26,17 @@ #include #include -static ErrorOr initialize_lagom_networking(int request_server_socket, int request_server_fd_passing_socket); +static ErrorOr initialize_lagom_networking(int request_server_socket); ErrorOr serenity_main(Main::Arguments arguments) { AK::set_rich_debug_enabled(true); - int fd_passing_socket { -1 }; int request_server_socket { -1 }; - int request_server_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(request_server_socket, "File descriptor of the request server socket", "request-server-socket", 's', "request-server-socket"); - args_parser.add_option(request_server_fd_passing_socket, "File descriptor of the request server fd passing socket", "request-server-fd-passing-socket", 'f', "request-server-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); @@ -51,25 +47,21 @@ ErrorOr serenity_main(Main::Arguments arguments) Web::Platform::FontPlugin::install(*new Web::Platform::FontPluginSerenity); - TRY(initialize_lagom_networking(request_server_socket, request_server_fd_passing_socket)); - - VERIFY(fd_passing_socket >= 0); + TRY(initialize_lagom_networking(request_server_socket)); TRY(Web::Bindings::initialize_main_thread_vm()); auto client = TRY(IPC::take_over_accepted_client_from_system_server()); - client->set_fd_passing_socket(TRY(Core::LocalSocket::adopt_fd(fd_passing_socket))); return event_loop.exec(); } -static ErrorOr initialize_lagom_networking(int request_server_socket, int request_server_fd_passing_socket) +static ErrorOr initialize_lagom_networking(int request_server_socket) { auto socket = TRY(Core::LocalSocket::adopt_fd(request_server_socket)); TRY(socket->set_blocking(true)); auto new_client = TRY(try_make_ref_counted(move(socket))); - new_client->set_fd_passing_socket(TRY(Core::LocalSocket::adopt_fd(request_server_fd_passing_socket))); Web::ResourceLoader::initialize(TRY(WebView::RequestServerAdapter::try_create(move(new_client)))); diff --git a/Meta/gn/secondary/Userland/Libraries/LibWebView/BUILD.gn b/Meta/gn/secondary/Userland/Libraries/LibWebView/BUILD.gn index b777e7fb4ac..eb5c19647f4 100644 --- a/Meta/gn/secondary/Userland/Libraries/LibWebView/BUILD.gn +++ b/Meta/gn/secondary/Userland/Libraries/LibWebView/BUILD.gn @@ -125,7 +125,6 @@ shared_library("LibWebView") { "ProcessManager.cpp", "RequestServerAdapter.cpp", "SearchEngine.cpp", - "SocketPair.cpp", "SourceHighlighter.cpp", "URL.cpp", "UserAgent.cpp", diff --git a/Userland/Libraries/LibIPC/Connection.h b/Userland/Libraries/LibIPC/Connection.h index 6a7b3006ed3..1387a09b04b 100644 --- a/Userland/Libraries/LibIPC/Connection.h +++ b/Userland/Libraries/LibIPC/Connection.h @@ -40,7 +40,6 @@ class ConnectionBase : public Core::EventReceiver { public: virtual ~ConnectionBase() override = default; - void set_fd_passing_socket(NonnullOwnPtr) { } void set_deferred_invoker(NonnullOwnPtr); DeferredInvoker& deferred_invoker() { return *m_deferred_invoker; } @@ -51,7 +50,6 @@ public: virtual void die() { } Core::LocalSocket& socket() { return *m_socket; } - Core::LocalSocket const& fd_passing_socket() const { return *m_socket; } protected: explicit ConnectionBase(IPC::Stub&, NonnullOwnPtr, u32 local_endpoint_magic); diff --git a/Userland/Libraries/LibWeb/HTML/MessagePort.cpp b/Userland/Libraries/LibWeb/HTML/MessagePort.cpp index d2fae5f876e..4b050883956 100644 --- a/Userland/Libraries/LibWeb/HTML/MessagePort.cpp +++ b/Userland/Libraries/LibWeb/HTML/MessagePort.cpp @@ -83,11 +83,6 @@ WebIDL::ExceptionOr MessagePort::transfer_steps(HTML::TransferDataHolder& m_socket = nullptr; data_holder.fds.append(IPC::File::adopt_fd(fd)); data_holder.data.append(IPC_FILE_TAG); - - auto fd_passing_socket = MUST(m_fd_passing_socket->release_fd()); - m_fd_passing_socket = nullptr; - data_holder.fds.append(IPC::File::adopt_fd(fd_passing_socket)); - data_holder.data.append(IPC_FILE_TAG); } // 4. Otherwise, set dataHolder.[[RemotePort]] to null. @@ -114,11 +109,6 @@ WebIDL::ExceptionOr MessagePort::transfer_receiving_steps(HTML::TransferDa auto fd = data_holder.fds.take_first(); m_socket = MUST(Core::LocalSocket::adopt_fd(fd.take_fd())); - fd_tag = data_holder.data.take_first(); - VERIFY(fd_tag == IPC_FILE_TAG); - fd = data_holder.fds.take_first(); - m_fd_passing_socket = MUST(Core::LocalSocket::adopt_fd(fd.take_fd())); - m_socket->on_ready_to_read = [strong_this = JS::make_handle(this)]() { strong_this->read_from_socket(); }; @@ -137,7 +127,6 @@ void MessagePort::disentangle() m_remote_port = nullptr; m_socket = nullptr; - m_fd_passing_socket = nullptr; } // https://html.spec.whatwg.org/multipage/web-messaging.html#entangle @@ -181,10 +170,6 @@ void MessagePort::entangle_with(MessagePort& remote_port) m_remote_port->m_socket->on_ready_to_read = [remote_port = JS::make_handle(m_remote_port)]() { remote_port->read_from_socket(); }; - - auto fd_sockets = create_paired_sockets(); - m_fd_passing_socket = move(fd_sockets[0]); - m_remote_port->m_fd_passing_socket = move(fd_sockets[1]); } // https://html.spec.whatwg.org/multipage/web-messaging.html#dom-messageport-postmessage-options @@ -408,7 +393,6 @@ void MessagePort::start() return; VERIFY(m_socket); - VERIFY(m_fd_passing_socket); // TODO: The start() method steps are to enable this's port message queue, if it is not already enabled. } diff --git a/Userland/Libraries/LibWeb/HTML/MessagePort.h b/Userland/Libraries/LibWeb/HTML/MessagePort.h index ccbe35a8fe8..2a2d721bfeb 100644 --- a/Userland/Libraries/LibWeb/HTML/MessagePort.h +++ b/Userland/Libraries/LibWeb/HTML/MessagePort.h @@ -91,7 +91,6 @@ private: bool m_has_been_shipped { false }; OwnPtr m_socket; - OwnPtr m_fd_passing_socket; enum class SocketState : u8 { Header, diff --git a/Userland/Libraries/LibWeb/HTML/WorkerAgent.cpp b/Userland/Libraries/LibWeb/HTML/WorkerAgent.cpp index 2b8914bf4ee..c50acc54645 100644 --- a/Userland/Libraries/LibWeb/HTML/WorkerAgent.cpp +++ b/Userland/Libraries/LibWeb/HTML/WorkerAgent.cpp @@ -33,14 +33,11 @@ void WorkerAgent::initialize(JS::Realm& realm) // 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())); + auto worker_socket_file = Bindings::host_defined_page(realm).client().request_worker_agent(); + auto worker_socket = MUST(Core::LocalSocket::adopt_fd(worker_socket_file.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), m_outside_settings->serialize()); } diff --git a/Userland/Libraries/LibWeb/Page/Page.h b/Userland/Libraries/LibWeb/Page/Page.h index 8df6cdd40a8..340c977ad48 100644 --- a/Userland/Libraries/LibWeb/Page/Page.h +++ b/Userland/Libraries/LibWeb/Page/Page.h @@ -38,7 +38,6 @@ #include #include #include -#include namespace Web { @@ -315,7 +314,7 @@ public: virtual void page_did_change_audio_play_state(HTML::AudioPlayState) { } - virtual WebView::SocketPair request_worker_agent() { return { IPC::File {}, IPC::File {} }; } + virtual IPC::File request_worker_agent() { return IPC::File {}; } virtual void inspector_did_load() { } virtual void inspector_did_select_dom_node([[maybe_unused]] i32 node_id, [[maybe_unused]] Optional const& pseudo_element) { } diff --git a/Userland/Libraries/LibWeb/Worker/WebWorkerClient.cpp b/Userland/Libraries/LibWeb/Worker/WebWorkerClient.cpp index 943b23c140b..9c71247becf 100644 --- a/Userland/Libraries/LibWeb/Worker/WebWorkerClient.cpp +++ b/Userland/Libraries/LibWeb/Worker/WebWorkerClient.cpp @@ -19,12 +19,9 @@ WebWorkerClient::WebWorkerClient(NonnullOwnPtr socket) { } -WebView::SocketPair WebWorkerClient::dup_sockets() +IPC::File WebWorkerClient::dup_socket() { - WebView::SocketPair pair; - pair.socket = MUST(IPC::File::clone_fd(socket().fd().value())); - pair.fd_passing_socket = MUST(IPC::File::clone_fd(fd_passing_socket().fd().value())); - return pair; + return MUST(IPC::File::clone_fd(socket().fd().value())); } } diff --git a/Userland/Libraries/LibWeb/Worker/WebWorkerClient.h b/Userland/Libraries/LibWeb/Worker/WebWorkerClient.h index 5d3f51e917d..1e7b675fa50 100644 --- a/Userland/Libraries/LibWeb/Worker/WebWorkerClient.h +++ b/Userland/Libraries/LibWeb/Worker/WebWorkerClient.h @@ -10,7 +10,6 @@ #include #include #include -#include namespace Web::HTML { @@ -22,7 +21,7 @@ class WebWorkerClient final public: explicit WebWorkerClient(NonnullOwnPtr); - WebView::SocketPair dup_sockets(); + IPC::File dup_socket(); private: virtual void die() override; diff --git a/Userland/Libraries/LibWebView/CMakeLists.txt b/Userland/Libraries/LibWebView/CMakeLists.txt index 2c6b9428b3e..1c0a1424fbf 100644 --- a/Userland/Libraries/LibWebView/CMakeLists.txt +++ b/Userland/Libraries/LibWebView/CMakeLists.txt @@ -9,7 +9,6 @@ set(SOURCES ProcessManager.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 713323a1d50..d6fd5519128 100644 --- a/Userland/Libraries/LibWebView/Forward.h +++ b/Userland/Libraries/LibWebView/Forward.h @@ -22,7 +22,6 @@ struct Attribute; struct CookieStorageKey; struct ProcessHandle; struct SearchEngine; -struct SocketPair; } diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp index a2c1ab518c2..b297676dc6a 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp @@ -75,7 +75,7 @@ OutOfProcessWebView::OutOfProcessWebView() on_request_worker_agent = []() { auto worker_client = MUST(Web::HTML::WebWorkerClient::try_create()); - return worker_client->dup_sockets(); + return worker_client->dup_socket(); }; } diff --git a/Userland/Libraries/LibWebView/SocketPair.cpp b/Userland/Libraries/LibWebView/SocketPair.cpp deleted file mode 100644 index d2600a0fb30..00000000000 --- a/Userland/Libraries/LibWebView/SocketPair.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 deleted file mode 100644 index 14aac2ebffd..00000000000 --- a/Userland/Libraries/LibWebView/SocketPair.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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 202addee055..7eddf695468 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.h +++ b/Userland/Libraries/LibWebView/ViewImplementation.h @@ -200,7 +200,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; + 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 609eb9d2c2c..5d91e516b2a 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.cpp +++ b/Userland/Libraries/LibWebView/WebContentClient.cpp @@ -665,7 +665,7 @@ Messages::WebContentClient::RequestWorkerAgentResponse WebContentClient::request return view->on_request_worker_agent(); } - return WebView::SocketPair { IPC::File {}, IPC::File {} }; + return IPC::File {}; } Optional WebContentClient::view_for_page_id(u64 page_id, SourceLocation location) diff --git a/Userland/Services/RequestServer/ConnectionFromClient.cpp b/Userland/Services/RequestServer/ConnectionFromClient.cpp index ca01cd995bb..013147ef16e 100644 --- a/Userland/Services/RequestServer/ConnectionFromClient.cpp +++ b/Userland/Services/RequestServer/ConnectionFromClient.cpp @@ -42,12 +42,10 @@ void ConnectionFromClient::die() Messages::RequestServer::ConnectNewClientResponse ConnectionFromClient::connect_new_client() { - Messages::RequestServer::ConnectNewClientResponse error_response = { IPC::File {}, IPC::File {} }; - int socket_fds[2] {}; if (auto err = Core::System::socketpair(AF_LOCAL, SOCK_STREAM, 0, socket_fds); err.is_error()) { dbgln("Failed to create client socketpair: {}", err.error()); - return error_response; + return IPC::File {}; } auto client_socket_or_error = Core::LocalSocket::adopt_fd(socket_fds[0]); @@ -55,32 +53,13 @@ Messages::RequestServer::ConnectNewClientResponse ConnectionFromClient::connect_ close(socket_fds[0]); close(socket_fds[1]); dbgln("Failed to adopt client socket: {}", client_socket_or_error.error()); - return error_response; + return IPC::File {}; } auto client_socket = client_socket_or_error.release_value(); // Note: A ref is stored in the static s_connections map auto client = adopt_ref(*new ConnectionFromClient(move(client_socket))); - int fd_passing_socket_fds[2] {}; - if (auto err = Core::System::socketpair(AF_LOCAL, SOCK_STREAM, 0, fd_passing_socket_fds); err.is_error()) { - close(socket_fds[1]); - dbgln("Failed to create fd-passing socketpair: {}", err.error()); - return error_response; - } - - auto fd_passing_socket_or_error = Core::LocalSocket::adopt_fd(fd_passing_socket_fds[0]); - if (fd_passing_socket_or_error.is_error()) { - // socket_fds[0] is already owned by client - close(socket_fds[1]); - close(fd_passing_socket_fds[0]); - close(fd_passing_socket_fds[1]); - dbgln("Failed to adopt fd-passing socket: {}", fd_passing_socket_or_error.error()); - return error_response; - } - auto fd_passing_socket = fd_passing_socket_or_error.release_value(); - client->set_fd_passing_socket(move(fd_passing_socket)); - - return { IPC::File::adopt_fd(socket_fds[1]), IPC::File::adopt_fd(fd_passing_socket_fds[1]) }; + return IPC::File::adopt_fd(socket_fds[1]); } Messages::RequestServer::IsSupportedProtocolResponse ConnectionFromClient::is_supported_protocol(ByteString const& protocol) diff --git a/Userland/Services/RequestServer/RequestServer.ipc b/Userland/Services/RequestServer/RequestServer.ipc index 35d0fb97c4a..7e48d81b21e 100644 --- a/Userland/Services/RequestServer/RequestServer.ipc +++ b/Userland/Services/RequestServer/RequestServer.ipc @@ -3,7 +3,7 @@ endpoint RequestServer { - connect_new_client() => (IPC::File client_socket, IPC::File client_fd_passing_socket) + connect_new_client() => (IPC::File client_socket) // Test if a specific protocol is supported, e.g "http" is_supported_protocol(ByteString protocol) => (bool supported) diff --git a/Userland/Services/WebContent/PageClient.cpp b/Userland/Services/WebContent/PageClient.cpp index 702a3d8b6c6..eea014edad6 100644 --- a/Userland/Services/WebContent/PageClient.cpp +++ b/Userland/Services/WebContent/PageClient.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -601,7 +600,7 @@ void PageClient::page_did_change_audio_play_state(Web::HTML::AudioPlayState play client().async_did_change_audio_play_state(m_id, play_state); } -WebView::SocketPair PageClient::request_worker_agent() +IPC::File PageClient::request_worker_agent() { auto response = client().send_sync_but_allow_failure(m_id); if (!response) { @@ -609,7 +608,7 @@ WebView::SocketPair PageClient::request_worker_agent() exit(0); } - return response->take_sockets(); + return response->take_socket(); } void PageClient::inspector_did_load() diff --git a/Userland/Services/WebContent/PageClient.h b/Userland/Services/WebContent/PageClient.h index 015a709dafe..dda5f8cd6f9 100644 --- a/Userland/Services/WebContent/PageClient.h +++ b/Userland/Services/WebContent/PageClient.h @@ -146,7 +146,7 @@ private: 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 void page_did_change_audio_play_state(Web::HTML::AudioPlayState) override; - virtual WebView::SocketPair request_worker_agent() override; + virtual IPC::File 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 2091772da8b..5684efa2158 100644 --- a/Userland/Services/WebContent/WebContentClient.ipc +++ b/Userland/Services/WebContent/WebContentClient.ipc @@ -13,7 +13,6 @@ #include #include #include -#include #include endpoint WebContentClient @@ -91,7 +90,7 @@ endpoint WebContentClient did_finish_text_test(u64 page_id) =| - request_worker_agent(u64 page_id) => (WebView::SocketPair sockets) // FIXME: Add required attributes to select a SharedWorker Agent + request_worker_agent(u64 page_id) => (IPC::File socket) // FIXME: Add required attributes to select a SharedWorker Agent inspector_did_load(u64 page_id) =| inspector_did_select_dom_node(u64 page_id, i32 node_id, Optional pseudo_element) =| diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp index 66ef637b334..5212a00a6be 100644 --- a/Userland/Utilities/headless-browser.cpp +++ b/Userland/Utilities/headless-browser.cpp @@ -96,10 +96,10 @@ public: .is_layout_test_mode = is_layout_test_mode, }; - auto request_server_sockets = TRY(connect_new_request_server_client(*request_client)); + auto request_server_socket = TRY(connect_new_request_server_client(*request_client)); auto candidate_web_content_paths = TRY(get_paths_for_helper_process("WebContent"sv)); - view->m_client_state.client = TRY(launch_web_content_process(*view, candidate_web_content_paths, web_content_options, move(request_server_sockets))); + view->m_client_state.client = TRY(launch_web_content_process(*view, candidate_web_content_paths, web_content_options, move(request_server_socket))); #endif view->client().async_update_system_theme(0, move(theme)); @@ -196,7 +196,7 @@ private: #else auto worker_client = MUST(launch_web_worker_process(MUST(get_paths_for_helper_process("WebWorker"sv)), *m_request_client)); #endif - return worker_client->dup_sockets(); + return worker_client->dup_socket(); }; }