Navigable.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 <LibJS/Heap/Cell.h>
  9. #include <LibWeb/Forward.h>
  10. #include <LibWeb/HTML/HistoryHandlingBehavior.h>
  11. #include <LibWeb/HTML/POSTResource.h>
  12. namespace Web::HTML {
  13. // https://html.spec.whatwg.org/multipage/document-sequences.html#navigable
  14. class Navigable : public JS::Cell {
  15. JS_CELL(Navigable, JS::Cell);
  16. public:
  17. virtual ~Navigable() override;
  18. ErrorOr<void> initialize_navigable(JS::NonnullGCPtr<DocumentState> document_state, JS::GCPtr<Navigable> parent);
  19. String const& id() const { return m_id; };
  20. JS::GCPtr<Navigable> parent() const { return m_parent; };
  21. bool is_closing() const { return m_closing; };
  22. void set_closing(bool value) { m_closing = value; };
  23. bool is_delaying_load_events() const { return m_delaying_load_events; };
  24. void set_delaying_load_events(bool value) { m_delaying_load_events = value; };
  25. JS::GCPtr<SessionHistoryEntry> active_session_history_entry() const { return m_active_session_history_entry; };
  26. JS::GCPtr<SessionHistoryEntry> current_session_history_entry() const { return m_current_session_history_entry; };
  27. Vector<JS::NonnullGCPtr<SessionHistoryEntry>>& get_session_history_entries() const;
  28. JS::GCPtr<DOM::Document> active_document();
  29. JS::GCPtr<BrowsingContext> active_browsing_context();
  30. JS::GCPtr<WindowProxy> active_window_proxy();
  31. JS::GCPtr<Window> active_window();
  32. JS::GCPtr<SessionHistoryEntry> get_the_target_history_entry(int target_step) const;
  33. String target_name() const;
  34. JS::GCPtr<NavigableContainer> container() const;
  35. void set_container(JS::GCPtr<NavigableContainer>);
  36. JS::GCPtr<TraversableNavigable> traversable_navigable() const;
  37. JS::GCPtr<TraversableNavigable> top_level_traversable();
  38. static JS::GCPtr<Navigable> navigable_with_active_document(JS::NonnullGCPtr<DOM::Document>);
  39. enum class Traversal {
  40. Tag
  41. };
  42. Variant<Empty, Traversal, String> ongoing_navigation() const { return m_ongoing_navigation; }
  43. WebIDL::ExceptionOr<void> navigate(
  44. AK::URL const&,
  45. JS::NonnullGCPtr<DOM::Document> source_document,
  46. Variant<Empty, String, POSTResource> document_resource = Empty {},
  47. JS::GCPtr<Fetch::Infrastructure::Response> = nullptr,
  48. bool exceptions_enabled = false,
  49. HistoryHandlingBehavior = HistoryHandlingBehavior::Push,
  50. String csp_navigation_type = String::from_utf8_short_string("other"sv),
  51. ReferrerPolicy::ReferrerPolicy = ReferrerPolicy::ReferrerPolicy::EmptyString);
  52. WebIDL::ExceptionOr<void> navigate_to_a_fragment(AK::URL const&, HistoryHandlingBehavior, String navigation_id);
  53. WebIDL::ExceptionOr<void> navigate_to_a_javascript_url(AK::URL const&, HistoryHandlingBehavior, Origin const& initiator_origin, String csp_navigation_type);
  54. protected:
  55. Navigable();
  56. virtual void visit_edges(Cell::Visitor&) override;
  57. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#ongoing-navigation
  58. Variant<Empty, Traversal, String> m_ongoing_navigation;
  59. private:
  60. // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-id
  61. String m_id;
  62. // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-parent
  63. JS::GCPtr<Navigable> m_parent;
  64. // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-current-history-entry
  65. JS::GCPtr<SessionHistoryEntry> m_current_session_history_entry;
  66. // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-active-history-entry
  67. JS::GCPtr<SessionHistoryEntry> m_active_session_history_entry;
  68. // https://html.spec.whatwg.org/multipage/document-sequences.html#is-closing
  69. bool m_closing { false };
  70. // https://html.spec.whatwg.org/multipage/document-sequences.html#delaying-load-events-mode
  71. bool m_delaying_load_events { false };
  72. // Implied link between navigable and its container.
  73. JS::GCPtr<NavigableContainer> m_container;
  74. };
  75. }