Coverage Report

Created: 2026-06-07 07:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibWeb/HTML/SessionHistoryEntry.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <AK/WeakPtr.h>
10
#include <LibJS/Heap/Cell.h>
11
#include <LibJS/Heap/GCPtr.h>
12
#include <LibURL/URL.h>
13
#include <LibWeb/Forward.h>
14
#include <LibWeb/HTML/PolicyContainers.h>
15
#include <LibWeb/HTML/StructuredSerialize.h>
16
17
namespace Web::HTML {
18
19
// https://html.spec.whatwg.org/multipage/history.html#scroll-restoration-mode
20
enum class ScrollRestorationMode {
21
    // https://html.spec.whatwg.org/multipage/history.html#dom-scrollrestoration-auto
22
    // The user agent is responsible for restoring the scroll position upon navigation.
23
    Auto,
24
25
    // https://html.spec.whatwg.org/multipage/history.html#dom-scrollrestoration-manual
26
    // The page is responsible for restoring the scroll position and the user agent does not attempt to do so automatically.
27
    Manual,
28
};
29
30
// https://html.spec.whatwg.org/multipage/history.html#session-history-entry
31
class SessionHistoryEntry final : public JS::Cell {
32
    JS_CELL(SessionHistoryEntry, JS::Cell);
33
    JS_DECLARE_ALLOCATOR(SessionHistoryEntry);
34
35
public:
36
    SessionHistoryEntry();
37
38
    JS::NonnullGCPtr<SessionHistoryEntry> clone() const;
39
40
    void visit_edges(Cell::Visitor&) override;
41
42
    JS::GCPtr<DOM::Document> document() const;
43
44
    enum class Pending {
45
        Tag,
46
    };
47
48
0
    [[nodiscard]] Variant<int, Pending> step() const { return m_step; }
49
0
    void set_step(Variant<int, Pending> step) { m_step = step; }
50
51
0
    [[nodiscard]] URL::URL const& url() const { return m_url; }
52
0
    void set_url(URL::URL url) { m_url = move(url); }
53
54
0
    [[nodiscard]] JS::GCPtr<HTML::DocumentState> document_state() const { return m_document_state; }
55
0
    void set_document_state(JS::GCPtr<HTML::DocumentState> document_state) { m_document_state = document_state; }
56
57
0
    [[nodiscard]] SerializationRecord const& classic_history_api_state() const { return m_classic_history_api_state; }
58
0
    void set_classic_history_api_state(SerializationRecord classic_history_api_state) { m_classic_history_api_state = move(classic_history_api_state); }
59
60
0
    [[nodiscard]] SerializationRecord const& navigation_api_state() const { return m_navigation_api_state; }
61
0
    void set_navigation_api_state(SerializationRecord navigation_api_state) { m_navigation_api_state = move(navigation_api_state); }
62
63
0
    [[nodiscard]] String const& navigation_api_key() const { return m_navigation_api_key; }
64
0
    void set_navigation_api_key(String navigation_api_key) { m_navigation_api_key = move(navigation_api_key); }
65
66
0
    [[nodiscard]] String const& navigation_api_id() const { return m_navigation_api_id; }
67
0
    void set_navigation_api_id(String navigation_api_id) { m_navigation_api_id = move(navigation_api_id); }
68
69
0
    [[nodiscard]] ScrollRestorationMode scroll_restoration_mode() const { return m_scroll_restoration_mode; }
70
0
    void set_scroll_restoration_mode(ScrollRestorationMode scroll_restoration_mode) { m_scroll_restoration_mode = scroll_restoration_mode; }
71
72
0
    [[nodiscard]] Optional<PolicyContainer> const& policy_container() const { return m_policy_container; }
73
0
    void set_policy_container(Optional<PolicyContainer> policy_container) { m_policy_container = move(policy_container); }
74
75
0
    [[nodiscard]] Optional<ByteString> const& browsing_context_name() const { return m_browsing_context_name; }
76
0
    void set_browsing_context_name(Optional<ByteString> browsing_context_name) { m_browsing_context_name = move(browsing_context_name); }
77
78
0
    [[nodiscard]] JS::GCPtr<BrowsingContext> original_source_browsing_context() const { return m_original_source_browsing_context; }
79
0
    void set_original_source_browsing_context(JS::GCPtr<BrowsingContext> original_source_browsing_context) { m_original_source_browsing_context = original_source_browsing_context; }
80
81
private:
82
    // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-step
83
    // step, a non-negative integer or "pending", initially "pending".
84
    Variant<int, Pending> m_step { Pending::Tag };
85
86
    // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-url
87
    // URL, a URL
88
    URL::URL m_url;
89
90
    // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-document-state
91
    JS::GCPtr<HTML::DocumentState> m_document_state;
92
93
    // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-classic-history-api-state
94
    // classic history API state, which is serialized state, initially StructuredSerializeForStorage(null).
95
    SerializationRecord m_classic_history_api_state;
96
97
    // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-navigation-api-state
98
    // navigation API state, which is a serialized state, initially StructuredSerializeForStorage(undefined).
99
    SerializationRecord m_navigation_api_state;
100
101
    // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-navigation-api-key
102
    // navigation API key, which is a string, initially set to the result of generating a random UUID.
103
    String m_navigation_api_key;
104
105
    // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-navigation-api-id
106
    // navigation API ID, which is a string, initially set to the result of generating a random UUID.
107
    String m_navigation_api_id;
108
109
    // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-scroll-restoration-mode
110
    // scroll restoration mode, a scroll restoration mode, initially "auto"
111
    ScrollRestorationMode m_scroll_restoration_mode { ScrollRestorationMode::Auto };
112
113
    // policy container, a policy container or null
114
    Optional<PolicyContainer> m_policy_container;
115
116
    // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-scroll-position
117
    // FIXME: scroll position data, which is scroll position data for the document's restorable scrollable regions
118
119
    // browsing context name, a browsing context name or null, initially null
120
    Optional<ByteString> m_browsing_context_name;
121
122
    // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-other
123
    // FIXME: persisted user state, which is implementation-defined, initially null
124
    // NOTE: This is where we could remember the state of form controls, for example.
125
126
    JS::GCPtr<BrowsingContext> m_original_source_browsing_context;
127
};
128
129
}