DocumentState.h 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. virtual ~DocumentState();
  20. enum class Client {
  21. Tag,
  22. };
  23. enum class NoReferrer {
  24. Tag,
  25. };
  26. [[nodiscard]] JS::GCPtr<DOM::Document> document() const { return m_document; }
  27. void set_document(JS::GCPtr<DOM::Document> document) { m_document = document; }
  28. [[nodiscard]] Variant<PolicyContainer, Client> history_policy_container() const { return m_history_policy_container; }
  29. void set_history_policy_container(Variant<PolicyContainer, Client> history_policy_container) { m_history_policy_container = move(history_policy_container); }
  30. [[nodiscard]] Variant<NoReferrer, Client, AK::URL> request_referrer() const { return m_request_referrer; }
  31. void set_request_referrer(Variant<NoReferrer, Client, AK::URL> request_referrer) { m_request_referrer = move(request_referrer); }
  32. [[nodiscard]] ReferrerPolicy::ReferrerPolicy request_referrer_policy() const { return m_request_referrer_policy; }
  33. void set_request_referrer_policy(ReferrerPolicy::ReferrerPolicy request_referrer_policy) { m_request_referrer_policy = move(request_referrer_policy); }
  34. [[nodiscard]] Optional<HTML::Origin> initiator_origin() const { return m_initiator_origin; }
  35. void set_initiator_origin(Optional<HTML::Origin> initiator_origin) { m_initiator_origin = move(initiator_origin); }
  36. [[nodiscard]] Optional<HTML::Origin> origin() const { return m_origin; }
  37. void set_origin(Optional<HTML::Origin> origin) { m_origin = move(origin); }
  38. [[nodiscard]] bool reload_pending() const { return m_reload_pending; }
  39. void set_reload_pending(bool reload_pending) { m_reload_pending = reload_pending; }
  40. [[nodiscard]] bool ever_populated() const { return m_ever_populated; }
  41. void set_ever_populated(bool ever_populated) { m_ever_populated = ever_populated; }
  42. [[nodiscard]] String ever_navigable_target_name() const { return m_navigable_target_name; }
  43. void set_navigable_target_name(String navigable_target_name) { m_navigable_target_name = navigable_target_name; }
  44. private:
  45. DocumentState();
  46. void visit_edges(Cell::Visitor&) override;
  47. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-document
  48. JS::GCPtr<DOM::Document> m_document;
  49. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-history-policy-container
  50. Variant<PolicyContainer, Client> m_history_policy_container { Client::Tag };
  51. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-request-referrer
  52. Variant<NoReferrer, Client, AK::URL> m_request_referrer { Client::Tag };
  53. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-request-referrer-policy
  54. ReferrerPolicy::ReferrerPolicy m_request_referrer_policy { ReferrerPolicy::DEFAULT_REFERRER_POLICY };
  55. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-initiator-origin
  56. Optional<HTML::Origin> m_initiator_origin;
  57. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-origin
  58. Optional<HTML::Origin> m_origin;
  59. // FIXME: https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-nested-histories
  60. // FIXME: https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-resource
  61. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-reload-pending
  62. bool m_reload_pending { false };
  63. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-ever-populated
  64. bool m_ever_populated { false };
  65. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state-nav-target-name
  66. String m_navigable_target_name;
  67. };
  68. }