Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / html / navigation_history_entry.lucb

#==============================================================================================
#
#   navigation_history_entry - HTML::NavigationHistoryEntry: an entry of a Navigation's entry
#   list, over its session history entry
#
#   DESCRIPTION:
#       Port of Libraries/LibWeb/HTML/NavigationHistoryEntry.cpp lines 23-40 (create, the
#       constructor, initialize) with the inline session_history_entry of
#       NavigationHistoryEntry.h. The JS-facing getters (url, key, id, index, sameDocument,
#       getState, ondispose) are phase 3.
#
#       Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from NavigationHistoryEntry.cpp:23 Web::HTML::NavigationHistoryEntry::create.
pub func html_navigation_history_entry_create(realm: Realm*, she: HtmlSessionHistoryEntry*) -> HtmlNavigationHistoryEntry*:
    return realm_create_html_navigation_history_entry(realm, realm, she)

## Ported from NavigationHistoryEntry.cpp:28 Web::HTML::NavigationHistoryEntry::NavigationHistoryEntry.
pub func html_navigation_history_entry_construct(this: HtmlNavigationHistoryEntry*, realm: Realm*, she: HtmlSessionHistoryEntry*):
    dom_event_target_construct(this.dom_event_target(), realm)
    this.m_session_history_entry = she

## Ported from NavigationHistoryEntry.cpp:36 Web::HTML::NavigationHistoryEntry::initialize (override).
pub func html_navigation_history_entry_initialize_impl(base: JsCell*, realm: Realm*):
    web_set_prototype_for_interface(base, realm, BindInterfaceName.navigation_history_entry)
    dom_event_target_initialize_impl(base, realm)

## Ported from NavigationHistoryEntry.h:28 Web::HTML::NavigationHistoryEntry::session_history_entry.
pub func html_navigation_history_entry_session_history_entry(this: HtmlNavigationHistoryEntry*) -> HtmlSessionHistoryEntry*:
    return this.m_session_history_entry

## Ported from NavigationHistoryEntry.cpp:69 Web::HTML::NavigationHistoryEntry::key.
## https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationhistoryentry-key
pub func html_navigation_history_entry_key(this: HtmlNavigationHistoryEntry*) -> ak.String:
    # The key of a NavigationHistoryEntry nhe is given by the return value of the following algorithm:
    # 1. If nhe's relevant global object's associated Document is not fully active, then return the empty string.
    let associated_document = html_window_associated_document(as_html_window((gc.Cell*)html_relevant_global_object((JsObject*)this)))
    if not dom_document_is_fully_active(associated_document):
        return ak.string_new()

    # 2. Return nhe's session history entry's navigation API key.
    return html_session_history_entry_navigation_api_key(this.m_session_history_entry)