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
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

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

View file

@ -7,12 +7,7 @@
#include <Interface/LadybirdWebViewBridge.h>
#include <LibCore/EventLoop.h>
#include <LibCore/ThreadEventQueue.h>
#include <LibImageDecoderClient/Client.h>
#include <LibRequests/RequestClient.h>
#include <LibWebView/Application.h>
#include <LibWebView/HelperProcess.h>
#include <LibWebView/Utilities.h>
#include <LibWebView/WebContentClient.h>
#include <Utilities/Conversions.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));
}
- (ErrorOr<void>)launchRequestServer
- (ErrorOr<void>)launchServices
{
auto request_server_paths = TRY(WebView::get_paths_for_helper_process("RequestServer"sv));
m_request_server_client = TRY(WebView::launch_request_server_process(request_server_paths, WebView::s_ladybird_resource_root));
TRY(m_application_bridge->launch_services());
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
- (void)terminate:(id)sender