/* * Copyright (c) 2022, Ben Abraham * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include namespace Web::HTML { // FIXME: This is a bit ugly, this implementation is basically a 1:1 copy of what is in ESO // just modified to use DOM::Document instead of HTML::Window since workers have no window class WorkerEnvironmentSettingsObject final : public EnvironmentSettingsObject , public Weakable { public: WorkerEnvironmentSettingsObject(DOM::Document& document, NonnullOwnPtr execution_context) : EnvironmentSettingsObject(move(execution_context)) , m_document(document) { } static WeakPtr setup(DOM::Document& document, NonnullOwnPtr 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(document, move(execution_context))); settings_object->target_browsing_context = nullptr; realm->set_host_defined(move(settings_object)); return static_cast(realm->host_defined()); } virtual ~WorkerEnvironmentSettingsObject() override = default; RefPtr responsible_document() override { return m_document; } String api_url_character_encoding() override { return m_document->encoding_or_default(); } AK::URL api_base_url() override { return m_document->url(); } Origin origin() override { return m_document->origin(); } CanUseCrossOriginIsolatedAPIs cross_origin_isolated_capability() override { TODO(); } private: NonnullRefPtr m_document; }; }