/src/serenity/Userland/Libraries/LibWeb/HTML/History.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2021, Luke Wilde <lukew@serenityos.org> |
3 | | * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> |
4 | | * |
5 | | * SPDX-License-Identifier: BSD-2-Clause |
6 | | */ |
7 | | |
8 | | #pragma once |
9 | | |
10 | | #include <LibWeb/Bindings/HistoryPrototype.h> |
11 | | #include <LibWeb/Bindings/PlatformObject.h> |
12 | | #include <LibWeb/HTML/HistoryHandlingBehavior.h> |
13 | | #include <LibWeb/WebIDL/ExceptionOr.h> |
14 | | #include <LibWeb/WebIDL/Types.h> |
15 | | |
16 | | namespace Web::HTML { |
17 | | |
18 | | class History final : public Bindings::PlatformObject { |
19 | | WEB_PLATFORM_OBJECT(History, Bindings::PlatformObject); |
20 | | JS_DECLARE_ALLOCATOR(History); |
21 | | |
22 | | public: |
23 | | [[nodiscard]] static JS::NonnullGCPtr<History> create(JS::Realm&, DOM::Document&); |
24 | | |
25 | | virtual ~History() override; |
26 | | |
27 | | WebIDL::ExceptionOr<void> push_state(JS::Value data, String const& unused, Optional<String> const& url = {}); |
28 | | WebIDL::ExceptionOr<void> replace_state(JS::Value data, String const& unused, Optional<String> const& url = {}); |
29 | | WebIDL::ExceptionOr<void> go(WebIDL::Long delta); |
30 | | WebIDL::ExceptionOr<void> back(); |
31 | | WebIDL::ExceptionOr<void> forward(); |
32 | | WebIDL::ExceptionOr<u64> length() const; |
33 | | WebIDL::ExceptionOr<Bindings::ScrollRestoration> scroll_restoration() const; |
34 | | WebIDL::ExceptionOr<void> set_scroll_restoration(Bindings::ScrollRestoration); |
35 | | WebIDL::ExceptionOr<JS::Value> state() const; |
36 | | |
37 | | u64 m_index { 0 }; |
38 | | u64 m_length { 0 }; |
39 | | |
40 | | JS::Value unsafe_state() const; |
41 | 0 | void set_state(JS::Value s) { m_state = s; } |
42 | | |
43 | | private: |
44 | | History(JS::Realm&, DOM::Document&); |
45 | | |
46 | | virtual void initialize(JS::Realm&) override; |
47 | | virtual void visit_edges(Cell::Visitor&) override; |
48 | | |
49 | | WebIDL::ExceptionOr<void> shared_history_push_replace_state(JS::Value data, Optional<String> const& url, HistoryHandlingBehavior); |
50 | | |
51 | | JS::NonnullGCPtr<DOM::Document> m_associated_document; |
52 | | JS::Value m_state { JS::js_null() }; |
53 | | }; |
54 | | |
55 | | bool can_have_its_url_rewritten(DOM::Document const& document, URL::URL const& target_url); |
56 | | |
57 | | } |