Navigable.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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/ActivateTab.h>
  11. #include <LibWeb/HTML/HistoryHandlingBehavior.h>
  12. #include <LibWeb/HTML/POSTResource.h>
  13. #include <LibWeb/HTML/SourceSnapshotParams.h>
  14. #include <LibWeb/HTML/TokenizedFeatures.h>
  15. namespace Web::HTML {
  16. enum class CSPNavigationType {
  17. Other,
  18. FormSubmission,
  19. };
  20. // https://html.spec.whatwg.org/multipage/document-sequences.html#navigable
  21. class Navigable : public JS::Cell {
  22. JS_CELL(Navigable, JS::Cell);
  23. public:
  24. virtual ~Navigable() override;
  25. ErrorOr<void> initialize_navigable(JS::NonnullGCPtr<DocumentState> document_state, JS::GCPtr<Navigable> parent);
  26. Vector<JS::Handle<Navigable>> child_navigables() const;
  27. String const& id() const { return m_id; };
  28. JS::GCPtr<Navigable> parent() const { return m_parent; };
  29. bool is_closing() const { return m_closing; };
  30. void set_closing(bool value) { m_closing = value; };
  31. bool is_delaying_load_events() const { return m_delaying_load_events; };
  32. void set_delaying_load_events(bool value) { m_delaying_load_events = value; };
  33. JS::GCPtr<SessionHistoryEntry> active_session_history_entry() const { return m_active_session_history_entry; };
  34. JS::GCPtr<SessionHistoryEntry> current_session_history_entry() const { return m_current_session_history_entry; };
  35. void set_current_session_history_entry(JS::GCPtr<SessionHistoryEntry> entry) { m_current_session_history_entry = entry; };
  36. Vector<JS::NonnullGCPtr<SessionHistoryEntry>>& get_session_history_entries() const;
  37. void activate_history_entry(JS::GCPtr<SessionHistoryEntry>);
  38. JS::GCPtr<DOM::Document> active_document();
  39. JS::GCPtr<BrowsingContext> active_browsing_context();
  40. JS::GCPtr<WindowProxy> active_window_proxy();
  41. JS::GCPtr<Window> active_window();
  42. JS::GCPtr<SessionHistoryEntry> get_the_target_history_entry(int target_step) const;
  43. String target_name() const;
  44. JS::GCPtr<NavigableContainer> container() const;
  45. JS::GCPtr<DOM::Document> container_document() const;
  46. JS::GCPtr<TraversableNavigable> traversable_navigable() const;
  47. JS::GCPtr<TraversableNavigable> top_level_traversable();
  48. enum class WindowType {
  49. ExistingOrNone,
  50. NewAndUnrestricted,
  51. NewWithNoOpener,
  52. };
  53. struct ChosenNavigable {
  54. JS::GCPtr<Navigable> navigable;
  55. WindowType window_type;
  56. };
  57. ChosenNavigable choose_a_navigable(StringView name, TokenizedFeature::NoOpener no_opener, ActivateTab = ActivateTab::Yes);
  58. static JS::GCPtr<Navigable> navigable_with_active_document(JS::NonnullGCPtr<DOM::Document>);
  59. enum class Traversal {
  60. Tag
  61. };
  62. Variant<Empty, Traversal, String> ongoing_navigation() const { return m_ongoing_navigation; }
  63. WebIDL::ExceptionOr<void> populate_session_history_entry_document(JS::GCPtr<SessionHistoryEntry>, Optional<NavigationParams>, Optional<String> navigation_id, SourceSnapshotParams const&, Function<void()>);
  64. WebIDL::ExceptionOr<void> navigate(
  65. AK::URL const&,
  66. JS::NonnullGCPtr<DOM::Document> source_document,
  67. Variant<Empty, String, POSTResource> document_resource = Empty {},
  68. JS::GCPtr<Fetch::Infrastructure::Response> = nullptr,
  69. bool exceptions_enabled = false,
  70. HistoryHandlingBehavior = HistoryHandlingBehavior::Push,
  71. CSPNavigationType csp_navigation_type = CSPNavigationType::Other,
  72. ReferrerPolicy::ReferrerPolicy = ReferrerPolicy::ReferrerPolicy::EmptyString);
  73. WebIDL::ExceptionOr<void> navigate_to_a_fragment(AK::URL const&, HistoryHandlingBehavior, String navigation_id);
  74. WebIDL::ExceptionOr<void> navigate_to_a_javascript_url(AK::URL const&, HistoryHandlingBehavior, Origin const& initiator_origin, CSPNavigationType csp_navigation_type);
  75. void reload();
  76. protected:
  77. Navigable();
  78. virtual void visit_edges(Cell::Visitor&) override;
  79. // https://html.spec.whatwg.org/multipage/browsing-the-web.html#ongoing-navigation
  80. Variant<Empty, Traversal, String> m_ongoing_navigation;
  81. private:
  82. // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-id
  83. String m_id;
  84. // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-parent
  85. JS::GCPtr<Navigable> m_parent;
  86. // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-current-history-entry
  87. JS::GCPtr<SessionHistoryEntry> m_current_session_history_entry;
  88. // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-active-history-entry
  89. JS::GCPtr<SessionHistoryEntry> m_active_session_history_entry;
  90. // https://html.spec.whatwg.org/multipage/document-sequences.html#is-closing
  91. bool m_closing { false };
  92. // https://html.spec.whatwg.org/multipage/document-sequences.html#delaying-load-events-mode
  93. bool m_delaying_load_events { false };
  94. // Implied link between navigable and its container.
  95. JS::GCPtr<NavigableContainer> m_container;
  96. };
  97. }