ladybird/Userland/Libraries/LibWeb/HTML/Scripting/WorkerEnvironmentSettingsObject.h
Andreas Kling e97cc671ea LibWeb: Give web workers a (totally hacky) Window object
This is *not* according to spec, however we currently store prototypes
and constructors on Window, so the only way for objects in a worker
context to become fully formed is to make a Window.

Long-term we should clean this up and remove the worker window object,
but for now it allows workers to exist without asserting.
2022-09-06 00:27:09 +02:00

50 lines
1.7 KiB
C++

/*
* Copyright (c) 2022, Ben Abraham <ben.d.abraham@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/URL.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Forward.h>
namespace Web::HTML {
class WorkerEnvironmentSettingsObject final
: public EnvironmentSettingsObject
, public Weakable<WorkerEnvironmentSettingsObject> {
public:
WorkerEnvironmentSettingsObject(NonnullOwnPtr<JS::ExecutionContext> execution_context)
: EnvironmentSettingsObject(move(execution_context))
{
}
static WeakPtr<WorkerEnvironmentSettingsObject> setup(NonnullOwnPtr<JS::ExecutionContext> execution_context /* FIXME: null or an environment reservedEnvironment, a URL topLevelCreationURL, and an origin topLevelOrigin */)
{
auto* realm = execution_context->realm;
VERIFY(realm);
auto settings_object = adopt_own(*new WorkerEnvironmentSettingsObject(move(execution_context)));
settings_object->target_browsing_context = nullptr;
realm->set_host_defined(move(settings_object));
return static_cast<WorkerEnvironmentSettingsObject*>(realm->host_defined());
}
virtual ~WorkerEnvironmentSettingsObject() override = default;
JS::GCPtr<DOM::Document> responsible_document() override { return nullptr; }
String api_url_character_encoding() override { return m_api_url_character_encoding; }
AK::URL api_base_url() override { return m_url; }
Origin origin() override { return m_origin; }
CanUseCrossOriginIsolatedAPIs cross_origin_isolated_capability() override { TODO(); }
private:
String m_api_url_character_encoding;
AK::URL m_url;
HTML::Origin m_origin;
};
}