SessionHistoryEntry.h 6.1 KB

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