Everywhere: Transition ImageDecoder to be single-instance, owned by UI

This is the same behavior as RequestServer, with the added benefit that
we know how to gracefully reconnect ImageDecoder to all WebContent
processes on restart.
This commit is contained in:
Andrew Kaster 2024-06-26 13:44:42 -06:00 committed by Andrew Kaster
commit 4b5541e1b7
Notes: sideshowbarker 2024-07-17 00:59:43 +09:00
21 changed files with 250 additions and 31 deletions

View file

@ -77,6 +77,7 @@ ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(
WebView::ViewImplementation& view,
ReadonlySpan<ByteString> candidate_web_content_paths,
Ladybird::WebContentOptions const& web_content_options,
IPC::File image_decoder_socket,
Optional<IPC::File> request_server_socket)
{
Vector<ByteString> arguments {
@ -113,6 +114,9 @@ ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(
arguments.append(ByteString::number(request_server_socket->fd()));
}
arguments.append("--image-decoder-socket"sv);
arguments.append(ByteString::number(image_decoder_socket.fd()));
return launch_server_process<WebView::WebContentClient>("WebContent"sv, candidate_web_content_paths, move(arguments), RegisterWithProcessManager::No, web_content_options.enable_callgrind_profiling, view);
}
@ -164,3 +168,19 @@ ErrorOr<IPC::File> connect_new_request_server_client(Protocol::RequestClient& cl
return socket;
}
ErrorOr<IPC::File> connect_new_image_decoder_client(ImageDecoderClient::Client& client)
{
auto new_socket = client.send_sync_but_allow_failure<Messages::ImageDecoderServer::ConnectNewClients>(1);
if (!new_socket)
return Error::from_string_literal("Failed to connect to ImageDecoder");
auto sockets = new_socket->take_sockets();
if (sockets.size() != 1)
return Error::from_string_literal("Failed to connect to ImageDecoder");
auto socket = sockets.take_last();
TRY(socket.clear_close_on_exec());
return socket;
}