dymokomi/luce-browser-engine
Source of release 0.6.1
0.6.1 / src / web / html / scripting / window_environment_settings_object.lucb
#==============================================================================================
#
# window_environment_settings_object - HTML::WindowEnvironmentSettingsObject: the settings
# object of a Window's realm
#
# DESCRIPTION:
# Port of Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp (lines
# 1-152) and WindowEnvironmentSettingsObject.h (lines 1-39): setting up a window
# environment settings object (and the realm's [[HostDefined]] with the web intrinsics
# and the page), and the settings object's algorithms, which answer from the window's
# associated Document.
#
# Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
# SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================
## Ported from Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp:18 Web::HTML::WindowEnvironmentSettingsObject::WindowEnvironmentSettingsObject.
pub func html_window_environment_settings_object_construct(this: HtmlWindowEnvironmentSettingsObject*, window: HtmlWindow*, execution_context: JsExecutionContext*):
html_environment_settings_object_construct(this.html_environment_settings_object(), execution_context)
this.m_window = window
## Ported from Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp:26 Web::HTML::WindowEnvironmentSettingsObject::visit_edges (override).
pub func html_window_environment_settings_object_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
let this = (HtmlWindowEnvironmentSettingsObject*)base
html_environment_settings_object_visit_edges_impl(base, visitor)
gc.cell_visitor_visit_t(visitor, this.m_window)
## The static next_id of setup.
var html_window_environment_settings_object_next_id: i64 = 1
## Ported from Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp:33 Web::HTML::WindowEnvironmentSettingsObject::setup.
## https://html.spec.whatwg.org/multipage/window-object.html#set-up-a-window-environment-settings-object
pub func html_window_environment_settings_object_setup(page: Page*, creation_url: web_url.Url, execution_context: JsExecutionContext*, reserved_environment: HtmlEnvironment*?, top_level_creation_url: web_url.Url, top_level_origin: web_url.Origin):
# 1. Let realm be the value of execution context's Realm component.
let realm = execution_context.realm else trap("VERIFY: the execution context has a realm")
# 2. Let window be realm's global object.
let window = as_html_window((gc.Cell*)realm_global_object(realm))
# 3. Let settings object be a new environment settings object whose algorithms are defined as follows:
# NOTE: See the functions defined for this class.
let settings_object = realm_create_html_window_environment_settings_object(realm, window, execution_context)
let environment = settings_object.html_environment()
# 4. If reservedEnvironment is non-null, then:
if let reserved = reserved_environment:
# FIXME: 1. Set settings object's id to reservedEnvironment's id,
# target browsing context to reservedEnvironment's target browsing context,
# and active service worker to reservedEnvironment's active service worker.
environment.id = reserved.id
environment.target_browsing_context = reserved.target_browsing_context
# 2. Set reservedEnvironment's id to the empty string.
reserved.id = ak.String()
# 5. Otherwise, ...
else:
# FIXME: ...set settings object's id to a new unique opaque string,
# settings object's target browsing context to null,
# and settings object's active service worker to null.
environment.id = ak.string_number_i64(html_window_environment_settings_object_next_id)
html_window_environment_settings_object_next_id += 1
environment.target_browsing_context = none
# 6. Set settings object's creation URL to creationURL,
# settings object's top-level creation URL to topLevelCreationURL,
# and settings object's top-level origin to topLevelOrigin.
environment.creation_url = creation_url
environment.top_level_creation_url = top_level_creation_url
environment.top_level_origin = top_level_origin
# 7. Set realm's [[HostDefined]] field to settings object.
# Non-Standard: We store the ESO next to the web intrinsics in a custom HostDefined object
let intrinsics = realm_create_bind_intrinsics(realm, realm)
let host_defined = bind_principal_host_defined_create(settings_object.html_environment_settings_object(), intrinsics, page)
realm_set_host_defined(realm, host_defined.bind_host_defined())
# Non-Standard: We cannot fully initialize window object until *after* the we set up
# the realm's [[HostDefined]] internal slot as the internal slot contains the web platform intrinsics
html_window_initialize_web_interfaces(window) else trap("MUST: Window::initialize_web_interfaces")
## Ported from Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp:87 Web::HTML::WindowEnvironmentSettingsObject::responsible_document (override).
## https://html.spec.whatwg.org/multipage/window-object.html#script-settings-for-window-objects:responsible-document
pub func html_window_environment_settings_object_responsible_document_impl(base: HtmlEnvironmentSettingsObject*) -> DomDocument*?:
let this = (HtmlWindowEnvironmentSettingsObject*)base
# Return window's associated Document.
return html_window_associated_document(this.m_window else trap("no window"))
## Ported from Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp:94 Web::HTML::WindowEnvironmentSettingsObject::api_base_url (override).
## https://html.spec.whatwg.org/multipage/window-object.html#script-settings-for-window-objects:api-base-url
pub func html_window_environment_settings_object_api_base_url_impl(base: HtmlEnvironmentSettingsObject*) -> web_url.Url:
let this = (HtmlWindowEnvironmentSettingsObject*)base
# Return the current base URL of window's associated Document.
return dom_document_base_url(html_window_associated_document(this.m_window else trap("no window")))
## Ported from Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp:101 Web::HTML::WindowEnvironmentSettingsObject::origin (override).
## https://html.spec.whatwg.org/multipage/window-object.html#script-settings-for-window-objects:concept-settings-object-origin
pub func html_window_environment_settings_object_origin_impl(base: HtmlEnvironmentSettingsObject*) -> web_url.Origin:
let this = (HtmlWindowEnvironmentSettingsObject*)base
# Return the origin of window's associated Document.
return dom_document_origin(html_window_associated_document(this.m_window else trap("no window")))
## Ported from Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp:108 Web::HTML::WindowEnvironmentSettingsObject::has_cross_site_ancestor (override).
## https://html.spec.whatwg.org/multipage/nav-history-apis.html#script-settings-for-window-objects:concept-settings-object-has-cross-site-ancestor
pub func html_window_environment_settings_object_has_cross_site_ancestor_impl(base: HtmlEnvironmentSettingsObject*) -> bool:
let this = (HtmlWindowEnvironmentSettingsObject*)base
let window = this.m_window else trap("no window")
let navigable = html_window_navigable(window) else trap("the window has no navigable")
# 1. If window's navigable's parent is null, then return false.
let parent = html_navigable_parent(navigable) else return false
# 2. Let parentDocument be window's navigable's parent's active document.
let parent_document = html_navigable_active_document(parent) else trap("the parent navigable has no active document")
# 3. If parentDocument's relevant settings object's has cross-site ancestor is true, then return true.
if html_environment_settings_object_has_cross_site_ancestor(dom_document_relevant_settings_object(parent_document)):
return true
# 4. If parentDocument's origin is not same site with window's associated Document's origin, then return true.
let parent_origin = dom_document_origin(parent_document)
if not web_url.origin_is_same_site(&parent_origin, dom_document_origin(html_window_associated_document(window))):
return true
# 5. Return false.
return false
## Ported from Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp:130 Web::HTML::WindowEnvironmentSettingsObject::policy_container (override).
## https://html.spec.whatwg.org/multipage/window-object.html#script-settings-for-window-objects:concept-settings-object-policy-container
pub func html_window_environment_settings_object_policy_container_impl(base: HtmlEnvironmentSettingsObject*) -> HtmlPolicyContainer*:
let this = (HtmlWindowEnvironmentSettingsObject*)base
# Return the policy container of window's associated Document.
return dom_document_policy_container(html_window_associated_document(this.m_window else trap("no window")))
## Ported from Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp:137 Web::HTML::WindowEnvironmentSettingsObject::time_origin (override).
## https://html.spec.whatwg.org/multipage/nav-history-apis.html#script-settings-for-window-objects:concept-settings-object-time-origin
pub func html_window_environment_settings_object_time_origin_impl(base: HtmlEnvironmentSettingsObject*) -> f64:
let this = (HtmlWindowEnvironmentSettingsObject*)base
# Return window's associated Document's load timing info's navigation start time.
return dom_document_load_timing_info(html_window_associated_document(this.m_window else trap("no window"))).navigation_start_time
## Ported from Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp:144 Web::HTML::WindowEnvironmentSettingsObject::cross_origin_isolated_capability (override).
## https://html.spec.whatwg.org/multipage/window-object.html#script-settings-for-window-objects:concept-settings-object-cross-origin-isolated-capability
pub func html_window_environment_settings_object_cross_origin_isolated_capability_impl(base: HtmlEnvironmentSettingsObject*) -> HtmlCanUseCrossOriginIsolatedApIs:
# FIXME: Return true if both of the following hold, and false otherwise:
# 1. realm's agent cluster's cross-origin-isolation mode is "concrete", and
# 2. window's associated Document is allowed to use the "cross-origin-isolated" feature.
return HtmlCanUseCrossOriginIsolatedApIs.no