mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 21:29:06 +00:00
LibWebView+UI: Move ownership of application services to LibWebView
LibWebView now knows how to launch RequestServer and ImageDecoderServer without help from the UI, so let's move ownership of these services over to LibWebView for de-duplication.
This commit is contained in:
parent
1b38ebcc7f
commit
bb7dff7dfe
Notes:
github-actions[bot]
2024-11-14 10:48:40 +00:00
Author: https://github.com/trflynn89
Commit: bb7dff7dfe
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2327
17 changed files with 99 additions and 188 deletions
|
@ -15,8 +15,10 @@
|
|||
#include <LibWebView/Application.h>
|
||||
#include <LibWebView/CookieJar.h>
|
||||
#include <LibWebView/Database.h>
|
||||
#include <LibWebView/HelperProcess.h>
|
||||
#include <LibWebView/URL.h>
|
||||
#include <LibWebView/UserAgent.h>
|
||||
#include <LibWebView/Utilities.h>
|
||||
#include <LibWebView/WebContentClient.h>
|
||||
|
||||
namespace WebView {
|
||||
|
@ -168,6 +170,51 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_
|
|||
}
|
||||
}
|
||||
|
||||
ErrorOr<void> Application::launch_services()
|
||||
{
|
||||
TRY(launch_request_server());
|
||||
TRY(launch_image_decoder_server());
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> 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));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> 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->on_death = [this]() {
|
||||
m_image_decoder_client = nullptr;
|
||||
|
||||
if (auto result = launch_image_decoder_server(); result.is_error()) {
|
||||
dbgln("Failed to restart image decoder: {}", result.error());
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
auto client_count = WebContentClient::client_count();
|
||||
auto new_sockets = m_image_decoder_client->send_sync_but_allow_failure<Messages::ImageDecoderServer::ConnectNewClients>(client_count);
|
||||
if (!new_sockets || new_sockets->sockets().is_empty()) {
|
||||
dbgln("Failed to connect {} new clients to ImageDecoder", client_count);
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
WebContentClient::for_each_client([sockets = new_sockets->take_sockets()](WebContentClient& client) mutable {
|
||||
client.async_connect_to_image_decoder(sockets.take_last());
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
};
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
int Application::execute()
|
||||
{
|
||||
int ret = m_event_loop.exec();
|
||||
|
|
|
@ -13,7 +13,9 @@
|
|||
#include <AK/Swift.h>
|
||||
#include <LibCore/EventLoop.h>
|
||||
#include <LibCore/Forward.h>
|
||||
#include <LibImageDecoderClient/Client.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <LibRequests/RequestClient.h>
|
||||
#include <LibURL/URL.h>
|
||||
#include <LibWebView/Options.h>
|
||||
#include <LibWebView/Process.h>
|
||||
|
@ -34,10 +36,15 @@ public:
|
|||
static ChromeOptions const& chrome_options() { return the().m_chrome_options; }
|
||||
static WebContentOptions const& web_content_options() { return the().m_web_content_options; }
|
||||
|
||||
static Requests::RequestClient& request_server_client() { return *the().m_request_server_client; }
|
||||
static ImageDecoderClient::Client& image_decoder_client() { return *the().m_image_decoder_client; }
|
||||
|
||||
static CookieJar& cookie_jar() { return *the().m_cookie_jar; }
|
||||
|
||||
Core::EventLoop& event_loop() { return m_event_loop; }
|
||||
|
||||
ErrorOr<void> launch_services();
|
||||
|
||||
void add_child_process(Process&&);
|
||||
|
||||
// FIXME: Should these methods be part of Application, instead of deferring to ProcessManager?
|
||||
|
@ -74,11 +81,17 @@ protected:
|
|||
private:
|
||||
void initialize(Main::Arguments const& arguments, URL::URL new_tab_page_url);
|
||||
|
||||
ErrorOr<void> launch_request_server();
|
||||
ErrorOr<void> launch_image_decoder_server();
|
||||
|
||||
static Application* s_the;
|
||||
|
||||
ChromeOptions m_chrome_options;
|
||||
WebContentOptions m_web_content_options;
|
||||
|
||||
RefPtr<Requests::RequestClient> m_request_server_client;
|
||||
RefPtr<ImageDecoderClient::Client> m_image_decoder_client;
|
||||
|
||||
RefPtr<Database> m_database;
|
||||
OwnPtr<CookieJar> m_cookie_jar;
|
||||
|
||||
|
|
|
@ -135,24 +135,24 @@ ErrorOr<NonnullRefPtr<ImageDecoderClient::Client>> launch_image_decoder_process(
|
|||
return launch_server_process<ImageDecoderClient::Client>("ImageDecoder"sv, candidate_image_decoder_paths, arguments);
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<Web::HTML::WebWorkerClient>> launch_web_worker_process(ReadonlySpan<ByteString> candidate_web_worker_paths, NonnullRefPtr<Requests::RequestClient> request_client)
|
||||
ErrorOr<NonnullRefPtr<Web::HTML::WebWorkerClient>> launch_web_worker_process(ReadonlySpan<ByteString> candidate_web_worker_paths)
|
||||
{
|
||||
Vector<ByteString> arguments;
|
||||
|
||||
auto socket = TRY(connect_new_request_server_client(*request_client));
|
||||
auto socket = TRY(connect_new_request_server_client());
|
||||
arguments.append("--request-server-socket"sv);
|
||||
arguments.append(ByteString::number(socket.fd()));
|
||||
|
||||
return launch_server_process<Web::HTML::WebWorkerClient>("WebWorker"sv, candidate_web_worker_paths, move(arguments));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<Requests::RequestClient>> launch_request_server_process(ReadonlySpan<ByteString> candidate_request_server_paths, StringView serenity_resource_root)
|
||||
ErrorOr<NonnullRefPtr<Requests::RequestClient>> launch_request_server_process(ReadonlySpan<ByteString> candidate_request_server_paths)
|
||||
{
|
||||
Vector<ByteString> arguments;
|
||||
|
||||
if (!serenity_resource_root.is_empty()) {
|
||||
if (!s_ladybird_resource_root.is_empty()) {
|
||||
arguments.append("--serenity-resource-root"sv);
|
||||
arguments.append(serenity_resource_root);
|
||||
arguments.append(s_ladybird_resource_root);
|
||||
}
|
||||
|
||||
for (auto const& certificate : WebView::Application::chrome_options().certificates)
|
||||
|
@ -166,9 +166,9 @@ ErrorOr<NonnullRefPtr<Requests::RequestClient>> launch_request_server_process(Re
|
|||
return launch_server_process<Requests::RequestClient>("RequestServer"sv, candidate_request_server_paths, move(arguments));
|
||||
}
|
||||
|
||||
ErrorOr<IPC::File> connect_new_request_server_client(Requests::RequestClient& client)
|
||||
ErrorOr<IPC::File> connect_new_request_server_client()
|
||||
{
|
||||
auto new_socket = client.send_sync_but_allow_failure<Messages::RequestServer::ConnectNewClient>();
|
||||
auto new_socket = Application::request_server_client().send_sync_but_allow_failure<Messages::RequestServer::ConnectNewClient>();
|
||||
if (!new_socket)
|
||||
return Error::from_string_literal("Failed to connect to RequestServer");
|
||||
|
||||
|
@ -178,9 +178,9 @@ ErrorOr<IPC::File> connect_new_request_server_client(Requests::RequestClient& cl
|
|||
return socket;
|
||||
}
|
||||
|
||||
ErrorOr<IPC::File> connect_new_image_decoder_client(ImageDecoderClient::Client& client)
|
||||
ErrorOr<IPC::File> connect_new_image_decoder_client()
|
||||
{
|
||||
auto new_socket = client.send_sync_but_allow_failure<Messages::ImageDecoderServer::ConnectNewClients>(1);
|
||||
auto new_socket = Application::image_decoder_client().send_sync_but_allow_failure<Messages::ImageDecoderServer::ConnectNewClients>(1);
|
||||
if (!new_socket)
|
||||
return Error::from_string_literal("Failed to connect to ImageDecoder");
|
||||
|
||||
|
|
|
@ -25,10 +25,10 @@ ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(
|
|||
Optional<IPC::File> request_server_socket = {});
|
||||
|
||||
ErrorOr<NonnullRefPtr<ImageDecoderClient::Client>> launch_image_decoder_process(ReadonlySpan<ByteString> candidate_image_decoder_paths);
|
||||
ErrorOr<NonnullRefPtr<Web::HTML::WebWorkerClient>> launch_web_worker_process(ReadonlySpan<ByteString> candidate_web_worker_paths, NonnullRefPtr<Requests::RequestClient>);
|
||||
ErrorOr<NonnullRefPtr<Requests::RequestClient>> launch_request_server_process(ReadonlySpan<ByteString> candidate_request_server_paths, StringView serenity_resource_root);
|
||||
ErrorOr<NonnullRefPtr<Web::HTML::WebWorkerClient>> launch_web_worker_process(ReadonlySpan<ByteString> candidate_web_worker_paths);
|
||||
ErrorOr<NonnullRefPtr<Requests::RequestClient>> launch_request_server_process(ReadonlySpan<ByteString> candidate_request_server_paths);
|
||||
|
||||
ErrorOr<IPC::File> connect_new_request_server_client(Requests::RequestClient&);
|
||||
ErrorOr<IPC::File> connect_new_image_decoder_client(ImageDecoderClient::Client&);
|
||||
ErrorOr<IPC::File> connect_new_request_server_client();
|
||||
ErrorOr<IPC::File> connect_new_image_decoder_client();
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue