mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:27:46 +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:
parent
4d22358e05
commit
b5acc5f2df
12 changed files with 92 additions and 13 deletions
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/HTML/Scripting/EnvironmentSettingsSnapshot.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
JS_DEFINE_ALLOCATOR(EnvironmentSettingsSnapshot);
|
||||
|
||||
EnvironmentSettingsSnapshot::EnvironmentSettingsSnapshot(NonnullOwnPtr<JS::ExecutionContext> execution_context, SerializedEnvironmentSettingsObject const& serialized_settings)
|
||||
: EnvironmentSettingsObject(move(execution_context))
|
||||
, m_api_url_character_encoding(serialized_settings.api_url_character_encoding)
|
||||
, m_url(serialized_settings.api_base_url)
|
||||
, m_origin(serialized_settings.origin)
|
||||
, m_policy_container(serialized_settings.policy_container)
|
||||
{
|
||||
// Why can't we put these in the init list? grandparent class members are strange it seems
|
||||
this->id = serialized_settings.id;
|
||||
this->creation_url = serialized_settings.creation_url;
|
||||
this->top_level_creation_url = serialized_settings.top_level_creation_url;
|
||||
this->top_level_creation_url = serialized_settings.top_level_creation_url;
|
||||
}
|
||||
|
||||
// Out of line to ensure this class has a key function
|
||||
EnvironmentSettingsSnapshot::~EnvironmentSettingsSnapshot() = default;
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/HTML/PolicyContainers.h>
|
||||
#include <LibWeb/HTML/Scripting/Environments.h>
|
||||
#include <LibWeb/HTML/Scripting/SerializedEnvironmentSettingsObject.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
class EnvironmentSettingsSnapshot final
|
||||
: public EnvironmentSettingsObject {
|
||||
JS_CELL(EnvironmentSettingsSnapshot, EnvironmentSettingsObject);
|
||||
JS_DECLARE_ALLOCATOR(EnvironmentSettingsSnapshot);
|
||||
|
||||
public:
|
||||
EnvironmentSettingsSnapshot(NonnullOwnPtr<JS::ExecutionContext>, SerializedEnvironmentSettingsObject const&);
|
||||
|
||||
virtual ~EnvironmentSettingsSnapshot() override;
|
||||
|
||||
JS::GCPtr<DOM::Document> responsible_document() override { return nullptr; }
|
||||
String api_url_character_encoding() override { return m_api_url_character_encoding; }
|
||||
URL api_base_url() override { return m_url; }
|
||||
Origin origin() override { return m_origin; }
|
||||
PolicyContainer policy_container() override { return m_policy_container; }
|
||||
CanUseCrossOriginIsolatedAPIs cross_origin_isolated_capability() override { return CanUseCrossOriginIsolatedAPIs::No; }
|
||||
|
||||
private:
|
||||
String m_api_url_character_encoding;
|
||||
URL m_url;
|
||||
HTML::Origin m_origin;
|
||||
HTML::PolicyContainer m_policy_container;
|
||||
};
|
||||
|
||||
}
|
|
@ -57,7 +57,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Worker>> Worker::create(String const& scrip
|
|||
// Technically not a fixme if our policy is not to throw errors :^)
|
||||
|
||||
// 2. Let outside settings be the current settings object.
|
||||
auto& outside_settings = document.relevant_settings_object();
|
||||
auto& outside_settings = current_settings_object();
|
||||
|
||||
// 3. Parse the scriptURL argument relative to outside settings.
|
||||
auto url = document.parse_url(script_url.to_byte_string());
|
||||
|
@ -110,7 +110,7 @@ void Worker::run_a_worker(URL& url, EnvironmentSettingsObject& outside_settings,
|
|||
// and is shared. Run the rest of these steps in that agent.
|
||||
|
||||
// Note: This spawns a new process to act as the 'agent' for the worker.
|
||||
m_agent = heap().allocate<WorkerAgent>(outside_settings.realm(), url, options, port);
|
||||
m_agent = heap().allocate<WorkerAgent>(outside_settings.realm(), url, options, port, outside_settings);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/workers.html#dom-worker-terminate
|
||||
|
|
|
@ -13,10 +13,11 @@ namespace Web::HTML {
|
|||
|
||||
JS_DEFINE_ALLOCATOR(WorkerAgent);
|
||||
|
||||
WorkerAgent::WorkerAgent(URL url, WorkerOptions const& options, JS::GCPtr<MessagePort> outside_port)
|
||||
WorkerAgent::WorkerAgent(URL url, WorkerOptions const& options, JS::GCPtr<MessagePort> outside_port, JS::NonnullGCPtr<EnvironmentSettingsObject> outside_settings)
|
||||
: m_worker_options(options)
|
||||
, m_url(move(url))
|
||||
, m_outside_port(outside_port)
|
||||
, m_outside_settings(outside_settings)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -41,7 +42,7 @@ void WorkerAgent::initialize(JS::Realm& realm)
|
|||
m_worker_ipc = make_ref_counted<WebWorkerClient>(move(worker_socket));
|
||||
m_worker_ipc->set_fd_passing_socket(move(fd_passing_socket));
|
||||
|
||||
m_worker_ipc->async_start_dedicated_worker(m_url, m_worker_options.type, m_worker_options.credentials, m_worker_options.name, move(data_holder));
|
||||
m_worker_ipc->async_start_dedicated_worker(m_url, m_worker_options.type, m_worker_options.credentials, m_worker_options.name, move(data_holder), m_outside_settings->serialize());
|
||||
}
|
||||
|
||||
void WorkerAgent::visit_edges(Cell::Visitor& visitor)
|
||||
|
@ -49,6 +50,7 @@ void WorkerAgent::visit_edges(Cell::Visitor& visitor)
|
|||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_message_port);
|
||||
visitor.visit(m_outside_port);
|
||||
visitor.visit(m_outside_settings);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ class WorkerAgent : public JS::Cell {
|
|||
JS_CELL(Agent, JS::Cell);
|
||||
JS_DECLARE_ALLOCATOR(WorkerAgent);
|
||||
|
||||
WorkerAgent(URL url, WorkerOptions const& options, JS::GCPtr<MessagePort> outside_port);
|
||||
WorkerAgent(URL url, WorkerOptions const& options, JS::GCPtr<MessagePort> outside_port, JS::NonnullGCPtr<EnvironmentSettingsObject> outside_settings);
|
||||
|
||||
private:
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
@ -33,6 +33,7 @@ private:
|
|||
|
||||
JS::GCPtr<MessagePort> m_message_port;
|
||||
JS::GCPtr<MessagePort> m_outside_port;
|
||||
JS::NonnullGCPtr<EnvironmentSettingsObject> m_outside_settings;
|
||||
|
||||
RefPtr<Web::HTML::WebWorkerClient> m_worker_ipc;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue