DocumentState.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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/Fetch/Infrastructure/HTTP/Requests.h>
  11. #include <LibWeb/Forward.h>
  12. #include <LibWeb/HTML/Origin.h>
  13. #include <LibWeb/HTML/POSTResource.h>
  14. #include <LibWeb/HTML/PolicyContainers.h>
  15. #include <LibWeb/ReferrerPolicy/ReferrerPolicy.h>
  16. namespace Web::HTML {
  17. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-2
  18. class DocumentState final : public JS::Cell {
  19. JS_CELL(DocumentState, JS::Cell);
  20. public:
  21. struct NestedHistory {
  22. String id;
  23. Vector<JS::NonnullGCPtr<SessionHistoryEntry>> entries;
  24. };
  25. virtual ~DocumentState();
  26. enum class Client {
  27. Tag,
  28. };
  29. [[nodiscard]] JS::GCPtr<DOM::Document> document() const { return m_document; }
  30. void set_document(JS::GCPtr<DOM::Document> document) { m_document = document; }
  31. [[nodiscard]] Variant<PolicyContainer, Client> history_policy_container() const { return m_history_policy_container; }
  32. void set_history_policy_container(Variant<PolicyContainer, Client> history_policy_container) { m_history_policy_container = move(history_policy_container); }
  33. [[nodiscard]] Fetch::Infrastructure::Request::ReferrerType request_referrer() const { return m_request_referrer; }
  34. void set_request_referrer(Fetch::Infrastructure::Request::ReferrerType request_referrer) { m_request_referrer = move(request_referrer); }
  35. [[nodiscard]] ReferrerPolicy::ReferrerPolicy request_referrer_policy() const { return m_request_referrer_policy; }
  36. void set_request_referrer_policy(ReferrerPolicy::ReferrerPolicy request_referrer_policy) { m_request_referrer_policy = move(request_referrer_policy); }
  37. [[nodiscard]] Optional<HTML::Origin> initiator_origin() const { return m_initiator_origin; }
  38. void set_initiator_origin(Optional<HTML::Origin> initiator_origin) { m_initiator_origin = move(initiator_origin); }
  39. [[nodiscard]] Optional<HTML::Origin> origin() const { return m_origin; }
  40. void set_origin(Optional<HTML::Origin> origin) { m_origin = move(origin); }
  41. [[nodiscard]] Optional<AK::URL> const& about_base_url() const { return m_about_base_url; }
  42. void set_about_base_url(Optional<AK::URL> url) { m_about_base_url = move(url); }
  43. [[nodiscard]] Vector<NestedHistory> const& nested_histories() const { return m_nested_histories; }
  44. [[nodiscard]] Vector<NestedHistory>& nested_histories() { return m_nested_histories; }
  45. [[nodiscard]] Variant<Empty, String, POSTResource> resource() const { return m_resource; }
  46. void set_resource(Variant<Empty, String, POSTResource> resource) { m_resource = move(resource); }
  47. [[nodiscard]] bool reload_pending() const { return m_reload_pending; }
  48. void set_reload_pending(bool reload_pending) { m_reload_pending = reload_pending; }
  49. [[nodiscard]] bool ever_populated() const { return m_ever_populated; }
  50. void set_ever_populated(bool ever_populated) { m_ever_populated = ever_populated; }
  51. [[nodiscard]] String navigable_target_name() const { return m_navigable_target_name; }
  52. void set_navigable_target_name(String navigable_target_name) { m_navigable_target_name = navigable_target_name; }
  53. private:
  54. DocumentState();
  55. void visit_edges(Cell::Visitor&) override;
  56. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-document
  57. JS::GCPtr<DOM::Document> m_document;
  58. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-history-policy-container
  59. Variant<PolicyContainer, Client> m_history_policy_container { Client::Tag };
  60. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-request-referrer
  61. Fetch::Infrastructure::Request::ReferrerType m_request_referrer { Fetch::Infrastructure::Request::Referrer::Client };
  62. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-request-referrer-policy
  63. ReferrerPolicy::ReferrerPolicy m_request_referrer_policy { ReferrerPolicy::DEFAULT_REFERRER_POLICY };
  64. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-initiator-origin
  65. Optional<HTML::Origin> m_initiator_origin;
  66. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-origin
  67. Optional<HTML::Origin> m_origin;
  68. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-about-base-url
  69. Optional<AK::URL> m_about_base_url = {};
  70. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-nested-histories
  71. Vector<NestedHistory> m_nested_histories;
  72. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-resource
  73. Variant<Empty, String, POSTResource> m_resource {};
  74. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-reload-pending
  75. bool m_reload_pending { false };
  76. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-ever-populated
  77. bool m_ever_populated { false };
  78. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-nav-target-name
  79. String m_navigable_target_name;
  80. };
  81. }