Navigable.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. JS::GCPtr<DOM::Document> active_document();
  28. JS::GCPtr<BrowsingContext> active_browsing_context();
  29. JS::GCPtr<WindowProxy> active_window_proxy();
  30. JS::GCPtr<Window> active_window();
  31. String target_name() const;
  32. JS::GCPtr<NavigableContainer> container() const;
  33. void set_container(JS::GCPtr<NavigableContainer>);
  34. JS::GCPtr<TraversableNavigable> traversable_navigable();
  35. JS::GCPtr<TraversableNavigable> top_level_traversable();
  36. static JS::GCPtr<Navigable> navigable_with_active_document(JS::NonnullGCPtr<DOM::Document>);
  37. enum class Traversal {
  38. Tag
  39. };
  40. Variant<Empty, Traversal, String> ongoing_navigation() const { return m_ongoing_navigation; }
  41. WebIDL::ExceptionOr<void> navigate(
  42. AK::URL const&,
  43. JS::NonnullGCPtr<DOM::Document> source_document,
  44. Variant<Empty, String, POSTResource> document_resource = Empty {},
  45. JS::GCPtr<Fetch::Infrastructure::Response> = nullptr,
  46. bool exceptions_enabled = false,
  47. HistoryHandlingBehavior = HistoryHandlingBehavior::Push,
  48. String csp_navigation_type = String::from_utf8_short_string("other"sv),
  49. ReferrerPolicy::ReferrerPolicy = ReferrerPolicy::ReferrerPolicy::EmptyString);
  50. WebIDL::ExceptionOr<void> navigate_to_a_fragment(AK::URL const&, HistoryHandlingBehavior, String navigation_id);
  51. WebIDL::ExceptionOr<void> navigate_to_a_javascript_url(AK::URL const&, HistoryHandlingBehavior, Origin const& initiator_origin, String csp_navigation_type);
  52. protected:
  53. Navigable();
  54. virtual void visit_edges(Cell::Visitor&) override;
  55. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#ongoing-navigation
  56. Variant<Empty, Traversal, String> m_ongoing_navigation;
  57. private:
  58. // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-id
  59. String m_id;
  60. // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-parent
  61. JS::GCPtr<Navigable> m_parent;
  62. // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-current-history-entry
  63. JS::GCPtr<SessionHistoryEntry> m_current_session_history_entry;
  64. // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-active-history-entry
  65. JS::GCPtr<SessionHistoryEntry> m_active_session_history_entry;
  66. // https://html.spec.whatwg.org/multipage/document-sequences.html#is-closing
  67. bool m_closing { false };
  68. // https://html.spec.whatwg.org/multipage/document-sequences.html#delaying-load-events-mode
  69. bool m_delaying_load_events { false };
  70. // Implied link between navigable and its container.
  71. JS::GCPtr<NavigableContainer> m_container;
  72. };
  73. }