1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 11:47:34 +00:00

LibWeb: Serialize and pass to the WebWorker the current ESO

This allows the initial fetch() in the run a worker AO to use the proper
values from the outside settings.
This commit is contained in:
Andrew Kaster 2024-03-05 09:42:10 -07:00 committed by Andreas Kling
parent 4d22358e05
commit b5acc5f2df
12 changed files with 92 additions and 13 deletions

View file

@ -52,12 +52,12 @@ Web::Page const& ConnectionFromClient::page() const
return m_page_host->page();
}
void ConnectionFromClient::start_dedicated_worker(URL const& url, String const& type, String const&, String const&, Web::HTML::TransferDataHolder const& implicit_port)
void ConnectionFromClient::start_dedicated_worker(URL const& url, String const& type, String const&, String const&, Web::HTML::TransferDataHolder const& implicit_port, Web::HTML::SerializedEnvironmentSettingsObject const& outside_settings)
{
m_worker_host = make_ref_counted<DedicatedWorkerHost>(url, type);
// FIXME: Yikes, const_cast to move? Feels like a LibIPC bug.
// We should be able to move non-copyable types from a Message type.
m_worker_host->run(page(), move(const_cast<Web::HTML::TransferDataHolder&>(implicit_port)));
m_worker_host->run(page(), move(const_cast<Web::HTML::TransferDataHolder&>(implicit_port)), outside_settings);
}
void ConnectionFromClient::handle_file_return(i32 error, Optional<IPC::File> const& file, i32 request_id)

View file

@ -39,7 +39,7 @@ private:
Web::Page& page();
Web::Page const& page() const;
virtual void start_dedicated_worker(URL const& url, String const&, String const&, String const&, Web::HTML::TransferDataHolder const&) override;
virtual void start_dedicated_worker(URL const& url, String const&, String const&, String const&, Web::HTML::TransferDataHolder const&, Web::HTML::SerializedEnvironmentSettingsObject const&) override;
virtual void handle_file_return(i32 error, Optional<IPC::File> const& file, i32 request_id) override;
JS::Handle<PageHost> m_page_host;

View file

@ -9,6 +9,7 @@
#include <LibWeb/Fetch/Fetching/Fetching.h>
#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>
#include <LibWeb/HTML/Scripting/ClassicScript.h>
#include <LibWeb/HTML/Scripting/EnvironmentSettingsSnapshot.h>
#include <LibWeb/HTML/Scripting/Fetching.h>
#include <LibWeb/HTML/Scripting/WorkerEnvironmentSettingsObject.h>
#include <LibWeb/HTML/WorkerDebugConsoleClient.h>
@ -28,7 +29,7 @@ DedicatedWorkerHost::~DedicatedWorkerHost() = default;
// https://html.spec.whatwg.org/multipage/workers.html#run-a-worker
// FIXME: Extract out into a helper for both shared and dedicated workers
void DedicatedWorkerHost::run(JS::NonnullGCPtr<Web::Page> page, Web::HTML::TransferDataHolder message_port_data)
void DedicatedWorkerHost::run(JS::NonnullGCPtr<Web::Page> page, Web::HTML::TransferDataHolder message_port_data, Web::HTML::SerializedEnvironmentSettingsObject const& outside_settings_snapshot)
{
bool const is_shared = false;
@ -64,6 +65,9 @@ void DedicatedWorkerHost::run(JS::NonnullGCPtr<Web::Page> page, Web::HTML::Trans
// 11. Append owner to worker global scope's owner set.
// FIXME: support for 'owner' set on WorkerGlobalScope
// IMPLEMENTATION DEFINED: We need an object to represent the fetch response's client
auto outside_settings = inner_settings->heap().allocate<Web::HTML::EnvironmentSettingsSnapshot>(inner_settings->realm(), inner_settings->realm_execution_context().copy(), outside_settings_snapshot);
// 12. If is shared is true, then:
if (is_shared) {
// FIXME: Shared worker support
@ -210,8 +214,7 @@ void DedicatedWorkerHost::run(JS::NonnullGCPtr<Web::Page> page, Web::HTML::Trans
dbgln("Unsupported script type {} for LibWeb/Worker", m_type);
TODO();
}
// FIXME: We don't have outside settings anymore, they live in the owner. https://github.com/whatwg/html/issues/9920
if (auto err = Web::HTML::fetch_classic_worker_script(m_url, inner_settings, destination, inner_settings, perform_fetch, on_complete); err.is_error()) {
if (auto err = Web::HTML::fetch_classic_worker_script(m_url, outside_settings, destination, inner_settings, perform_fetch, on_complete); err.is_error()) {
dbgln("Failed to run worker script");
// FIXME: Abort the worker properly
TODO();

View file

@ -10,6 +10,7 @@
#include <AK/URL.h>
#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/Forward.h>
#include <LibWeb/HTML/Scripting/SerializedEnvironmentSettingsObject.h>
#include <LibWeb/HTML/StructuredSerialize.h>
namespace WebWorker {
@ -19,7 +20,7 @@ public:
explicit DedicatedWorkerHost(URL url, String type);
~DedicatedWorkerHost();
void run(JS::NonnullGCPtr<Web::Page>, Web::HTML::TransferDataHolder message_port_data);
void run(JS::NonnullGCPtr<Web::Page>, Web::HTML::TransferDataHolder message_port_data, Web::HTML::SerializedEnvironmentSettingsObject const&);
private:
RefPtr<Web::HTML::WorkerDebugConsoleClient> m_console;