1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:04:59 +00:00

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".
This commit is contained in:
Andrew Kaster 2024-01-06 13:13:59 -07:00 committed by Andrew Kaster
parent 6ea4c248ab
commit 02edd240ae
26 changed files with 152 additions and 99 deletions

View file

@ -8,6 +8,7 @@ set(SOURCES
InspectorClient.cpp
RequestServerAdapter.cpp
SearchEngine.cpp
SocketPair.cpp
SourceHighlighter.cpp
URL.cpp
UserAgent.cpp

View file

@ -21,6 +21,7 @@ class WebContentClient;
struct Attribute;
struct CookieStorageKey;
struct SearchEngine;
struct SocketPair;
}

View file

@ -17,6 +17,7 @@
#include <LibGfx/Palette.h>
#include <LibGfx/SystemTheme.h>
#include <LibWeb/Crypto/Crypto.h>
#include <LibWeb/Worker/WebWorkerClient.h>
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;

View file

@ -0,0 +1,26 @@
/*
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibIPC/Decoder.h>
#include <LibIPC/Encoder.h>
#include <LibWebView/SocketPair.h>
template<>
ErrorOr<void> IPC::encode(Encoder& encoder, WebView::SocketPair const& pair)
{
TRY(encoder.encode(pair.socket));
TRY(encoder.encode(pair.fd_passing_socket));
return {};
}
template<>
ErrorOr<WebView::SocketPair> IPC::decode(Decoder& decoder)
{
auto socket = TRY(decoder.decode<IPC::File>());
auto fd_passing_socket = TRY(decoder.decode<IPC::File>());
return WebView::SocketPair { move(socket), move(fd_passing_socket) };
}

View file

@ -0,0 +1,28 @@
/*
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibIPC/File.h>
namespace WebView {
struct SocketPair {
IPC::File socket;
IPC::File fd_passing_socket;
};
}
namespace IPC {
template<>
ErrorOr<void> encode(Encoder&, WebView::SocketPair const&);
template<>
ErrorOr<WebView::SocketPair> decode(Decoder&);
}

View file

@ -177,6 +177,7 @@ public:
Function<void(i32, String const&, Vector<Attribute> const&)> on_inspector_replaced_dom_node_attribute;
Function<void(i32, Gfx::IntPoint, String const&, Optional<String> const&, Optional<Attribute> const&)> on_inspector_requested_dom_tree_context_menu;
Function<void(String const&)> on_inspector_executed_console_script;
Function<SocketPair()> on_request_worker_agent;
virtual Web::DevicePixelRect viewport_rect() const = 0;
virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const = 0;

View file

@ -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 } };
}
}

View file

@ -98,6 +98,7 @@ private:
virtual void inspector_did_replace_dom_node_attribute(i32 node_id, String const& name, Vector<Attribute> const& replacement_attributes) override;
virtual void inspector_did_request_dom_tree_context_menu(i32 node_id, Gfx::IntPoint position, String const& type, Optional<String> const& tag, Optional<Attribute> 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;
};