SessionHistoryEntry.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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::GCPtr<DOM::Document> document() const;
  32. enum class Pending {
  33. Tag,
  34. };
  35. [[nodiscard]] Variant<int, Pending> step() const { return m_step; }
  36. void set_step(Variant<int, Pending> step) { m_step = step; }
  37. [[nodiscard]] URL::URL const& url() const { return m_url; }
  38. void set_url(URL::URL url) { m_url = move(url); }
  39. [[nodiscard]] JS::GCPtr<HTML::DocumentState> document_state() const { return m_document_state; }
  40. void set_document_state(JS::GCPtr<HTML::DocumentState> document_state) { m_document_state = document_state; }
  41. [[nodiscard]] SerializationRecord const& classic_history_api_state() const { return m_classic_history_api_state; }
  42. void set_classic_history_api_state(SerializationRecord classic_history_api_state) { m_classic_history_api_state = move(classic_history_api_state); }
  43. [[nodiscard]] SerializationRecord const& navigation_api_state() const { return m_navigation_api_state; }
  44. void set_navigation_api_state(SerializationRecord navigation_api_state) { m_navigation_api_state = move(navigation_api_state); }
  45. [[nodiscard]] String const& navigation_api_key() const { return m_navigation_api_key; }
  46. void set_navigation_api_key(String navigation_api_key) { m_navigation_api_key = move(navigation_api_key); }
  47. [[nodiscard]] String const& navigation_api_id() const { return m_navigation_api_id; }
  48. void set_navigation_api_id(String navigation_api_id) { m_navigation_api_id = move(navigation_api_id); }
  49. [[nodiscard]] ScrollRestorationMode scroll_restoration_mode() const { return m_scroll_restoration_mode; }
  50. void set_scroll_restoration_mode(ScrollRestorationMode scroll_restoration_mode) { m_scroll_restoration_mode = scroll_restoration_mode; }
  51. [[nodiscard]] Optional<PolicyContainer> const& policy_container() const { return m_policy_container; }
  52. void set_policy_container(Optional<PolicyContainer> policy_container) { m_policy_container = move(policy_container); }
  53. [[nodiscard]] Optional<ByteString> const& browsing_context_name() const { return m_browsing_context_name; }
  54. void set_browsing_context_name(Optional<ByteString> browsing_context_name) { m_browsing_context_name = move(browsing_context_name); }
  55. [[nodiscard]] JS::GCPtr<BrowsingContext> original_source_browsing_context() const { return m_original_source_browsing_context; }
  56. void set_original_source_browsing_context(JS::GCPtr<BrowsingContext> original_source_browsing_context) { m_original_source_browsing_context = original_source_browsing_context; }
  57. private:
  58. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-step
  59. // step, a non-negative integer or "pending", initially "pending".
  60. Variant<int, Pending> m_step { Pending::Tag };
  61. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-url
  62. // URL, a URL
  63. URL::URL m_url;
  64. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-document-state
  65. JS::GCPtr<HTML::DocumentState> m_document_state;
  66. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-classic-history-api-state
  67. // classic history API state, which is serialized state, initially StructuredSerializeForStorage(null).
  68. SerializationRecord m_classic_history_api_state;
  69. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-navigation-api-state
  70. // navigation API state, which is a serialized state, initially StructuredSerializeForStorage(undefined).
  71. SerializationRecord m_navigation_api_state;
  72. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-navigation-api-key
  73. // navigation API key, which is a string, initially set to the result of generating a random UUID.
  74. String m_navigation_api_key;
  75. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-navigation-api-id
  76. // navigation API ID, which is a string, initially set to the result of generating a random UUID.
  77. String m_navigation_api_id;
  78. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-scroll-restoration-mode
  79. // scroll restoration mode, a scroll restoration mode, initially "auto"
  80. ScrollRestorationMode m_scroll_restoration_mode { ScrollRestorationMode::Auto };
  81. // policy container, a policy container or null
  82. Optional<PolicyContainer> m_policy_container;
  83. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-scroll-position
  84. // FIXME: scroll position data, which is scroll position data for the document's restorable scrollable regions
  85. // browsing context name, a browsing context name or null, initially null
  86. Optional<ByteString> m_browsing_context_name;
  87. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#she-other
  88. // FIXME: persisted user state, which is implementation-defined, initially null
  89. // NOTE: This is where we could remember the state of form controls, for example.
  90. JS::GCPtr<BrowsingContext> m_original_source_browsing_context;
  91. };
  92. }