DocumentState.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/URL.h>
  9. #include <LibJS/Heap/Cell.h>
  10. #include <LibWeb/Forward.h>
  11. #include <LibWeb/HTML/Origin.h>
  12. #include <LibWeb/HTML/PolicyContainers.h>
  13. #include <LibWeb/ReferrerPolicy/ReferrerPolicy.h>
  14. namespace Web::HTML {
  15. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-2
  16. class DocumentState final : public JS::Cell {
  17. JS_CELL(DocumentState, JS::Cell);
  18. public:
  19. struct NestedHistory {
  20. String id;
  21. Vector<JS::NonnullGCPtr<SessionHistoryEntry>> entries;
  22. };
  23. virtual ~DocumentState();
  24. enum class Client {
  25. Tag,
  26. };
  27. enum class NoReferrer {
  28. Tag,
  29. };
  30. [[nodiscard]] JS::GCPtr<DOM::Document> document() const { return m_document; }
  31. void set_document(JS::GCPtr<DOM::Document> document) { m_document = document; }
  32. [[nodiscard]] Variant<PolicyContainer, Client> history_policy_container() const { return m_history_policy_container; }
  33. void set_history_policy_container(Variant<PolicyContainer, Client> history_policy_container) { m_history_policy_container = move(history_policy_container); }
  34. [[nodiscard]] Variant<NoReferrer, Client, AK::URL> request_referrer() const { return m_request_referrer; }
  35. void set_request_referrer(Variant<NoReferrer, Client, AK::URL> request_referrer) { m_request_referrer = move(request_referrer); }
  36. [[nodiscard]] ReferrerPolicy::ReferrerPolicy request_referrer_policy() const { return m_request_referrer_policy; }
  37. void set_request_referrer_policy(ReferrerPolicy::ReferrerPolicy request_referrer_policy) { m_request_referrer_policy = move(request_referrer_policy); }
  38. [[nodiscard]] Optional<HTML::Origin> initiator_origin() const { return m_initiator_origin; }
  39. void set_initiator_origin(Optional<HTML::Origin> initiator_origin) { m_initiator_origin = move(initiator_origin); }
  40. [[nodiscard]] Optional<HTML::Origin> origin() const { return m_origin; }
  41. void set_origin(Optional<HTML::Origin> origin) { m_origin = move(origin); }
  42. [[nodiscard]] Vector<NestedHistory> const& nested_histories() const { return m_nested_histories; }
  43. [[nodiscard]] Vector<NestedHistory>& nested_histories() { return m_nested_histories; }
  44. [[nodiscard]] bool reload_pending() const { return m_reload_pending; }
  45. void set_reload_pending(bool reload_pending) { m_reload_pending = reload_pending; }
  46. [[nodiscard]] bool ever_populated() const { return m_ever_populated; }
  47. void set_ever_populated(bool ever_populated) { m_ever_populated = ever_populated; }
  48. [[nodiscard]] String ever_navigable_target_name() const { return m_navigable_target_name; }
  49. void set_navigable_target_name(String navigable_target_name) { m_navigable_target_name = navigable_target_name; }
  50. private:
  51. DocumentState();
  52. void visit_edges(Cell::Visitor&) override;
  53. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-document
  54. JS::GCPtr<DOM::Document> m_document;
  55. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-history-policy-container
  56. Variant<PolicyContainer, Client> m_history_policy_container { Client::Tag };
  57. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-request-referrer
  58. Variant<NoReferrer, Client, AK::URL> m_request_referrer { Client::Tag };
  59. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-request-referrer-policy
  60. ReferrerPolicy::ReferrerPolicy m_request_referrer_policy { ReferrerPolicy::DEFAULT_REFERRER_POLICY };
  61. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-initiator-origin
  62. Optional<HTML::Origin> m_initiator_origin;
  63. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-origin
  64. Optional<HTML::Origin> m_origin;
  65. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-nested-histories
  66. Vector<NestedHistory> m_nested_histories;
  67. // FIXME: https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-resource
  68. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-reload-pending
  69. bool m_reload_pending { false };
  70. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-ever-populated
  71. bool m_ever_populated { false };
  72. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-nav-target-name
  73. String m_navigable_target_name;
  74. };
  75. }