Navigable.h 4.4 KB

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