Skip to content

Commit

Permalink
LibWebView+ImageDecoder+RequestServer+WebContent: Add init_transport
Browse files Browse the repository at this point in the history
  • Loading branch information
stasoid authored and ADKaster committed Feb 13, 2025
1 parent 652af31 commit 3e46cb9
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Libraries/LibImageDecoderClient/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class Client final
C_OBJECT_ABSTRACT(Client);

public:
using InitTransport = Messages::ImageDecoderServer::InitTransport;

Client(IPC::Transport);

NonnullRefPtr<Core::Promise<DecodedImage>> decode_image(ReadonlyBytes, Function<ErrorOr<void>(DecodedImage&)> on_resolved, Function<void(Error&)> on_rejected, Optional<Gfx::IntSize> ideal_size = {}, Optional<ByteString> mime_type = {});
Expand Down
2 changes: 2 additions & 0 deletions Libraries/LibRequests/RequestClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class RequestClient final
C_OBJECT_ABSTRACT(RequestClient)

public:
using InitTransport = Messages::RequestServer::InitTransport;

explicit RequestClient(IPC::Transport);
virtual ~RequestClient() override;

Expand Down
5 changes: 5 additions & 0 deletions Libraries/LibWebView/HelperProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ static ErrorOr<NonnullRefPtr<ClientType>> launch_server_process(
if constexpr (requires { client->set_pid(pid_t {}); })
client->set_pid(process.pid());

if constexpr (requires { client->transport().set_peer_pid(0); } && !IsSame<ClientType, Web::HTML::WebWorkerClient>) {
auto response = client->template send_sync<typename ClientType::InitTransport>(Core::System::getpid());
client->transport().set_peer_pid(response->peer_pid());
}

WebView::Application::the().add_child_process(move(process));

if (chrome_options.profile_helper_process == process_type) {
Expand Down
2 changes: 2 additions & 0 deletions Libraries/LibWebView/WebContentClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class WebContentClient final
C_OBJECT_ABSTRACT(WebContentClient);

public:
using InitTransport = Messages::WebContentServer::InitTransport;

static Optional<ViewImplementation&> view_for_pid_and_page_id(pid_t pid, u64 page_id);

template<CallableAs<IterationDecision, WebContentClient&> Callback>
Expand Down
9 changes: 9 additions & 0 deletions Services/ImageDecoder/ConnectionFromClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ void ConnectionFromClient::die()
}
}

Messages::ImageDecoderServer::InitTransportResponse ConnectionFromClient::init_transport([[maybe_unused]] int peer_pid)
{
#ifdef AK_OS_WINDOWS
m_transport.set_peer_pid(peer_pid);
return Core::System::getpid();
#endif
VERIFY_NOT_REACHED();
}

ErrorOr<IPC::File> ConnectionFromClient::connect_new_client()
{
int socket_fds[2] {};
Expand Down
1 change: 1 addition & 0 deletions Services/ImageDecoder/ConnectionFromClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ConnectionFromClient final
virtual Messages::ImageDecoderServer::DecodeImageResponse decode_image(Core::AnonymousBuffer const&, Optional<Gfx::IntSize> const& ideal_size, Optional<ByteString> const& mime_type) override;
virtual void cancel_decoding(i64 image_id) override;
virtual Messages::ImageDecoderServer::ConnectNewClientsResponse connect_new_clients(size_t count) override;
virtual Messages::ImageDecoderServer::InitTransportResponse init_transport(int peer_pid) override;

ErrorOr<IPC::File> connect_new_client();

Expand Down
1 change: 1 addition & 0 deletions Services/ImageDecoder/ImageDecoderServer.ipc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

endpoint ImageDecoderServer
{
init_transport(int peer_pid) => (int peer_pid)
decode_image(Core::AnonymousBuffer data, Optional<Gfx::IntSize> ideal_size, Optional<ByteString> mime_type) => (i64 image_id)
cancel_decoding(i64 image_id) =|

Expand Down
9 changes: 9 additions & 0 deletions Services/RequestServer/ConnectionFromClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,15 @@ void ConnectionFromClient::die()
Core::EventLoop::current().quit(0);
}

Messages::RequestServer::InitTransportResponse ConnectionFromClient::init_transport([[maybe_unused]] int peer_pid)
{
#ifdef AK_OS_WINDOWS
m_transport.set_peer_pid(peer_pid);
return Core::System::getpid();
#endif
VERIFY_NOT_REACHED();
}

Messages::RequestServer::ConnectNewClientResponse ConnectionFromClient::connect_new_client()
{
static_assert(IsSame<IPC::Transport, IPC::TransportSocket>, "Need to handle other IPC transports here");
Expand Down
1 change: 1 addition & 0 deletions Services/RequestServer/ConnectionFromClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ConnectionFromClient final
private:
explicit ConnectionFromClient(IPC::Transport);

virtual Messages::RequestServer::InitTransportResponse init_transport(int peer_pid) override;
virtual Messages::RequestServer::ConnectNewClientResponse connect_new_client() override;
virtual Messages::RequestServer::IsSupportedProtocolResponse is_supported_protocol(ByteString const&) override;
virtual void set_dns_server(ByteString const& host_or_address, u16 port, bool use_tls) override;
Expand Down
1 change: 1 addition & 0 deletions Services/RequestServer/RequestServer.ipc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

endpoint RequestServer
{
init_transport(int peer_pid) => (int peer_pid)
connect_new_client() => (IPC::File client_socket)

// use_tls: enable DNS over TLS
Expand Down
9 changes: 9 additions & 0 deletions Services/WebContent/ConnectionFromClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ void ConnectionFromClient::die()
Web::Platform::EventLoopPlugin::the().quit();
}

Messages::WebContentServer::InitTransportResponse ConnectionFromClient::init_transport([[maybe_unused]] int peer_pid)
{
#ifdef AK_OS_WINDOWS
m_transport.set_peer_pid(peer_pid);
return Core::System::getpid();
#endif
VERIFY_NOT_REACHED();
}

Optional<PageClient&> ConnectionFromClient::page(u64 index, SourceLocation location)
{
if (auto page = m_page_host->page(index); page.has_value())
Expand Down
1 change: 1 addition & 0 deletions Services/WebContent/ConnectionFromClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class ConnectionFromClient final
Optional<PageClient&> page(u64 index, SourceLocation = SourceLocation::current());
Optional<PageClient const&> page(u64 index, SourceLocation = SourceLocation::current()) const;

virtual Messages::WebContentServer::InitTransportResponse init_transport(int peer_pid) override;
virtual void close_server() override;
virtual Messages::WebContentServer::GetWindowHandleResponse get_window_handle(u64 page_id) override;
virtual void set_window_handle(u64 page_id, String const& handle) override;
Expand Down
1 change: 1 addition & 0 deletions Services/WebContent/WebContentServer.ipc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

endpoint WebContentServer
{
init_transport(int peer_pid) => (int peer_pid)
close_server() =|

get_window_handle(u64 page_id) => (String handle)
Expand Down
8 changes: 8 additions & 0 deletions Services/WebContent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ ErrorOr<void> initialize_resource_loader(GC::Heap& heap, int request_server_sock
TRY(socket->set_blocking(true));

auto request_client = TRY(try_make_ref_counted<Requests::RequestClient>(IPC::Transport(move(socket))));
#ifdef AK_OS_WINDOWS
auto response = request_client->send_sync<Messages::RequestServer::InitTransport>(Core::System::getpid());
request_client->transport().set_peer_pid(response->peer_pid());
#endif
Web::ResourceLoader::initialize(heap, move(request_client));

return {};
Expand All @@ -292,6 +296,10 @@ ErrorOr<void> initialize_image_decoder(int image_decoder_socket)
TRY(socket->set_blocking(true));

auto new_client = TRY(try_make_ref_counted<ImageDecoderClient::Client>(IPC::Transport(move(socket))));
#ifdef AK_OS_WINDOWS
auto response = new_client->send_sync<Messages::ImageDecoderServer::InitTransport>(Core::System::getpid());
new_client->transport().set_peer_pid(response->peer_pid());
#endif

Web::Platform::ImageCodecPlugin::install(*new WebView::ImageCodecPlugin(move(new_client)));

Expand Down

0 comments on commit 3e46cb9

Please sign in to comment.