/src/serenity/Userland/Libraries/LibWeb/HTML/SessionHistoryEntry.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibWeb/Crypto/Crypto.h> |
8 | | #include <LibWeb/HTML/BrowsingContext.h> |
9 | | #include <LibWeb/HTML/DocumentState.h> |
10 | | #include <LibWeb/HTML/SessionHistoryEntry.h> |
11 | | |
12 | | namespace Web::HTML { |
13 | | |
14 | | JS_DEFINE_ALLOCATOR(SessionHistoryEntry); |
15 | | |
16 | | void SessionHistoryEntry::visit_edges(Cell::Visitor& visitor) |
17 | 0 | { |
18 | 0 | Base::visit_edges(visitor); |
19 | 0 | visitor.visit(m_document_state); |
20 | 0 | visitor.visit(m_original_source_browsing_context); |
21 | 0 | } |
22 | | |
23 | | SessionHistoryEntry::SessionHistoryEntry() |
24 | 0 | : m_classic_history_api_state(MUST(structured_serialize_for_storage(vm(), JS::js_null()))) |
25 | 0 | , m_navigation_api_state(MUST(structured_serialize_for_storage(vm(), JS::js_undefined()))) |
26 | 0 | , m_navigation_api_key(MUST(Crypto::generate_random_uuid())) |
27 | 0 | , m_navigation_api_id(MUST(Crypto::generate_random_uuid())) |
28 | 0 | { |
29 | 0 | } |
30 | | |
31 | | JS::NonnullGCPtr<SessionHistoryEntry> SessionHistoryEntry::clone() const |
32 | 0 | { |
33 | 0 | JS::NonnullGCPtr<SessionHistoryEntry> entry = *heap().allocate_without_realm<SessionHistoryEntry>(); |
34 | 0 | entry->m_step = m_step; |
35 | 0 | entry->m_url = m_url; |
36 | 0 | entry->m_document_state = m_document_state->clone(); |
37 | 0 | entry->m_classic_history_api_state = m_classic_history_api_state; |
38 | 0 | entry->m_navigation_api_state = m_navigation_api_state; |
39 | 0 | entry->m_navigation_api_key = m_navigation_api_key; |
40 | 0 | entry->m_navigation_api_id = m_navigation_api_id; |
41 | 0 | entry->m_scroll_restoration_mode = m_scroll_restoration_mode; |
42 | 0 | entry->m_policy_container = m_policy_container; |
43 | 0 | entry->m_browsing_context_name = m_browsing_context_name; |
44 | 0 | entry->m_original_source_browsing_context = m_original_source_browsing_context; |
45 | 0 | return entry; |
46 | 0 | } |
47 | | |
48 | | // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-document |
49 | | JS::GCPtr<DOM::Document> SessionHistoryEntry::document() const |
50 | 0 | { |
51 | | // To get a session history entry's document, return its document state's document. |
52 | 0 | if (!m_document_state) |
53 | 0 | return {}; |
54 | 0 | return m_document_state->document(); |
55 | 0 | } |
56 | | |
57 | | } |