Navigable.h 5.2 KB

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