Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / html / window_2.lucb

#==============================================================================================
#
#   window_2 - HTML::Window: user activation, idle periods, the associated Document, PDF viewer
#   objects, test mode, and the IDL attributes from window to opener
#
#   DESCRIPTION:
#       Port of Libraries/LibWeb/HTML/Window.cpp lines 553-1106 (has_sticky_activation through
#       set_opener).
#
#       Copyright (c) 2020-2023, Andreas Kling <andreas@ladybird.org>
#       Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

# mark: User activation =========================================================================

## Ported from Window.cpp:554 Web::HTML::Window::has_sticky_activation.
# https://html.spec.whatwg.org/multipage/interaction.html#sticky-activation
pub func html_window_has_sticky_activation(this: HtmlWindow*) -> bool:
    # When the current high resolution time given W
    let current_time = high_resolution_time_current_high_resolution_time((JsObject*)this)

    # is greater than or equal to the last activation timestamp in W
    if current_time >= this.m_last_activation_timestamp:
        # W is said to have sticky activation.
        return true

    return false

## Window::has_transient_activation's transient_activation_duration_ms.
let html_window_transient_activation_duration_ms: f64 = 5000.0

## Ported from Window.cpp:569 Web::HTML::Window::has_transient_activation.
# https://html.spec.whatwg.org/multipage/interaction.html#transient-activation
pub func html_window_has_transient_activation(this: HtmlWindow*) -> bool:
    # The transient activation duration is expected be at most a few seconds, so that the user can possibly
    # perceive the link between an interaction with the page and the page calling the activation-gated API.

    # When the current high resolution time given W
    let current_time = high_resolution_time_current_high_resolution_time((JsObject*)this)

    # is greater than or equal to the last activation timestamp in W
    if current_time >= this.m_last_activation_timestamp:
        # and less than the last activation timestamp in W plus the transient activation duration
        if current_time < this.m_last_activation_timestamp + html_window_transient_activation_duration_ms:
            # then W is said to have transient activation.
            return true

    return false

## Ported from Window.cpp:591 Web::HTML::Window::has_history_action_activation.
# https://html.spec.whatwg.org/multipage/interaction.html#history-action-activation
pub func html_window_has_history_action_activation(this: HtmlWindow*) -> bool:
    # When the last history-action activation timestamp of W is not equal to the last activation timestamp of W, then W is said to have history-action activation.
    return this.m_last_history_action_activation_timestamp != this.m_last_activation_timestamp

## Steps 2-4 shared by the two consume steps: the active window of each inclusive descendant
## navigable of the window's navigable's top-level traversable's active document.
func html_window_windows_of_top_level_traversable(navigable: HtmlNavigable*) -> ak.Vector[HtmlWindow*?]:
    # 2. Let top be W's navigable's top-level traversable.
    let top = html_navigable_top_level_traversable(navigable) else trap("no top-level traversable")

    # 3. Let navigables be the inclusive descendant navigables of top's active document.
    let navigables = dom_document_inclusive_descendant_navigables(html_navigable_active_document(top.html_navigable()) else trap("no active document"))

    # 4. Let windows be the list of Window objects constructed by taking the active window of each item in navigables.
    var windows = ak.Vector[HtmlWindow*?]()
    for n in ak.vector_span_const(&navigables):
        ak.vector_append_t(&windows, html_navigable_active_window(n else trap("no navigable")))
    return windows

## Ported from Window.cpp:598 Web::HTML::Window::consume_history_action_user_activation.
# https://html.spec.whatwg.org/multipage/interaction.html#consume-history-action-user-activation
pub func html_window_consume_history_action_user_activation(this: HtmlWindow*):
    let navigable = html_window_navigable(this)

    # 1. If W's navigable is null, then return.
    let current = navigable else return

    # 2.-4. (top, navigables and windows)
    let windows = html_window_windows_of_top_level_traversable(current)

    # 5. For each window in windows, set window's last history-action activation timestamp to window's last activation timestamp.
    for window in ak.vector_span_const(&windows):
        let w = window else trap("no active window")
        html_window_set_last_history_action_activation_timestamp(w, html_window_last_activation_timestamp(w))

## Ported from Window.cpp:623 Web::HTML::Window::consume_user_activation.
# https://html.spec.whatwg.org/multipage/interaction.html#consume-user-activation
pub func html_window_consume_user_activation(this: HtmlWindow*):
    let navigable = html_window_navigable(this)

    # 1. If W's navigable is null, then return.
    let current = navigable else return

    # 2.-4. (top, navigables and windows)
    let windows = html_window_windows_of_top_level_traversable(current)

    # 5. For each window in windows, if window's last activation timestamp is not positive infinity, then set window's last activation timestamp to negative infinity.
    for window in ak.vector_span_const(&windows):
        let w = window else trap("no active window")
        if html_window_last_activation_timestamp(w) != math.infinity:
            html_window_set_last_activation_timestamp(w, -math.infinity)

# mark: Idle periods ============================================================================

## The idle-task task queued by start_an_idle_period and invoke_idle_callbacks (`[this] { invoke_idle_callbacks(); }`).
func html_window_invoke_idle_callbacks_task(context: void*?):
    html_window_invoke_idle_callbacks((HtmlWindow*)(context else trap("no window")))

## Ported from Window.cpp:650 Web::HTML::Window::start_an_idle_period.
# https://w3c.github.io/requestidlecallback/#start-an-idle-period-algorithm
pub func html_window_start_an_idle_period(this: HtmlWindow*):
    # 1. Optionally, if the user agent determines the idle period should be delayed, return from this algorithm.

    # 2. Let pending_list be window's list of idle request callbacks.
    let pending_list = &this.m_idle_request_callbacks
    # 3. Let run_list be window's list of runnable idle callbacks.
    let run_list = &this.m_runnable_idle_callbacks
    ak.vector_extend(run_list, pending_list)
    # 4. Clear pending_list.
    ak.vector_clear(pending_list)

    # FIXME: This might not agree with the spec, but currently we use 100% CPU if we keep queueing tasks
    if ak.vector_is_empty(run_list):
        return

    # 5. Queue a task on the queue associated with the idle-task task source,
    #    which performs the steps defined in the invoke idle callbacks algorithm with window and getDeadline as parameters.
    _ = html_queue_global_task(HtmlTaskSource.idle_task, (JsObject*)this, gc.create_function0(gc.cell_heap(this.cell()), ak.Function0[unit](call = html_window_invoke_idle_callbacks_task, context = this)))

## Ported from Window.cpp:674 Web::HTML::Window::invoke_idle_callbacks.
# https://w3c.github.io/requestidlecallback/#invoke-idle-callbacks-algorithm
func html_window_invoke_idle_callbacks(this: HtmlWindow*):
    let event_loop = html_main_thread_event_loop()
    # 1. If the user-agent believes it should end the idle period early due to newly scheduled high-priority work, return from the algorithm.
    # 2. Let now be the current time.
    let now = high_resolution_time_unsafe_shared_current_time()
    # 3. If now is less than the result of calling getDeadline and the window's list of runnable idle callbacks is not empty:
    if now < html_event_loop_compute_deadline(event_loop) and not ak.vector_is_empty(&this.m_runnable_idle_callbacks):
        let realm = bind_platform_object_realm(this.bind_platform_object())
        # 1. Pop the top callback from window's list of runnable idle callbacks.
        let callback = ak.vector_take_first(&this.m_runnable_idle_callbacks)
        # 2. Let deadlineArg be a new IdleDeadline whose [get deadline time algorithm] is getDeadline.
        let deadline_arg = request_idle_callback_idle_deadline_create(realm)
        # 3. Call callback with deadlineArg as its argument. If an uncaught runtime script error occurs, then report the exception.
        let result = html_idle_callback_invoke(callback, deadline_arg)
        if js_completion_is_error(&result):
            html_report_exception_js_completion(result, realm)
        # 4. If window's list of runnable idle callbacks is not empty, queue a task which performs the steps
        #    in the invoke idle callbacks algorithm with getDeadline and window as a parameters and return from this algorithm
        _ = html_queue_global_task(HtmlTaskSource.idle_task, (JsObject*)this, gc.create_function0(gc.cell_heap(this.cell()), ak.Function0[unit](call = html_window_invoke_idle_callbacks_task, context = this)))

# mark: The associated Document =================================================================

## Ported from Window.cpp:698 Web::HTML::Window::set_associated_document.
pub func html_window_set_associated_document(this: HtmlWindow*, document: DomDocument*):
    this.m_associated_document = document

## Ported from Window.cpp:703 Web::HTML::Window::set_current_event.
pub func html_window_set_current_event(this: HtmlWindow*, event: DomEvent*?):
    this.m_current_event = event

## Ported from Window.cpp:708 Web::HTML::Window::browsing_context.
pub func html_window_browsing_context_const(this: HtmlWindow*) -> HtmlBrowsingContext*?:
    return dom_document_browsing_context(this.m_associated_document else trap("no associated document"))

## Ported from Window.cpp:713 Web::HTML::Window::browsing_context.
pub func html_window_browsing_context(this: HtmlWindow*) -> HtmlBrowsingContext*?:
    return dom_document_browsing_context(this.m_associated_document else trap("no associated document"))

## Ported from Window.cpp:719 Web::HTML::Window::navigable.
# https://html.spec.whatwg.org/multipage/nav-history-apis.html#window-navigable
pub func html_window_navigable(this: HtmlWindow*) -> HtmlNavigable*?:
    # A Window's navigable is the navigable whose active document is the Window's associated Document's, or null if there is no such navigable.
    return dom_document_navigable(this.m_associated_document else trap("no associated document"))

# mark: PDF viewer objects ======================================================================

## Ported from Window.cpp:726 Web::HTML::Window::pdf_viewer_plugin_objects.
# https://html.spec.whatwg.org/multipage/system-state.html#pdf-viewer-plugin-objects
pub func html_window_pdf_viewer_plugin_objects(this: HtmlWindow*) -> ak.Vector[HtmlPlugin*]:
    # Each Window object has a PDF viewer plugin objects list. If the user agent's PDF viewer supported is false, then it is the empty list.
    # Otherwise, it is a list containing five Plugin objects, whose names are, respectively:
    # 0.   "PDF Viewer"
    # 1.   "Chrome PDF Viewer"
    # 2.   "Chromium PDF Viewer"
    # 3.   "Microsoft Edge PDF Viewer"
    # 4.   "WebKit built-in PDF"
    # The values of the above list form the PDF viewer plugin names list. https://html.spec.whatwg.org/multipage/system-state.html#pdf-viewer-plugin-names
    if not page_pdf_viewer_supported(html_window_page(this)):
        return ak.Vector[HtmlPlugin*]()

    if ak.vector_is_empty(&this.m_pdf_viewer_plugin_objects):
        let realm = bind_platform_object_realm(this.bind_platform_object())
        # FIXME: Propagate errors.
        ak.vector_append_t(&this.m_pdf_viewer_plugin_objects, realm_create_html_plugin(realm, realm, ak.string_from_str("PDF Viewer")))
        ak.vector_append_t(&this.m_pdf_viewer_plugin_objects, realm_create_html_plugin(realm, realm, ak.string_from_str("Chrome PDF Viewer")))
        ak.vector_append_t(&this.m_pdf_viewer_plugin_objects, realm_create_html_plugin(realm, realm, ak.string_from_str("Chromium PDF Viewer")))
        ak.vector_append_t(&this.m_pdf_viewer_plugin_objects, realm_create_html_plugin(realm, realm, ak.string_from_str("Microsoft Edge PDF Viewer")))
        ak.vector_append_t(&this.m_pdf_viewer_plugin_objects, realm_create_html_plugin(realm, realm, ak.string_from_str("WebKit built-in PDF")))

    return this.m_pdf_viewer_plugin_objects

## Ported from Window.cpp:752 Web::HTML::Window::pdf_viewer_mime_type_objects.
# https://html.spec.whatwg.org/multipage/system-state.html#pdf-viewer-mime-type-objects
pub func html_window_pdf_viewer_mime_type_objects(this: HtmlWindow*) -> ak.Vector[HtmlMimeType*]:
    # Each Window object has a PDF viewer mime type objects list. If the user agent's PDF viewer supported is false, then it is the empty list.
    # Otherwise, it is a list containing two MimeType objects, whose types are, respectively:
    # 0.   "application/pdf"
    # 1.   "text/pdf"
    # The values of the above list form the PDF viewer mime types list. https://html.spec.whatwg.org/multipage/system-state.html#pdf-viewer-mime-types
    if not page_pdf_viewer_supported(html_window_page(this)):
        return ak.Vector[HtmlMimeType*]()

    if ak.vector_is_empty(&this.m_pdf_viewer_mime_type_objects):
        let realm = bind_platform_object_realm(this.bind_platform_object())
        ak.vector_append_t(&this.m_pdf_viewer_mime_type_objects, realm_create_html_mime_type(realm, realm, ak.string_from_str("application/pdf")))
        ak.vector_append_t(&this.m_pdf_viewer_mime_type_objects, realm_create_html_mime_type(realm, realm, ak.string_from_str("text/pdf")))

    return this.m_pdf_viewer_mime_type_objects

# mark: Test mode and internals =================================================================

## Ported from Window.cpp:772 Web::HTML::Window::in_test_mode.
pub func html_window_in_test_mode() -> bool:
    return html_s_test_mode

## Ported from Window.cpp:777 Web::HTML::Window::set_enable_test_mode.
pub func html_window_set_enable_test_mode(exposed: bool):
    html_s_test_mode = exposed

## Ported from Window.cpp:784 Web::HTML::Window::set_internals_object_exposed.
pub func html_window_set_internals_object_exposed(exposed: bool):
    html_s_internals_object_exposed = exposed

## Ported from Window.cpp:789 Web::HTML::Window::is_internals_object_exposed.
pub func html_window_is_internals_object_exposed() -> bool:
    return html_s_internals_object_exposed

## Ported from Window.cpp:794 Web::HTML::Window::initialize_web_interfaces.
pub func html_window_initialize_web_interfaces(this: HtmlWindow*) -> !:
    let realm = bind_platform_object_realm(this.bind_platform_object())
    # add_window_exposed_interfaces(*this): the interface objects are JS properties of the global
    # object, made by the bindings (phase 3).

    web_set_prototype_for_interface(this.js_cell(), realm, BindInterfaceName.window)

    # Bindings::WindowGlobalMixin::initialize(realm, *this) and
    # Bindings::WindowGlobalMixin::define_unforgeable_attributes(realm, *this): the global's JS
    # properties and unforgeable attributes come with the bindings (phase 3).
    html_window_or_worker_global_scope_mixin_initialize(&this.window_or_worker_global_scope_mixin, realm)

    # if (s_internals_object_exposed) define_direct_property("internals", realm.create<Internals::Internals>(realm), ...):
    # the internals object is a JS property of the global (phase 3, with the test runner's scripts).
    return

## Ported from Window.cpp:812 Web::HTML::Window::internal_set_prototype_of (override).
# https://webidl.spec.whatwg.org/#platform-object-setprototypeof
pub func html_window_internal_set_prototype_of_impl(this: HtmlWindow*, prototype: JsObject*?) -> bool!:
    # 1. Return ? SetImmutablePrototype(O, V).
    trap("unported (P3): Web::HTML::Window::internal_set_prototype_of (JS::Object::set_immutable_prototype)")

# mark: The window, document and name ===========================================================

## Ported from Window.cpp:819 Web::HTML::Window::window.
# https://html.spec.whatwg.org/multipage/window-object.html#dom-window
pub func html_window_window(this: HtmlWindow*) -> HtmlWindowProxy*:
    # The window, frames, and self getter steps are to return this's relevant realm.[[GlobalEnv]].[[GlobalThisValue]].
    return as_html_window_proxy((gc.Cell*)realm_global_this_value(html_relevant_realm((JsObject*)this)))

## Ported from Window.cpp:826 Web::HTML::Window::self.
# https://html.spec.whatwg.org/multipage/window-object.html#dom-self
pub func html_window_self(this: HtmlWindow*) -> HtmlWindowProxy*:
    # The window, frames, and self getter steps are to return this's relevant realm.[[GlobalEnv]].[[GlobalThisValue]].
    return as_html_window_proxy((gc.Cell*)realm_global_this_value(html_relevant_realm((JsObject*)this)))

## Ported from Window.cpp:833 Web::HTML::Window::document.
# https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-document-2
pub func html_window_document(this: HtmlWindow*) -> DomDocument*:
    # The document getter steps are to return this's associated Document.
    return html_window_associated_document(this)

## Ported from Window.cpp:840 Web::HTML::Window::name.
# https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-name
pub func html_window_name(this: HtmlWindow*) -> ak.String:
    # 1. If this's navigable is null, then return the empty string.
    let navigable = html_window_navigable(this) else return ak.String()

    # 2. Return this's navigable's target name.
    return html_navigable_target_name(navigable)

## Ported from Window.cpp:851 Web::HTML::Window::set_name.
# https://html.spec.whatwg.org/multipage/nav-history-apis.html#apis-for-creating-and-navigating-browsing-contexts-by-name:dom-name
pub func html_window_set_name(this: HtmlWindow*, name: ak.String):
    # 1. If this's navigable is null, then return.
    let navigable = html_window_navigable(this) else return

    # 2. Set this's navigable's active session history entry's document state's navigable target name to the given value.
    let entry = html_navigable_active_session_history_entry(navigable) else trap("no active session history entry")
    html_document_state_set_navigable_target_name(html_session_history_entry_document_state(entry) else trap("no document state"), name)

## Ported from Window.cpp:862 Web::HTML::Window::status.
# https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-status
pub func html_window_status(this: HtmlWindow*) -> ak.String:
    # the status attribute on the Window object must, on getting, return the last string it was set to
    return this.m_status

# mark: Closing =================================================================================

## Window::close's queued task (`[traversable] { as<TraversableNavigable>(*traversable).definitely_close_top_level_traversable(); }`).
func html_window_definitely_close_task(context: void*?):
    let traversable = (HtmlNavigable*)(context else trap("no traversable"))
    html_traversable_navigable_definitely_close_top_level_traversable(as_html_traversable_navigable(traversable))

## Ported from Window.cpp:869 Web::HTML::Window::close.
# https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-close
pub func html_window_close(this: HtmlWindow*):
    # 1. Let thisTraversable be this's navigable.
    let navigable = html_window_navigable(this)

    # 2. If thisTraversable is not a top-level traversable, then return.
    let traversable = navigable else return
    if not html_navigable_is_top_level_traversable(traversable):
        return

    # 3. If thisTraversable's is closing is true, then return.
    if html_navigable_is_closing(traversable):
        return

    # 4. Let browsingContext be thisTraversable's active browsing context.
    let browsing_context = html_navigable_active_browsing_context(traversable) else trap("no active browsing context")

    # 5. Let sourceSnapshotParams be the result of snapshotting source snapshot params given thisTraversable's active document.
    let source_snapshot_params = dom_document_snapshot_source_snapshot_params(html_navigable_active_document(traversable) else trap("no active document"))

    let incumbent_global_object = as_html_window((gc.Cell*)html_incumbent_global_object())

    # 6. If all the following are true:
    if (html_navigable_is_script_closable(traversable) and html_browsing_context_is_familiar_with(html_window_browsing_context(incumbent_global_object) else trap("no browsing context"), browsing_context) and html_navigable_allowed_by_sandboxing_to_navigate(html_window_navigable(incumbent_global_object) else trap("no navigable"), traversable, source_snapshot_params)):
        # thisTraversable is script-closable;
        # the incumbent global object's browsing context is familiar with browsingContext; and
        # the incumbent global object's navigable is allowed by sandboxing to navigate thisTraversable, given sourceSnapshotParams,
        # then:
        # 1. Set thisTraversable's is closing to true.
        html_navigable_set_closing(traversable, true)

        # 2. Queue a task on the DOM manipulation task source to definitely close thisTraversable.
        _ = html_queue_global_task(HtmlTaskSource.dom_manipulation, (JsObject*)incumbent_global_object, gc.create_function0(gc.cell_heap(this.cell()), ak.Function0[unit](call = html_window_definitely_close_task, context = traversable)))

## Ported from Window.cpp:913 Web::HTML::Window::closed.
# https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-closed
pub func html_window_closed(this: HtmlWindow*) -> bool:
    # The closed getter steps are to return true if this's browsing context is null or its is closing is true;
    # otherwise false.
    if html_window_browsing_context_const(this) == none:
        return true

    # FIXME: The spec seems a bit out of date. The `is closing` flag is on the navigable, not the browsing context.
    let navigable = html_window_navigable(this) else return true
    if html_navigable_is_closing(navigable):
        return true

    return false

## Ported from Window.cpp:928 Web::HTML::Window::set_status.
# https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-status
pub func html_window_set_status(this: HtmlWindow*, status: ak.String):
    # on setting, must set itself to the new value.
    this.m_status = status

# mark: Location, history, stop and focus =======================================================

## Ported from Window.cpp:935 Web::HTML::Window::location.
# https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-location
pub func html_window_location(this: HtmlWindow*) -> HtmlHtmlLocation*:
    let realm = bind_platform_object_realm(this.bind_platform_object())

    # The Window object's location getter steps are to return this's Location object.
    if this.m_location == none:
        this.m_location = realm_create_html_html_location(realm, realm)
    return this.m_location else trap("unreachable")

## Ported from Window.cpp:946 Web::HTML::Window::history.
# https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-history
pub func html_window_history(this: HtmlWindow*) -> HtmlHistory*:
    # The history getter steps are to return this's associated Document's history object.
    return dom_document_history(html_window_associated_document(this))

## Ported from Window.cpp:953 Web::HTML::Window::stop.
# https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-stop
pub func html_window_stop(this: HtmlWindow*):
    # 1. If this's navigable is null, then return.
    let navigable = html_window_navigable(this) else return

    # 2. Stop loading this's navigable.
    html_navigable_stop_loading(navigable)

## Ported from Window.cpp:965 Web::HTML::Window::focus.
# https://html.spec.whatwg.org/multipage/interaction.html#dom-window-focus
pub func html_window_focus(this: HtmlWindow*):
    # 1. Let current be this's navigable.
    let navigable = html_window_navigable(this)

    # 2. If current is null, then return.
    let current = navigable else return

    # 3. If the allow focus steps given current's active document return false, then return.
    if not dom_document_allow_focus(html_window_document(this)):
        return

    # 4. Run the focusing steps with current.
    # FIXME: We should pass in the browsing context itself instead of the active document, however the focusing steps don't currently accept browsing contexts.
    #        Passing in a browsing context always makes it resolve to its active document for focus, so this is fine for now.
    if let document = html_navigable_active_document(current):
        html_run_focusing_steps(document.dom_node())
    else:
        html_run_focusing_steps(none)

    # FIXME: 5. If current is a top-level traversable, user agents are encouraged to trigger some sort of notification to
    #           indicate to the user that the page is attempting to gain focus.

## Ported from Window.cpp:988 Web::HTML::Window::blur.
# https://html.spec.whatwg.org/multipage/interaction.html#dom-window-blur
pub func html_window_blur(this: HtmlWindow*):
    # The Window blur() method steps are to do nothing.
    return

# mark: Bar props ===============================================================================

## `if (!m_bar) m_bar = BarProp::create(realm()); return *m_bar;`.
func html_window_bar_prop(this: HtmlWindow*, bar: (HtmlBarProp*?)*) -> HtmlBarProp*:
    if *bar == none:
        *bar = html_bar_prop_create(bind_platform_object_realm(this.bind_platform_object()))

    return *bar else trap("unreachable")

## Ported from Window.cpp:994 Web::HTML::Window::locationbar.
# https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-locationbar
pub func html_window_locationbar(this: HtmlWindow*) -> HtmlBarProp*:
    return html_window_bar_prop(this, &this.m_locationbar)

## Ported from Window.cpp:1003 Web::HTML::Window::menubar.
# https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-menubar
pub func html_window_menubar(this: HtmlWindow*) -> HtmlBarProp*:
    return html_window_bar_prop(this, &this.m_menubar)

## Ported from Window.cpp:1012 Web::HTML::Window::personalbar.
# https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-personalbar
pub func html_window_personalbar(this: HtmlWindow*) -> HtmlBarProp*:
    return html_window_bar_prop(this, &this.m_personalbar)

## Ported from Window.cpp:1021 Web::HTML::Window::scrollbars.
# https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-scrollbars
pub func html_window_scrollbars(this: HtmlWindow*) -> HtmlBarProp*:
    return html_window_bar_prop(this, &this.m_scrollbars)

## Ported from Window.cpp:1030 Web::HTML::Window::statusbar.
# https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-statusbar
pub func html_window_statusbar(this: HtmlWindow*) -> HtmlBarProp*:
    return html_window_bar_prop(this, &this.m_statusbar)

## Ported from Window.cpp:1039 Web::HTML::Window::toolbar.
# https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-toolbar
pub func html_window_toolbar(this: HtmlWindow*) -> HtmlBarProp*:
    return html_window_bar_prop(this, &this.m_toolbar)

# mark: Frames, top and opener ==================================================================

## Ported from Window.cpp:1048 Web::HTML::Window::frames.
# https://html.spec.whatwg.org/multipage/window-object.html#dom-frames
pub func html_window_frames(this: HtmlWindow*) -> HtmlWindowProxy*:
    # The window, frames, and self getter steps are to return this's relevant realm.[[GlobalEnv]].[[GlobalThisValue]].
    return as_html_window_proxy((gc.Cell*)realm_global_this_value(html_relevant_realm((JsObject*)this)))

## Ported from Window.cpp:1055 Web::HTML::Window::length.
# https://html.spec.whatwg.org/multipage/window-object.html#dom-length
pub func html_window_length(this: HtmlWindow*) -> u32:
    # The length getter steps are to return this's associated Document's document-tree child navigables's size.
    let navigables = dom_document_document_tree_child_navigables(html_window_associated_document(this))
    return (u32)ak.vector_size(&navigables)

## Ported from Window.cpp:1062 Web::HTML::Window::top.
# https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-top
pub func html_window_top(this: HtmlWindow*) -> HtmlWindowProxy*?:
    # 1. If this's navigable is null, then return null.
    let navigable = html_window_navigable(this) else return none

    # 2. Return this's navigable's top-level traversable's active WindowProxy.
    let top = html_navigable_top_level_traversable(navigable) else trap("no top-level traversable")
    return html_navigable_active_window_proxy(top.html_navigable())

## Ported from Window.cpp:1074 Web::HTML::Window::opener.
# https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-opener
pub func html_window_opener(this: HtmlWindow*) -> HtmlWindowProxy*?:
    # 1. Let current be this's browsing context.
    let current = html_window_browsing_context_const(this)

    # 2. If current is null, then return null.
    let context = current else return none

    # 3. If current's opener browsing context is null, then return null.
    let opener_browsing_context = html_browsing_context_opener_browsing_context(context) else return none

    # 4. Return current's opener browsing context's WindowProxy object.
    return html_browsing_context_window_proxy(opener_browsing_context)

## Ported from Window.cpp:1092 Web::HTML::Window::set_opener.
pub func html_window_set_opener(this: HtmlWindow*, value: JsValue) -> !:
    # 1. If the given value is null and this's browsing context is non-null, then set this's browsing context's opener browsing context to null.
    let browsing_context = html_window_browsing_context(this)
    if js_value_is_null(value):
        if let context = browsing_context:
            html_browsing_context_set_opener_browsing_context(context, none)

    # 2. If the given value is non-null, then perform ? DefinePropertyOrThrow(this, "opener", { [[Value]]: the given value, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }).
    if not js_value_is_null(value):
        trap("unported (P3): Web::HTML::Window::set_opener (DefinePropertyOrThrow on the global object)")

    return