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:
Timothy Flynn 2024-11-13 15:33:02 -05:00 committed by Andreas Kling
parent 1b38ebcc7f
commit bb7dff7dfe
Notes: github-actions[bot] 2024-11-14 10:48:40 +00:00
17 changed files with 99 additions and 188 deletions

View file

@ -15,8 +15,10 @@
#include <LibWebView/Application.h> #include <LibWebView/Application.h>
#include <LibWebView/CookieJar.h> #include <LibWebView/CookieJar.h>
#include <LibWebView/Database.h> #include <LibWebView/Database.h>
#include <LibWebView/HelperProcess.h>
#include <LibWebView/URL.h> #include <LibWebView/URL.h>
#include <LibWebView/UserAgent.h> #include <LibWebView/UserAgent.h>
#include <LibWebView/Utilities.h>
#include <LibWebView/WebContentClient.h> #include <LibWebView/WebContentClient.h>
namespace WebView { 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 Application::execute()
{ {
int ret = m_event_loop.exec(); int ret = m_event_loop.exec();

View file

@ -13,7 +13,9 @@
#include <AK/Swift.h> #include <AK/Swift.h>
#include <LibCore/EventLoop.h> #include <LibCore/EventLoop.h>
#include <LibCore/Forward.h> #include <LibCore/Forward.h>
#include <LibImageDecoderClient/Client.h>
#include <LibMain/Main.h> #include <LibMain/Main.h>
#include <LibRequests/RequestClient.h>
#include <LibURL/URL.h> #include <LibURL/URL.h>
#include <LibWebView/Options.h> #include <LibWebView/Options.h>
#include <LibWebView/Process.h> #include <LibWebView/Process.h>
@ -34,10 +36,15 @@ public:
static ChromeOptions const& chrome_options() { return the().m_chrome_options; } static ChromeOptions const& chrome_options() { return the().m_chrome_options; }
static WebContentOptions const& web_content_options() { return the().m_web_content_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; } static CookieJar& cookie_jar() { return *the().m_cookie_jar; }
Core::EventLoop& event_loop() { return m_event_loop; } Core::EventLoop& event_loop() { return m_event_loop; }
ErrorOr<void> launch_services();
void add_child_process(Process&&); void add_child_process(Process&&);
// FIXME: Should these methods be part of Application, instead of deferring to ProcessManager? // FIXME: Should these methods be part of Application, instead of deferring to ProcessManager?
@ -74,11 +81,17 @@ protected:
private: private:
void initialize(Main::Arguments const& arguments, URL::URL new_tab_page_url); 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; static Application* s_the;
ChromeOptions m_chrome_options; ChromeOptions m_chrome_options;
WebContentOptions m_web_content_options; WebContentOptions m_web_content_options;
RefPtr<Requests::RequestClient> m_request_server_client;
RefPtr<ImageDecoderClient::Client> m_image_decoder_client;
RefPtr<Database> m_database; RefPtr<Database> m_database;
OwnPtr<CookieJar> m_cookie_jar; OwnPtr<CookieJar> m_cookie_jar;

View file

@ -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); 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; 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("--request-server-socket"sv);
arguments.append(ByteString::number(socket.fd())); arguments.append(ByteString::number(socket.fd()));
return launch_server_process<Web::HTML::WebWorkerClient>("WebWorker"sv, candidate_web_worker_paths, move(arguments)); 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; 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"sv);
arguments.append(serenity_resource_root); arguments.append(s_ladybird_resource_root);
} }
for (auto const& certificate : WebView::Application::chrome_options().certificates) 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)); 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) if (!new_socket)
return Error::from_string_literal("Failed to connect to RequestServer"); 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; 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) if (!new_socket)
return Error::from_string_literal("Failed to connect to ImageDecoder"); return Error::from_string_literal("Failed to connect to ImageDecoder");

View file

@ -25,10 +25,10 @@ ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(
Optional<IPC::File> request_server_socket = {}); Optional<IPC::File> request_server_socket = {});
ErrorOr<NonnullRefPtr<ImageDecoderClient::Client>> launch_image_decoder_process(ReadonlySpan<ByteString> candidate_image_decoder_paths); 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<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, StringView serenity_resource_root); 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_request_server_client();
ErrorOr<IPC::File> connect_new_image_decoder_client(ImageDecoderClient::Client&); ErrorOr<IPC::File> connect_new_image_decoder_client();
} }

View file

@ -23,9 +23,6 @@ class WebViewBridge;
- (void)setupWebViewApplication:(Main::Arguments&)arguments - (void)setupWebViewApplication:(Main::Arguments&)arguments
newTabPageURL:(URL::URL)new_tab_page_url; newTabPageURL:(URL::URL)new_tab_page_url;
- (ErrorOr<void>)launchRequestServer; - (ErrorOr<void>)launchServices;
- (ErrorOr<void>)launchImageDecoder;
- (ErrorOr<NonnullRefPtr<WebView::WebContentClient>>)launchWebContent:(Ladybird::WebViewBridge&)web_view_bridge;
- (ErrorOr<IPC::File>)launchWebWorker;
@end @end

View file

@ -7,12 +7,7 @@
#include <Interface/LadybirdWebViewBridge.h> #include <Interface/LadybirdWebViewBridge.h>
#include <LibCore/EventLoop.h> #include <LibCore/EventLoop.h>
#include <LibCore/ThreadEventQueue.h> #include <LibCore/ThreadEventQueue.h>
#include <LibImageDecoderClient/Client.h>
#include <LibRequests/RequestClient.h>
#include <LibWebView/Application.h> #include <LibWebView/Application.h>
#include <LibWebView/HelperProcess.h>
#include <LibWebView/Utilities.h>
#include <LibWebView/WebContentClient.h>
#include <Utilities/Conversions.h> #include <Utilities/Conversions.h>
#import <Application/Application.h> #import <Application/Application.h>
@ -68,75 +63,12 @@ ApplicationBridge::ApplicationBridge(Badge<WebView::Application>, Main::Argument
m_application_bridge = Ladybird::ApplicationBridge::create(arguments, move(new_tab_page_url)); m_application_bridge = Ladybird::ApplicationBridge::create(arguments, move(new_tab_page_url));
} }
- (ErrorOr<void>)launchRequestServer - (ErrorOr<void>)launchServices
{ {
auto request_server_paths = TRY(WebView::get_paths_for_helper_process("RequestServer"sv)); TRY(m_application_bridge->launch_services());
m_request_server_client = TRY(WebView::launch_request_server_process(request_server_paths, WebView::s_ladybird_resource_root));
return {}; return {};
} }
static ErrorOr<NonnullRefPtr<ImageDecoderClient::Client>> launch_new_image_decoder()
{
auto image_decoder_paths = TRY(WebView::get_paths_for_helper_process("ImageDecoder"sv));
return WebView::launch_image_decoder_process(image_decoder_paths);
}
- (ErrorOr<void>)launchImageDecoder
{
m_image_decoder_client = TRY(launch_new_image_decoder());
__weak Application* weak_self = self;
m_image_decoder_client->on_death = [weak_self]() {
Application* self = weak_self;
if (self == nil) {
return;
}
m_image_decoder_client = nullptr;
if (auto err = [self launchImageDecoder]; err.is_error()) {
dbgln("Failed to restart image decoder: {}", err.error());
VERIFY_NOT_REACHED();
}
auto num_clients = WebView::WebContentClient::client_count();
auto new_sockets = m_image_decoder_client->send_sync_but_allow_failure<Messages::ImageDecoderServer::ConnectNewClients>(num_clients);
if (!new_sockets || new_sockets->sockets().size() == 0) {
dbgln("Failed to connect {} new clients to ImageDecoder", num_clients);
VERIFY_NOT_REACHED();
}
WebView::WebContentClient::for_each_client([sockets = new_sockets->take_sockets()](WebView::WebContentClient& client) mutable {
client.async_connect_to_image_decoder(sockets.take_last());
return IterationDecision::Continue;
});
};
return {};
}
- (ErrorOr<NonnullRefPtr<WebView::WebContentClient>>)launchWebContent:(Ladybird::WebViewBridge&)web_view_bridge
{
// FIXME: Fail to open the tab, rather than crashing the whole application if this fails
auto request_server_socket = TRY(WebView::connect_new_request_server_client(*m_request_server_client));
auto image_decoder_socket = TRY(WebView::connect_new_image_decoder_client(*m_image_decoder_client));
auto web_content_paths = TRY(WebView::get_paths_for_helper_process("WebContent"sv));
auto web_content = TRY(WebView::launch_web_content_process(web_view_bridge, web_content_paths, move(image_decoder_socket), move(request_server_socket)));
return web_content;
}
- (ErrorOr<IPC::File>)launchWebWorker
{
auto web_worker_paths = TRY(WebView::get_paths_for_helper_process("WebWorker"sv));
auto worker_client = TRY(WebView::launch_web_worker_process(web_worker_paths, *m_request_server_client));
return worker_client->clone_transport();
}
#pragma mark - NSApplication #pragma mark - NSApplication
- (void)terminate:(id)sender - (void)terminate:(id)sender

View file

@ -12,9 +12,11 @@
#include <LibURL/URL.h> #include <LibURL/URL.h>
#include <LibWeb/HTML/SelectedFile.h> #include <LibWeb/HTML/SelectedFile.h>
#include <LibWebView/Application.h> #include <LibWebView/Application.h>
#include <LibWebView/HelperProcess.h>
#include <LibWebView/SearchEngine.h> #include <LibWebView/SearchEngine.h>
#include <LibWebView/SourceHighlighter.h> #include <LibWebView/SourceHighlighter.h>
#include <LibWebView/URL.h> #include <LibWebView/URL.h>
#include <LibWebView/Utilities.h>
#import <Application/Application.h> #import <Application/Application.h>
#import <Application/ApplicationDelegate.h> #import <Application/ApplicationDelegate.h>
@ -344,18 +346,9 @@ static void copy_data_to_clipboard(StringView data, NSPasteboardType pasteboard_
return [self.observer onCreateNewTab:{} activateTab:activate_tab]; return [self.observer onCreateNewTab:{} activateTab:activate_tab];
}; };
m_web_view_bridge->on_request_web_content = [weak_self]() {
Application* application = NSApp;
LadybirdWebView* self = weak_self;
if (self == nil) {
VERIFY_NOT_REACHED();
}
return [application launchWebContent:*(self->m_web_view_bridge)].release_value_but_fixme_should_propagate_errors();
};
m_web_view_bridge->on_request_worker_agent = []() { m_web_view_bridge->on_request_worker_agent = []() {
Application* application = NSApp; auto worker_client = MUST(WebView::launch_web_worker_process(MUST(WebView::get_paths_for_helper_process("WebWorker"sv))));
return [application launchWebWorker].release_value_but_fixme_should_propagate_errors(); return worker_client->clone_transport();
}; };
m_web_view_bridge->on_activate_tab = [weak_self]() { m_web_view_bridge->on_activate_tab = [weak_self]() {

View file

@ -10,7 +10,9 @@
#include <LibIPC/File.h> #include <LibIPC/File.h>
#include <LibWeb/Crypto/Crypto.h> #include <LibWeb/Crypto/Crypto.h>
#include <LibWebView/Application.h> #include <LibWebView/Application.h>
#include <LibWebView/HelperProcess.h>
#include <LibWebView/UserAgent.h> #include <LibWebView/UserAgent.h>
#include <LibWebView/Utilities.h>
#import <Interface/Palette.h> #import <Interface/Palette.h>
@ -143,11 +145,16 @@ Gfx::IntPoint WebViewBridge::to_widget_position(Gfx::IntPoint content_position)
void WebViewBridge::initialize_client(CreateNewClient create_new_client) void WebViewBridge::initialize_client(CreateNewClient create_new_client)
{ {
VERIFY(on_request_web_content);
if (create_new_client == CreateNewClient::Yes) { if (create_new_client == CreateNewClient::Yes) {
m_client_state = {}; m_client_state = {};
m_client_state.client = on_request_web_content();
auto request_server_socket = WebView::connect_new_request_server_client().release_value_but_fixme_should_propagate_errors();
auto image_decoder_socket = WebView::connect_new_image_decoder_client().release_value_but_fixme_should_propagate_errors();
auto candidate_web_content_paths = WebView::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, AK::move(image_decoder_socket), AK::move(request_server_socket)).release_value_but_fixme_should_propagate_errors();
m_client_state.client = new_client;
} else { } else {
m_client_state.client->register_view(m_client_state.page_index, *this); m_client_state.client->register_view(m_client_state.page_index, *this);
} }

View file

@ -50,7 +50,6 @@ public:
}; };
Optional<Paintable> paintable(); Optional<Paintable> paintable();
Function<NonnullRefPtr<WebView::WebContentClient>()> on_request_web_content;
Function<void()> on_zoom_level_changed; Function<void()> on_zoom_level_changed;
private: private:

View file

@ -83,10 +83,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
view->did_allocate_iosurface_backing_stores(message.front_backing_store_id, move(message.front_backing_store_port), message.back_backing_store_id, move(message.back_backing_store_port)); view->did_allocate_iosurface_backing_stores(message.front_backing_store_id, move(message.front_backing_store_port), message.back_backing_store_id, move(message.back_backing_store_port));
}; };
// FIXME: Create an abstraction to re-spawn the RequestServer and re-hook up its client hooks to each tab on crash TRY([application launchServices]);
TRY([application launchRequestServer]);
TRY([application launchImageDecoder]);
auto* delegate = [[ApplicationDelegate alloc] init]; auto* delegate = [[ApplicationDelegate alloc] init];
[NSApp setDelegate:delegate]; [NSApp setDelegate:delegate];

View file

@ -73,17 +73,6 @@ void Application::create_platform_options(WebView::ChromeOptions& chrome_options
web_content_options.is_layout_test_mode = is_layout_test_mode ? WebView::IsLayoutTestMode::Yes : WebView::IsLayoutTestMode::No; web_content_options.is_layout_test_mode = is_layout_test_mode ? WebView::IsLayoutTestMode::Yes : WebView::IsLayoutTestMode::No;
} }
ErrorOr<void> Application::launch_services()
{
auto request_server_paths = TRY(WebView::get_paths_for_helper_process("RequestServer"sv));
m_request_client = TRY(WebView::launch_request_server_process(request_server_paths, resources_folder));
auto image_decoder_paths = TRY(WebView::get_paths_for_helper_process("ImageDecoder"sv));
m_image_decoder_client = TRY(WebView::launch_image_decoder_process(image_decoder_paths));
return {};
}
ErrorOr<void> Application::launch_test_fixtures() ErrorOr<void> Application::launch_test_fixtures()
{ {
Fixture::initialize_fixtures(); Fixture::initialize_fixtures();

View file

@ -9,10 +9,7 @@
#include <AK/ByteString.h> #include <AK/ByteString.h>
#include <AK/Error.h> #include <AK/Error.h>
#include <AK/NonnullOwnPtr.h> #include <AK/NonnullOwnPtr.h>
#include <AK/RefPtr.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibImageDecoderClient/Client.h>
#include <LibRequests/RequestClient.h>
#include <LibWeb/PixelUnits.h> #include <LibWeb/PixelUnits.h>
#include <LibWebView/Application.h> #include <LibWebView/Application.h>
@ -34,12 +31,8 @@ public:
virtual void create_platform_arguments(Core::ArgsParser&) override; virtual void create_platform_arguments(Core::ArgsParser&) override;
virtual void create_platform_options(WebView::ChromeOptions&, WebView::WebContentOptions&) override; virtual void create_platform_options(WebView::ChromeOptions&, WebView::WebContentOptions&) override;
ErrorOr<void> launch_services();
ErrorOr<void> launch_test_fixtures(); ErrorOr<void> launch_test_fixtures();
static Requests::RequestClient& request_client() { return *the().m_request_client; }
static ImageDecoderClient::Client& image_decoder_client() { return *the().m_image_decoder_client; }
HeadlessWebView& create_web_view(Core::AnonymousBuffer theme, Web::DevicePixelSize window_size); HeadlessWebView& create_web_view(Core::AnonymousBuffer theme, Web::DevicePixelSize window_size);
HeadlessWebView& create_child_web_view(HeadlessWebView const&, u64 page_index); HeadlessWebView& create_child_web_view(HeadlessWebView const&, u64 page_index);
void destroy_web_views(); void destroy_web_views();
@ -70,9 +63,6 @@ public:
int height { 600 }; int height { 600 };
private: private:
RefPtr<Requests::RequestClient> m_request_client;
RefPtr<ImageDecoderClient::Client> m_image_decoder_client;
Vector<NonnullOwnPtr<HeadlessWebView>> m_web_views; Vector<NonnullOwnPtr<HeadlessWebView>> m_web_views;
}; };

View file

@ -33,7 +33,7 @@ HeadlessWebView::HeadlessWebView(Core::AnonymousBuffer theme, Web::DevicePixelSi
on_request_worker_agent = []() { on_request_worker_agent = []() {
auto web_worker_paths = MUST(WebView::get_paths_for_helper_process("WebWorker"sv)); auto web_worker_paths = MUST(WebView::get_paths_for_helper_process("WebWorker"sv));
auto worker_client = MUST(WebView::launch_web_worker_process(web_worker_paths, Application::request_client())); auto worker_client = MUST(WebView::launch_web_worker_process(web_worker_paths));
return worker_client->clone_transport(); return worker_client->clone_transport();
}; };
@ -162,8 +162,8 @@ NonnullOwnPtr<HeadlessWebView> HeadlessWebView::create_child(HeadlessWebView con
void HeadlessWebView::initialize_client(CreateNewClient create_new_client) void HeadlessWebView::initialize_client(CreateNewClient create_new_client)
{ {
if (create_new_client == CreateNewClient::Yes) { if (create_new_client == CreateNewClient::Yes) {
auto request_server_socket = WebView::connect_new_request_server_client(Application::request_client()).release_value_but_fixme_should_propagate_errors(); auto request_server_socket = WebView::connect_new_request_server_client().release_value_but_fixme_should_propagate_errors();
auto image_decoder_socket = WebView::connect_new_image_decoder_client(Application::image_decoder_client()).release_value_but_fixme_should_propagate_errors(); auto image_decoder_socket = WebView::connect_new_image_decoder_client().release_value_but_fixme_should_propagate_errors();
auto web_content_paths = WebView::get_paths_for_helper_process("WebContent"sv).release_value_but_fixme_should_propagate_errors(); auto web_content_paths = WebView::get_paths_for_helper_process("WebContent"sv).release_value_but_fixme_should_propagate_errors();
m_client_state.client = WebView::launch_web_content_process(*this, web_content_paths, move(image_decoder_socket), move(request_server_socket)).release_value_but_fixme_should_propagate_errors(); m_client_state.client = WebView::launch_web_content_process(*this, web_content_paths, move(image_decoder_socket), move(request_server_socket)).release_value_but_fixme_should_propagate_errors();

View file

@ -5,9 +5,7 @@
*/ */
#include <LibCore/ArgsParser.h> #include <LibCore/ArgsParser.h>
#include <LibWebView/HelperProcess.h>
#include <LibWebView/URL.h> #include <LibWebView/URL.h>
#include <LibWebView/Utilities.h>
#include <UI/Qt/Application.h> #include <UI/Qt/Application.h>
#include <UI/Qt/Settings.h> #include <UI/Qt/Settings.h>
#include <UI/Qt/StringUtils.h> #include <UI/Qt/StringUtils.h>
@ -54,38 +52,6 @@ bool Application::event(QEvent* event)
return QApplication::event(event); return QApplication::event(event);
} }
static ErrorOr<NonnullRefPtr<ImageDecoderClient::Client>> launch_new_image_decoder()
{
auto paths = TRY(WebView::get_paths_for_helper_process("ImageDecoder"sv));
return WebView::launch_image_decoder_process(paths);
}
ErrorOr<void> Application::initialize_image_decoder()
{
m_image_decoder_client = TRY(launch_new_image_decoder());
m_image_decoder_client->on_death = [this] {
m_image_decoder_client = nullptr;
if (auto err = this->initialize_image_decoder(); err.is_error()) {
dbgln("Failed to restart image decoder: {}", err.error());
VERIFY_NOT_REACHED();
}
auto num_clients = WebView::WebContentClient::client_count();
auto new_sockets = m_image_decoder_client->send_sync_but_allow_failure<Messages::ImageDecoderServer::ConnectNewClients>(num_clients);
if (!new_sockets || new_sockets->sockets().size() == 0) {
dbgln("Failed to connect {} new clients to ImageDecoder", num_clients);
VERIFY_NOT_REACHED();
}
WebView::WebContentClient::for_each_client([sockets = new_sockets->take_sockets()](WebView::WebContentClient& client) mutable {
client.async_connect_to_image_decoder(sockets.take_last());
return IterationDecision::Continue;
});
};
return {};
}
void Application::show_task_manager_window() void Application::show_task_manager_window()
{ {
if (!m_task_manager_window) { if (!m_task_manager_window) {

View file

@ -7,9 +7,6 @@
#pragma once #pragma once
#include <AK/Function.h> #include <AK/Function.h>
#include <AK/HashTable.h>
#include <LibImageDecoderClient/Client.h>
#include <LibRequests/RequestClient.h>
#include <LibURL/URL.h> #include <LibURL/URL.h>
#include <LibWebView/Application.h> #include <LibWebView/Application.h>
#include <UI/Qt/BrowserWindow.h> #include <UI/Qt/BrowserWindow.h>
@ -30,10 +27,6 @@ public:
virtual bool event(QEvent* event) override; virtual bool event(QEvent* event) override;
Function<void(URL::URL)> on_open_file; Function<void(URL::URL)> on_open_file;
RefPtr<Requests::RequestClient> request_server_client;
NonnullRefPtr<ImageDecoderClient::Client> image_decoder_client() const { return *m_image_decoder_client; }
ErrorOr<void> initialize_image_decoder();
BrowserWindow& new_window(Vector<URL::URL> const& initial_urls, BrowserWindow::IsPopupWindow is_popup_window = BrowserWindow::IsPopupWindow::No, Tab* parent_tab = nullptr, Optional<u64> page_index = {}); BrowserWindow& new_window(Vector<URL::URL> const& initial_urls, BrowserWindow::IsPopupWindow is_popup_window = BrowserWindow::IsPopupWindow::No, Tab* parent_tab = nullptr, Optional<u64> page_index = {});
@ -50,8 +43,6 @@ private:
TaskManagerWindow* m_task_manager_window { nullptr }; TaskManagerWindow* m_task_manager_window { nullptr };
BrowserWindow* m_active_window { nullptr }; BrowserWindow* m_active_window { nullptr };
RefPtr<ImageDecoderClient::Client> m_image_decoder_client;
}; };
} }

View file

@ -128,8 +128,7 @@ WebContentView::WebContentView(QWidget* window, RefPtr<WebView::WebContentClient
}; };
on_request_worker_agent = [&]() { on_request_worker_agent = [&]() {
auto& request_server_client = static_cast<Ladybird::Application*>(QApplication::instance())->request_server_client; auto worker_client = MUST(WebView::launch_web_worker_process(MUST(WebView::get_paths_for_helper_process("WebWorker"sv))));
auto worker_client = MUST(WebView::launch_web_worker_process(MUST(WebView::get_paths_for_helper_process("WebWorker"sv)), *request_server_client));
return worker_client->clone_transport(); return worker_client->clone_transport();
}; };
@ -629,13 +628,9 @@ void WebContentView::initialize_client(WebView::ViewImplementation::CreateNewCli
if (create_new_client == CreateNewClient::Yes) { if (create_new_client == CreateNewClient::Yes) {
m_client_state = {}; m_client_state = {};
auto& request_server_client = static_cast<Ladybird::Application*>(QApplication::instance())->request_server_client; // FIXME: Fail to open the tab, rather than crashing the whole application if these fail.
auto request_server_socket = WebView::connect_new_request_server_client().release_value_but_fixme_should_propagate_errors();
// FIXME: Fail to open the tab, rather than crashing the whole application if this fails auto image_decoder_socket = WebView::connect_new_image_decoder_client().release_value_but_fixme_should_propagate_errors();
auto request_server_socket = WebView::connect_new_request_server_client(*request_server_client).release_value_but_fixme_should_propagate_errors();
auto image_decoder = static_cast<Ladybird::Application*>(QApplication::instance())->image_decoder_client();
auto image_decoder_socket = WebView::connect_new_image_decoder_client(*image_decoder).release_value_but_fixme_should_propagate_errors();
auto candidate_web_content_paths = WebView::get_paths_for_helper_process("WebContent"sv).release_value_but_fixme_should_propagate_errors(); auto candidate_web_content_paths = WebView::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, AK::move(image_decoder_socket), AK::move(request_server_socket)).release_value_but_fixme_should_propagate_errors(); auto new_client = launch_web_content_process(*this, candidate_web_content_paths, AK::move(image_decoder_socket), AK::move(request_server_socket)).release_value_but_fixme_should_propagate_errors();

View file

@ -114,12 +114,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
WebView::copy_default_config_files(Ladybird::Settings::the()->directory()); WebView::copy_default_config_files(Ladybird::Settings::the()->directory());
// FIXME: Create an abstraction to re-spawn the RequestServer and re-hook up its client hooks to each tab on crash TRY(app->launch_services());
auto request_server_paths = TRY(WebView::get_paths_for_helper_process("RequestServer"sv));
auto requests_client = TRY(WebView::launch_request_server_process(request_server_paths, WebView::s_ladybird_resource_root));
app->request_server_client = move(requests_client);
TRY(app->initialize_image_decoder());
chrome_process.on_new_window = [&](auto const& urls) { chrome_process.on_new_window = [&](auto const& urls) {
app->new_window(urls); app->new_window(urls);