Navigable.h 4.4 KB

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