LibWeb: Construct ResourceLoader with a GC Heap

This will allow us to easily make use of HeapFunctions instead of
SafeFunction for all of the callbacks in ResourceLoader.
This commit is contained in:
Shannon Booth 2024-10-31 02:38:57 +13:00 committed by Alexander Kalenik
parent a8077f79cc
commit e44702f090
Notes: github-actions[bot] 2024-10-30 19:57:36 +00:00
6 changed files with 23 additions and 18 deletions

View file

@ -48,7 +48,7 @@
static ErrorOr<void> load_content_filters(StringView config_path);
static ErrorOr<void> load_autoplay_allowlist(StringView config_path);
static ErrorOr<void> initialize_resource_loader(int request_server_socket);
static ErrorOr<void> initialize_resource_loader(JS::Heap&, int request_server_socket);
static ErrorOr<void> initialize_image_decoder(int image_decoder_socket);
static ErrorOr<void> reinitialize_image_decoder(IPC::File const& image_decoder_socket);
@ -163,7 +163,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}
#endif
TRY(initialize_resource_loader(request_server_socket));
TRY(initialize_image_decoder(image_decoder_socket));
Web::HTML::Window::set_internals_object_exposed(expose_internals_object);
@ -172,6 +171,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Web::Bindings::initialize_main_thread_vm(Web::HTML::EventLoop::Type::Window));
TRY(initialize_resource_loader(Web::Bindings::main_thread_vm().heap(), request_server_socket));
if (log_all_js_exceptions) {
JS::g_log_all_js_exceptions = true;
}
@ -191,7 +192,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
static_assert(IsSame<IPC::Transport, IPC::TransportSocket>, "Need to handle other IPC transports here");
auto webcontent_socket = TRY(Core::take_over_socket_from_system_server("WebContent"sv));
auto webcontent_client = TRY(WebContent::ConnectionFromClient::try_create(IPC::Transport(move(webcontent_socket))));
auto webcontent_client = TRY(WebContent::ConnectionFromClient::try_create(Web::Bindings::main_thread_vm().heap(), IPC::Transport(move(webcontent_socket))));
webcontent_client->on_image_decoder_connection = [&](auto& socket_file) {
auto maybe_error = reinitialize_image_decoder(socket_file);
@ -250,7 +251,7 @@ static ErrorOr<void> load_autoplay_allowlist(StringView config_path)
return {};
}
ErrorOr<void> initialize_resource_loader(int request_server_socket)
ErrorOr<void> initialize_resource_loader(JS::Heap& heap, int request_server_socket)
{
static_assert(IsSame<IPC::Transport, IPC::TransportSocket>, "Need to handle other IPC transports here");
@ -258,7 +259,7 @@ ErrorOr<void> initialize_resource_loader(int request_server_socket)
TRY(socket->set_blocking(true));
auto request_client = TRY(try_make_ref_counted<Requests::RequestClient>(IPC::Transport(move(socket))));
Web::ResourceLoader::initialize(move(request_client));
Web::ResourceLoader::initialize(heap, move(request_client));
return {};
}

View file

@ -29,7 +29,7 @@
# include <QCoreApplication>
#endif
static ErrorOr<void> initialize_resource_loader(int request_server_socket);
static ErrorOr<void> initialize_resource_loader(JS::Heap&, int request_server_socket);
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
@ -62,16 +62,16 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Web::Platform::FontPlugin::install(*new Ladybird::FontPlugin(false));
TRY(initialize_resource_loader(request_server_socket));
TRY(Web::Bindings::initialize_main_thread_vm(Web::HTML::EventLoop::Type::Worker));
TRY(initialize_resource_loader(Web::Bindings::main_thread_vm().heap(), request_server_socket));
auto client = TRY(IPC::take_over_accepted_client_from_system_server<WebWorker::ConnectionFromClient>());
return event_loop.exec();
}
static ErrorOr<void> initialize_resource_loader(int request_server_socket)
static ErrorOr<void> initialize_resource_loader(JS::Heap& heap, int request_server_socket)
{
static_assert(IsSame<IPC::Transport, IPC::TransportSocket>, "Need to handle other IPC transports here");
@ -79,7 +79,7 @@ static ErrorOr<void> initialize_resource_loader(int request_server_socket)
TRY(socket->set_blocking(true));
auto request_client = TRY(try_make_ref_counted<Requests::RequestClient>(IPC::Transport(move(socket))));
Web::ResourceLoader::initialize(move(request_client));
Web::ResourceLoader::initialize(heap, move(request_client));
return {};
}

View file

@ -30,9 +30,9 @@ namespace Web {
static RefPtr<ResourceLoader> s_resource_loader;
void ResourceLoader::initialize(NonnullRefPtr<Requests::RequestClient> request_client)
void ResourceLoader::initialize(JS::Heap& heap, NonnullRefPtr<Requests::RequestClient> request_client)
{
s_resource_loader = adopt_ref(*new ResourceLoader(move(request_client)));
s_resource_loader = adopt_ref(*new ResourceLoader(heap, move(request_client)));
}
ResourceLoader& ResourceLoader::the()
@ -44,8 +44,9 @@ ResourceLoader& ResourceLoader::the()
return *s_resource_loader;
}
ResourceLoader::ResourceLoader(NonnullRefPtr<Requests::RequestClient> request_client)
: m_request_client(move(request_client))
ResourceLoader::ResourceLoader(JS::Heap& heap, NonnullRefPtr<Requests::RequestClient> request_client)
: m_heap(heap)
, m_request_client(move(request_client))
, m_user_agent(MUST(String::from_utf8(default_user_agent)))
, m_platform(MUST(String::from_utf8(default_platform)))
, m_preferred_languages({ "en-US"_string })

View file

@ -22,7 +22,7 @@ namespace Web {
class ResourceLoader : public Core::EventReceiver {
C_OBJECT_ABSTRACT(ResourceLoader)
public:
static void initialize(NonnullRefPtr<Requests::RequestClient>);
static void initialize(JS::Heap&, NonnullRefPtr<Requests::RequestClient>);
static ResourceLoader& the();
RefPtr<Resource> load_resource(Resource::Type, LoadRequest&);
@ -74,8 +74,10 @@ public:
void clear_cache();
void evict_from_cache(LoadRequest const&);
JS::Heap& heap() { return m_heap; }
private:
explicit ResourceLoader(NonnullRefPtr<Requests::RequestClient>);
explicit ResourceLoader(JS::Heap&, NonnullRefPtr<Requests::RequestClient>);
RefPtr<Requests::Request> start_network_request(LoadRequest const&);
void handle_network_response_headers(LoadRequest const&, HTTP::HeaderMap const&);
@ -83,6 +85,7 @@ private:
int m_pending_loads { 0 };
JS::Heap& m_heap;
NonnullRefPtr<Requests::RequestClient> m_request_client;
HashTable<NonnullRefPtr<Requests::Request>> m_active_requests;

View file

@ -50,8 +50,8 @@ ErrorOr<int> serenity_main(Main::Arguments)
return Web::Platform::AudioCodecPluginAgnostic::create(move(loader));
});
Web::ResourceLoader::initialize(TRY(WebView::RequestServerAdapter::try_create()));
TRY(Web::Bindings::initialize_main_thread_vm(Web::HTML::EventLoop::Type::Window));
Web::ResourceLoader::initialize(Web::Bindings::main_thread_vm().heap(), TRY(WebView::RequestServerAdapter::try_create()));
auto client = TRY(IPC::take_over_accepted_client_from_system_server<WebContent::ConnectionFromClient>());
return event_loop.exec();

View file

@ -35,8 +35,8 @@ ErrorOr<int> serenity_main(Main::Arguments)
Web::Platform::EventLoopPlugin::install(*new Web::Platform::EventLoopPluginSerenity);
Web::Platform::FontPlugin::install(*new Web::Platform::FontPluginSerenity);
Web::ResourceLoader::initialize(TRY(WebView::RequestServerAdapter::try_create()));
TRY(Web::Bindings::initialize_main_thread_vm(Web::HTML::EventLoop::Type::Worker));
Web::ResourceLoader::initialize(Web::Bindings::main_thread_vm().heap(), TRY(WebView::RequestServerAdapter::try_create()));
auto client = TRY(IPC::take_over_accepted_client_from_system_server<WebWorker::ConnectionFromClient>());