mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
Ladybird+headless-browser: Make RequestServer single instance on Lagom
Co-Authored-By: Timothy Flynn <trflynn89@pm.me>
This commit is contained in:
parent
336b661835
commit
c87e32154a
Notes:
sideshowbarker
2024-07-17 03:30:41 +09:00
Author: https://github.com/ADKaster
Commit: c87e32154a
Pull-request: https://github.com/SerenityOS/serenity/pull/23945
Reviewed-by: https://github.com/trflynn89 ✅
20 changed files with 308 additions and 75 deletions
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <Ladybird/FontPlugin.h>
|
||||
#include <Ladybird/HelperProcess.h>
|
||||
#include <Ladybird/ImageCodecPlugin.h>
|
||||
#include <Ladybird/Utilities.h>
|
||||
#include <LibAudio/Loader.h>
|
||||
|
|
@ -20,6 +19,7 @@
|
|||
#include <LibIPC/ConnectionFromClient.h>
|
||||
#include <LibJS/Bytecode/Interpreter.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <LibProtocol/RequestClient.h>
|
||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/Loader/ContentFilter.h>
|
||||
|
|
@ -51,7 +51,7 @@
|
|||
|
||||
static ErrorOr<void> load_content_filters();
|
||||
static ErrorOr<void> load_autoplay_allowlist();
|
||||
static ErrorOr<void> initialize_lagom_networking(Vector<ByteString> const& certificates);
|
||||
static ErrorOr<void> initialize_lagom_networking(int request_server_socket, int request_server_fd_passing_socket);
|
||||
|
||||
namespace JS {
|
||||
extern bool g_log_all_js_exceptions;
|
||||
|
|
@ -93,6 +93,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
StringView mach_server_name {};
|
||||
Vector<ByteString> 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;
|
||||
|
|
@ -103,8 +105,9 @@ ErrorOr<int> 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(certificates, "Path to a certificate file", "certificate", 'C', "certificate");
|
||||
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);
|
||||
|
|
@ -136,7 +139,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
Web::ResourceLoader::initialize(Ladybird::RequestManagerQt::create());
|
||||
else
|
||||
#endif
|
||||
TRY(initialize_lagom_networking(certificates));
|
||||
TRY(initialize_lagom_networking(request_server_socket, request_server_fd_passing_socket));
|
||||
|
||||
Web::HTML::Window::set_internals_object_exposed(is_layout_test_mode);
|
||||
|
||||
|
|
@ -217,11 +220,14 @@ static ErrorOr<void> load_autoplay_allowlist()
|
|||
return {};
|
||||
}
|
||||
|
||||
static ErrorOr<void> initialize_lagom_networking(Vector<ByteString> const& certificates)
|
||||
ErrorOr<void> initialize_lagom_networking(int request_server_socket, int request_server_fd_passing_socket)
|
||||
{
|
||||
auto candidate_request_server_paths = TRY(get_paths_for_helper_process("RequestServer"sv));
|
||||
auto request_server_client = TRY(launch_request_server_process(candidate_request_server_paths, s_serenity_resource_root, certificates));
|
||||
Web::ResourceLoader::initialize(TRY(WebView::RequestServerAdapter::try_create(move(request_server_client))));
|
||||
auto socket = TRY(Core::LocalSocket::adopt_fd(request_server_socket));
|
||||
TRY(socket->set_blocking(true));
|
||||
|
||||
auto new_client = TRY(try_make_ref_counted<Protocol::RequestClient>(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 {};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue