Truly independent web browser
/*
* Copyright (c) 2023, Andrew Kaster <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibGC/Heap.h>
#include <LibWeb/HTML/NavigationDestination.h>
#include <LibWeb/HTML/NavigationHistoryEntry.h>
#include <LibWeb/HTML/StructuredSerialize.h>
#include <LibWeb/Infra/SerializedURL.h>
namespace Web::HTML {
GC_DEFINE_ALLOCATOR(NavigationDestination);
GC::Ref<NavigationDestination> NavigationDestination::create()
{
return GC::Heap::the().allocate<NavigationDestination>();
}
NavigationDestination::NavigationDestination()
{
}
NavigationDestination::~NavigationDestination() = default;
void NavigationDestination::visit_edges(GC::Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_entry);
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationdestination-url
Utf16String NavigationDestination::url() const
{
// The url getter steps are to return this's URL, serialized.
return utf16_string_from_url_ascii(m_url.serialize());
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationdestination-key
Utf16String NavigationDestination::key() const
{
// The key getter steps are:
// 1. If this's entry is null, then return the empty string.
// 2. Return this's entry's key.
return (m_entry == nullptr) ? Utf16String {} : m_entry->key();
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationdestination-id
Utf16String NavigationDestination::id() const
{
// The id getter steps are:
// 1. If this's entry is null, then return the empty string.
// 2. Return this's entry's ID.
return (m_entry == nullptr) ? Utf16String {} : m_entry->id();
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationdestination-index
i64 NavigationDestination::index() const
{
// The index getter steps are:
// 1. If this's entry is null, then return -1.
// 2. Return this's entry's index.
return (m_entry == nullptr) ? -1 : m_entry->index();
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationdestination-samedocument
bool NavigationDestination::same_document() const
{
// The sameDocument getter steps are to return this's is same document.
return m_is_same_document;
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationdestination-getstate
WebIDL::ExceptionOr<JS::Value> NavigationDestination::get_state(JS::Realm& realm)
{
// The getState() method steps are to return StructuredDeserialize(this's state).
return HTML::structured_deserialize(realm.vm(), m_state, realm);
}
}