TraversableNavigable.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <andreas@ladybird.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 <LibGfx/MetalContext.h>
  17. #endif
  18. #ifdef USE_VULKAN
  19. # include <LibGfx/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. GC_CELL(TraversableNavigable, Navigable);
  25. GC_DECLARE_ALLOCATOR(TraversableNavigable);
  26. public:
  27. static WebIDL::ExceptionOr<GC::Ref<TraversableNavigable>> create_a_new_top_level_traversable(GC::Ref<Page>, GC::Ptr<BrowsingContext> opener, String target_name);
  28. static WebIDL::ExceptionOr<GC::Ref<TraversableNavigable>> create_a_fresh_top_level_traversable(GC::Ref<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<GC::Ref<SessionHistoryEntry>>& session_history_entries() { return m_session_history_entries; }
  33. Vector<GC::Ref<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>, GC::Ptr<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<GC::Root<Navigable>> get_all_navigables_whose_current_session_history_entry_will_change_or_reload(int) const;
  58. Vector<GC::Root<Navigable>> get_all_navigables_that_only_need_history_object_length_index_update(int) const;
  59. Vector<GC::Root<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 definitely_close_top_level_traversable();
  65. void destroy_top_level_traversable();
  66. void append_session_history_traversal_steps(GC::Ref<GC::Function<void()>> steps)
  67. {
  68. m_session_history_traversal_queue->append(steps);
  69. }
  70. void append_session_history_synchronous_navigation_steps(GC::Ref<Navigable> target_navigable, GC::Ref<GC::Function<void()>> steps)
  71. {
  72. m_session_history_traversal_queue->append_sync(steps, target_navigable);
  73. }
  74. String window_handle() const { return m_window_handle; }
  75. void set_window_handle(String window_handle) { m_window_handle = move(window_handle); }
  76. [[nodiscard]] GC::Ptr<DOM::Node> currently_focused_area();
  77. void paint(Web::DevicePixelRect const&, Painting::BackingStore&, Web::PaintOptions);
  78. enum class CheckIfUnloadingIsCanceledResult {
  79. CanceledByBeforeUnload,
  80. CanceledByNavigate,
  81. Continue,
  82. };
  83. CheckIfUnloadingIsCanceledResult check_if_unloading_is_canceled(Vector<GC::Root<Navigable>> navigables_that_need_before_unload);
  84. RefPtr<Gfx::SkiaBackendContext> skia_backend_context() const { return m_skia_backend_context; }
  85. private:
  86. TraversableNavigable(GC::Ref<Page>);
  87. virtual void visit_edges(Cell::Visitor&) override;
  88. // FIXME: Fix spec typo cancelation --> cancellation
  89. HistoryStepResult apply_the_history_step(
  90. int step,
  91. bool check_for_cancelation,
  92. Optional<SourceSnapshotParams>,
  93. GC::Ptr<Navigable> initiator_to_check,
  94. Optional<UserNavigationInvolvement> user_involvement_for_navigate_events,
  95. Optional<Bindings::NavigationType> navigation_type,
  96. SynchronousNavigation);
  97. CheckIfUnloadingIsCanceledResult check_if_unloading_is_canceled(Vector<GC::Root<Navigable>> navigables_that_need_before_unload, GC::Ptr<TraversableNavigable> traversable, Optional<int> target_step, Optional<UserNavigationInvolvement> user_involvement_for_navigate_events);
  98. Vector<GC::Ref<SessionHistoryEntry>> get_session_history_entries_for_the_navigation_api(GC::Ref<Navigable>, int);
  99. [[nodiscard]] bool can_go_forward() const;
  100. // https://html.spec.whatwg.org/multipage/document-sequences.html#tn-current-session-history-step
  101. int m_current_session_history_step { 0 };
  102. // https://html.spec.whatwg.org/multipage/document-sequences.html#tn-session-history-entries
  103. Vector<GC::Ref<SessionHistoryEntry>> m_session_history_entries;
  104. // FIXME: https://html.spec.whatwg.org/multipage/document-sequences.html#tn-session-history-traversal-queue
  105. // https://html.spec.whatwg.org/multipage/document-sequences.html#tn-running-nested-apply-history-step
  106. bool m_running_nested_apply_history_step { false };
  107. // https://html.spec.whatwg.org/multipage/document-sequences.html#system-visibility-state
  108. VisibilityState m_system_visibility_state { VisibilityState::Hidden };
  109. GC::Ref<SessionHistoryTraversalQueue> m_session_history_traversal_queue;
  110. String m_window_handle;
  111. RefPtr<Gfx::SkiaBackendContext> m_skia_backend_context;
  112. #ifdef AK_OS_MACOS
  113. OwnPtr<Gfx::MetalContext> m_metal_context;
  114. #endif
  115. };
  116. struct BrowsingContextAndDocument {
  117. GC::Ref<HTML::BrowsingContext> browsing_context;
  118. GC::Ref<DOM::Document> document;
  119. };
  120. WebIDL::ExceptionOr<BrowsingContextAndDocument> create_a_new_top_level_browsing_context_and_document(GC::Ref<Page> page);
  121. void finalize_a_same_document_navigation(GC::Ref<TraversableNavigable> traversable, GC::Ref<Navigable> target_navigable, GC::Ref<SessionHistoryEntry> target_entry, GC::Ptr<SessionHistoryEntry> entry_to_replace, HistoryHandlingBehavior);
  122. }