mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
Route BroadcastChannel messages over IPC so matching channels can receive them across WebContent and WebWorker processes, rather than only within a single process. Each channel now serializes its payload, sends it upward over IPC, and receiving processes deliver it locally after matching by storage key and channel name.
65 lines
2.1 KiB
C++
65 lines
2.1 KiB
C++
/*
|
|
* Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/HashMap.h>
|
|
#include <LibGC/Root.h>
|
|
#include <LibIPC/ConnectionFromClient.h>
|
|
#include <LibJS/Forward.h>
|
|
#include <LibWeb/Forward.h>
|
|
#include <LibWeb/HTML/BroadcastChannelMessage.h>
|
|
#include <LibWeb/Loader/FileRequest.h>
|
|
#include <LibWeb/Worker/WebWorkerClientEndpoint.h>
|
|
#include <LibWeb/Worker/WebWorkerServerEndpoint.h>
|
|
#include <WebWorker/Forward.h>
|
|
#include <WebWorker/PageHost.h>
|
|
|
|
namespace WebWorker {
|
|
|
|
class ConnectionFromClient final
|
|
: public IPC::ConnectionFromClient<WebWorkerClientEndpoint, WebWorkerServerEndpoint> {
|
|
C_OBJECT(ConnectionFromClient);
|
|
|
|
public:
|
|
virtual ~ConnectionFromClient() override;
|
|
|
|
virtual void die() override;
|
|
|
|
virtual void close_worker() override;
|
|
|
|
void request_file(Web::FileRequest);
|
|
|
|
PageHost& page_host() { return *m_page_host; }
|
|
PageHost const& page_host() const { return *m_page_host; }
|
|
|
|
Function<void(IPC::TransportHandle const&)> on_request_server_connection;
|
|
Function<void(IPC::TransportHandle const&)> on_image_decoder_connection;
|
|
|
|
private:
|
|
explicit ConnectionFromClient(NonnullOwnPtr<IPC::Transport>);
|
|
|
|
Web::Page& page();
|
|
Web::Page const& page() const;
|
|
|
|
virtual void connect_to_request_server(IPC::TransportHandle handle) override;
|
|
virtual void connect_to_image_decoder(IPC::TransportHandle handle) override;
|
|
virtual void start_worker(URL::URL url, Web::Bindings::WorkerType type, Web::Bindings::RequestCredentials credentials, String name, Web::HTML::TransferDataEncoder, Web::HTML::SerializedEnvironmentSettingsObject, Web::Bindings::AgentType) override;
|
|
virtual void handle_file_return(i32 error, Optional<IPC::File> file, i32 request_id) override;
|
|
virtual void broadcast_channel_message(Web::HTML::BroadcastChannelMessage message) override;
|
|
|
|
GC::Root<PageHost> m_page_host;
|
|
|
|
// FIXME: Route console messages to the Browser UI using a ConsoleClient
|
|
|
|
HashMap<int, Web::FileRequest> m_requested_files {};
|
|
int last_id { 0 };
|
|
|
|
RefPtr<WorkerHost> m_worker_host;
|
|
};
|
|
|
|
}
|