2022-02-17 13:31:09 +01:00
/*
* 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 {
// FIXME: This is a bit ugly, this implementation is basically a 1:1 copy of what is in ESO
2022-03-07 23:08:26 +01:00
// just modified to use DOM::Document instead of HTML::Window since workers have no window
2022-02-17 13:31:09 +01:00
class WorkerEnvironmentSettingsObject final
: public EnvironmentSettingsObject
, public Weakable < WorkerEnvironmentSettingsObject > {
public :
2022-08-04 21:30:33 +02:00
WorkerEnvironmentSettingsObject ( DOM : : Document & document , NonnullOwnPtr < JS : : ExecutionContext > execution_context )
: EnvironmentSettingsObject ( move ( execution_context ) )
2022-08-28 13:42:07 +02:00
, m_document ( JS : : make_handle ( document ) )
2022-02-17 13:31:09 +01:00
{
}
2022-08-04 21:30:33 +02:00
static WeakPtr < WorkerEnvironmentSettingsObject > setup ( DOM : : Document & document , NonnullOwnPtr < JS : : ExecutionContext > execution_context /* FIXME: null or an environment reservedEnvironment, a URL topLevelCreationURL, and an origin topLevelOrigin */ )
2022-02-17 13:31:09 +01:00
{
2022-08-04 21:30:33 +02:00
auto * realm = execution_context - > realm ;
2022-02-17 13:31:09 +01:00
VERIFY ( realm ) ;
2022-08-04 21:30:33 +02:00
auto settings_object = adopt_own ( * new WorkerEnvironmentSettingsObject ( document , move ( execution_context ) ) ) ;
2022-02-17 13:31:09 +01:00
settings_object - > target_browsing_context = nullptr ;
realm - > set_host_defined ( move ( settings_object ) ) ;
return static_cast < WorkerEnvironmentSettingsObject * > ( realm - > host_defined ( ) ) ;
}
virtual ~ WorkerEnvironmentSettingsObject ( ) override = default ;
2022-08-28 13:42:07 +02:00
JS : : GCPtr < DOM : : Document > responsible_document ( ) override { return m_document . ptr ( ) ; }
2022-02-17 13:31:09 +01:00
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 :
2022-08-28 13:42:07 +02:00
JS : : Handle < DOM : : Document > m_document ;
2022-02-17 13:31:09 +01:00
} ;
}