TraversableNavigable.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Vector.h>
  8. #include <LibWeb/HTML/Navigable.h>
  9. #include <LibWeb/HTML/NavigationType.h>
  10. #include <LibWeb/HTML/SessionHistoryTraversalQueue.h>
  11. #include <LibWeb/HTML/VisibilityState.h>
  12. #include <LibWeb/Page/Page.h>
  13. #include <LibWeb/Painting/DisplayListPlayerSkia.h>
  14. #include <WebContent/BackingStoreManager.h>
  15. #ifdef AK_OS_MACOS
  16. # include <LibCore/MetalContext.h>
  17. #endif
  18. #ifdef USE_VULKAN
  19. # include <LibCore/VulkanContext.h>
  20. #endif
  21. namespace Web::HTML {
  22. // https://html.spec.whatwg.org/multipage/document-sequences.html#traversable-navigable
  23. class TraversableNavigable final : public Navigable {
  24. JS_CELL(TraversableNavigable, Navigable);
  25. JS_DECLARE_ALLOCATOR(TraversableNavigable);
  26. public:
  27. static WebIDL::ExceptionOr<JS::NonnullGCPtr<TraversableNavigable>> create_a_new_top_level_traversable(JS::NonnullGCPtr<Page>, JS::GCPtr<BrowsingContext> opener, String target_name);
  28. static WebIDL::ExceptionOr<JS::NonnullGCPtr<TraversableNavigable>> create_a_fresh_top_level_traversable(JS::NonnullGCPtr<Page>, URL::URL const& initial_navigation_url, Variant<Empty, String, POSTResource> = Empty {});
  29. virtual ~TraversableNavigable() override;
  30. virtual bool is_top_level_traversable() const override;
  31. int current_session_history_step() const { return m_current_session_history_step; }
  32. Vector<JS::NonnullGCPtr<SessionHistoryEntry>>& session_history_entries() { return m_session_history_entries; }
  33. Vector<JS::NonnullGCPtr<SessionHistoryEntry>> const& session_history_entries() const { return m_session_history_entries; }
  34. bool running_nested_apply_history_step() const { return m_running_nested_apply_history_step; }
  35. VisibilityState system_visibility_state() const { return m_system_visibility_state; }
  36. void set_system_visibility_state(VisibilityState);
  37. struct HistoryObjectLengthAndIndex {
  38. u64 script_history_length;
  39. u64 script_history_index;
  40. };
  41. HistoryObjectLengthAndIndex get_the_history_object_length_and_index(int) const;
  42. enum class HistoryStepResult {
  43. InitiatorDisallowed,
  44. CanceledByBeforeUnload,
  45. CanceledByNavigate,
  46. Applied,
  47. };
  48. HistoryStepResult apply_the_traverse_history_step(int, Optional<SourceSnapshotParams>, JS::GCPtr<Navigable>, UserNavigationInvolvement);
  49. HistoryStepResult apply_the_reload_history_step();
  50. enum class SynchronousNavigation : bool {
  51. Yes,
  52. No,
  53. };
  54. HistoryStepResult apply_the_push_or_replace_history_step(int step, HistoryHandlingBehavior history_handling, SynchronousNavigation);
  55. HistoryStepResult update_for_navigable_creation_or_destruction();
  56. int get_the_used_step(int step) const;
  57. Vector<JS::Handle<Navigable>> get_all_navigables_whose_current_session_history_entry_will_change_or_reload(int) const;
  58. Vector<JS::Handle<Navigable>> get_all_navigables_that_only_need_history_object_length_index_update(int) const;
  59. Vector<JS::Handle<Navigable>> get_all_navigables_that_might_experience_a_cross_document_traversal(int) const;
  60. Vector<int> get_all_used_history_steps() const;
  61. void clear_the_forward_session_history();
  62. void traverse_the_history_by_delta(int delta, Optional<DOM::Document&> source_document = {});
  63. void close_top_level_traversable();
  64. void destroy_top_level_traversable();
  65. void append_session_history_traversal_steps(JS::NonnullGCPtr<JS::HeapFunction<void()>> steps)
  66. {
  67. m_session_history_traversal_queue->append(steps);
  68. }
  69. void append_session_history_synchronous_navigation_steps(JS::NonnullGCPtr<Navigable> target_navigable, JS::NonnullGCPtr<JS::HeapFunction<void()>> steps)
  70. {
  71. m_session_history_traversal_queue->append_sync(steps, target_navigable);
  72. }
  73. String window_handle() const { return m_window_handle; }
  74. void set_window_handle(String window_handle) { m_window_handle = move(window_handle); }
  75. [[nodiscard]] JS::GCPtr<DOM::Node> currently_focused_area();
  76. void paint(Web::DevicePixelRect const&, Painting::BackingStore&, Web::PaintOptions);
  77. private:
  78. TraversableNavigable(JS::NonnullGCPtr<Page>);
  79. virtual void visit_edges(Cell::Visitor&) override;
  80. // FIXME: Fix spec typo cancelation --> cancellation
  81. HistoryStepResult apply_the_history_step(
  82. int step,
  83. bool check_for_cancelation,
  84. Optional<SourceSnapshotParams>,
  85. JS::GCPtr<Navigable> initiator_to_check,
  86. Optional<UserNavigationInvolvement> user_involvement_for_navigate_events,
  87. Optional<Bindings::NavigationType> navigation_type,
  88. SynchronousNavigation);
  89. Vector<JS::NonnullGCPtr<SessionHistoryEntry>> get_session_history_entries_for_the_navigation_api(JS::NonnullGCPtr<Navigable>, int);
  90. [[nodiscard]] bool can_go_forward() const;
  91. // https://html.spec.whatwg.org/multipage/document-sequences.html#tn-current-session-history-step
  92. int m_current_session_history_step { 0 };
  93. // https://html.spec.whatwg.org/multipage/document-sequences.html#tn-session-history-entries
  94. Vector<JS::NonnullGCPtr<SessionHistoryEntry>> m_session_history_entries;
  95. // FIXME: https://html.spec.whatwg.org/multipage/document-sequences.html#tn-session-history-traversal-queue
  96. // https://html.spec.whatwg.org/multipage/document-sequences.html#tn-running-nested-apply-history-step
  97. bool m_running_nested_apply_history_step { false };
  98. // https://html.spec.whatwg.org/multipage/document-sequences.html#system-visibility-state
  99. VisibilityState m_system_visibility_state { VisibilityState::Visible };
  100. JS::NonnullGCPtr<SessionHistoryTraversalQueue> m_session_history_traversal_queue;
  101. String m_window_handle;
  102. OwnPtr<Web::Painting::SkiaBackendContext> m_skia_backend_context;
  103. #ifdef AK_OS_MACOS
  104. OwnPtr<Core::MetalContext> m_metal_context;
  105. #endif
  106. };
  107. struct BrowsingContextAndDocument {
  108. JS::NonnullGCPtr<HTML::BrowsingContext> browsing_context;
  109. JS::NonnullGCPtr<DOM::Document> document;
  110. };
  111. WebIDL::ExceptionOr<BrowsingContextAndDocument> create_a_new_top_level_browsing_context_and_document(JS::NonnullGCPtr<Page> page);
  112. void finalize_a_same_document_navigation(JS::NonnullGCPtr<TraversableNavigable> traversable, JS::NonnullGCPtr<Navigable> target_navigable, JS::NonnullGCPtr<SessionHistoryEntry> target_entry, JS::GCPtr<SessionHistoryEntry> entry_to_replace, HistoryHandlingBehavior);
  113. }