| 
									
										
										
										
											2022-12-12 12:01:09 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:19:50 +02:00
										 |  |  |  * Copyright (c) 2022, Andreas Kling <andreas@ladybird.org> | 
					
						
							| 
									
										
										
										
											2022-12-12 12:01:09 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/Vector.h>
 | 
					
						
							|  |  |  | #include <LibWeb/HTML/Navigable.h>
 | 
					
						
							| 
									
										
										
										
											2024-03-28 12:19:57 +01:00
										 |  |  | #include <LibWeb/HTML/NavigationType.h>
 | 
					
						
							| 
									
										
										
										
											2023-07-25 01:22:57 +02:00
										 |  |  | #include <LibWeb/HTML/SessionHistoryTraversalQueue.h>
 | 
					
						
							| 
									
										
										
										
											2022-12-12 12:01:09 +01:00
										 |  |  | #include <LibWeb/HTML/VisibilityState.h>
 | 
					
						
							| 
									
										
										
										
											2024-06-10 02:58:32 +03:00
										 |  |  | #include <LibWeb/Page/Page.h>
 | 
					
						
							| 
									
										
										
										
											2024-06-26 17:56:55 +02:00
										 |  |  | #include <LibWeb/Painting/DisplayListPlayerSkia.h>
 | 
					
						
							| 
									
										
										
										
											2024-06-25 16:43:39 +02:00
										 |  |  | #include <WebContent/BackingStoreManager.h>
 | 
					
						
							| 
									
										
										
										
											2022-12-12 12:01:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-26 17:56:55 +02:00
										 |  |  | #ifdef AK_OS_MACOS
 | 
					
						
							| 
									
										
										
										
											2024-09-26 17:01:07 +02:00
										 |  |  | #    include <LibGfx/MetalContext.h>
 | 
					
						
							| 
									
										
										
										
											2024-06-26 17:56:55 +02:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-03 19:23:27 +02:00
										 |  |  | #ifdef USE_VULKAN
 | 
					
						
							|  |  |  | #    include <LibCore/VulkanContext.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-12 12:01:09 +01:00
										 |  |  | namespace Web::HTML { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://html.spec.whatwg.org/multipage/document-sequences.html#traversable-navigable
 | 
					
						
							|  |  |  | class TraversableNavigable final : public Navigable { | 
					
						
							|  |  |  |     JS_CELL(TraversableNavigable, Navigable); | 
					
						
							| 
									
										
										
										
											2023-11-19 19:47:52 +01:00
										 |  |  |     JS_DECLARE_ALLOCATOR(TraversableNavigable); | 
					
						
							| 
									
										
										
										
											2022-12-12 12:01:09 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2023-12-03 16:56:04 +13:00
										 |  |  |     static WebIDL::ExceptionOr<JS::NonnullGCPtr<TraversableNavigable>> create_a_new_top_level_traversable(JS::NonnullGCPtr<Page>, JS::GCPtr<BrowsingContext> opener, String target_name); | 
					
						
							| 
									
										
										
										
											2024-03-18 16:22:27 +13:00
										 |  |  |     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 {}); | 
					
						
							| 
									
										
										
										
											2022-12-17 14:26:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-12 12:01:09 +01:00
										 |  |  |     virtual ~TraversableNavigable() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-28 18:00:52 +02:00
										 |  |  |     virtual bool is_top_level_traversable() const override; | 
					
						
							| 
									
										
										
										
											2022-12-12 12:01:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-07 22:48:11 -04:00
										 |  |  |     int current_session_history_step() const { return m_current_session_history_step; } | 
					
						
							|  |  |  |     Vector<JS::NonnullGCPtr<SessionHistoryEntry>>& session_history_entries() { return m_session_history_entries; } | 
					
						
							|  |  |  |     Vector<JS::NonnullGCPtr<SessionHistoryEntry>> const& session_history_entries() const { return m_session_history_entries; } | 
					
						
							|  |  |  |     bool running_nested_apply_history_step() const { return m_running_nested_apply_history_step; } | 
					
						
							| 
									
										
										
										
											2023-09-19 20:24:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-07 22:48:11 -04:00
										 |  |  |     VisibilityState system_visibility_state() const { return m_system_visibility_state; } | 
					
						
							| 
									
										
										
										
											2023-09-19 20:24:18 +02:00
										 |  |  |     void set_system_visibility_state(VisibilityState); | 
					
						
							| 
									
										
										
										
											2022-12-12 12:01:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-13 10:18:46 +03:00
										 |  |  |     struct HistoryObjectLengthAndIndex { | 
					
						
							| 
									
										
										
										
											2023-09-23 22:59:27 +02:00
										 |  |  |         u64 script_history_length; | 
					
						
							|  |  |  |         u64 script_history_index; | 
					
						
							| 
									
										
										
										
											2023-04-13 10:18:46 +03:00
										 |  |  |     }; | 
					
						
							|  |  |  |     HistoryObjectLengthAndIndex get_the_history_object_length_and_index(int) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-27 23:23:00 -06:00
										 |  |  |     enum class HistoryStepResult { | 
					
						
							|  |  |  |         InitiatorDisallowed, | 
					
						
							|  |  |  |         CanceledByBeforeUnload, | 
					
						
							|  |  |  |         CanceledByNavigate, | 
					
						
							|  |  |  |         Applied, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     HistoryStepResult apply_the_traverse_history_step(int, Optional<SourceSnapshotParams>, JS::GCPtr<Navigable>, UserNavigationInvolvement); | 
					
						
							|  |  |  |     HistoryStepResult apply_the_reload_history_step(); | 
					
						
							| 
									
										
										
										
											2024-04-05 16:02:52 +02:00
										 |  |  |     enum class SynchronousNavigation : bool { | 
					
						
							|  |  |  |         Yes, | 
					
						
							|  |  |  |         No, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     HistoryStepResult apply_the_push_or_replace_history_step(int step, HistoryHandlingBehavior history_handling, SynchronousNavigation); | 
					
						
							| 
									
										
										
										
											2023-09-27 23:23:00 -06:00
										 |  |  |     HistoryStepResult update_for_navigable_creation_or_destruction(); | 
					
						
							| 
									
										
										
										
											2023-04-13 10:23:59 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-19 21:08:26 +03:00
										 |  |  |     int get_the_used_step(int step) const; | 
					
						
							| 
									
										
										
										
											2023-06-19 21:11:30 +03:00
										 |  |  |     Vector<JS::Handle<Navigable>> get_all_navigables_whose_current_session_history_entry_will_change_or_reload(int) const; | 
					
						
							| 
									
										
										
										
											2023-09-27 22:59:57 -06:00
										 |  |  |     Vector<JS::Handle<Navigable>> get_all_navigables_that_only_need_history_object_length_index_update(int) const; | 
					
						
							|  |  |  |     Vector<JS::Handle<Navigable>> get_all_navigables_that_might_experience_a_cross_document_traversal(int) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-13 10:11:31 +03:00
										 |  |  |     Vector<int> get_all_used_history_steps() const; | 
					
						
							| 
									
										
										
										
											2023-04-06 12:24:09 +03:00
										 |  |  |     void clear_the_forward_session_history(); | 
					
						
							| 
									
										
										
										
											2023-09-27 22:59:57 -06:00
										 |  |  |     void traverse_the_history_by_delta(int delta, Optional<DOM::Document&> source_document = {}); | 
					
						
							| 
									
										
										
										
											2023-04-13 10:11:31 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-17 10:37:46 +01:00
										 |  |  |     void close_top_level_traversable(); | 
					
						
							| 
									
										
										
										
											2024-10-09 06:36:15 -04:00
										 |  |  |     void definitely_close_top_level_traversable(); | 
					
						
							| 
									
										
										
										
											2022-12-17 10:19:35 +01:00
										 |  |  |     void destroy_top_level_traversable(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-18 17:45:56 +12:00
										 |  |  |     void append_session_history_traversal_steps(JS::NonnullGCPtr<JS::HeapFunction<void()>> steps) | 
					
						
							| 
									
										
										
										
											2023-07-25 01:22:57 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2024-08-18 17:45:56 +12:00
										 |  |  |         m_session_history_traversal_queue->append(steps); | 
					
						
							| 
									
										
										
										
											2023-07-25 01:22:57 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-18 17:45:56 +12:00
										 |  |  |     void append_session_history_synchronous_navigation_steps(JS::NonnullGCPtr<Navigable> target_navigable, JS::NonnullGCPtr<JS::HeapFunction<void()>> steps) | 
					
						
							| 
									
										
										
										
											2023-11-03 19:18:18 -06:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2024-08-18 17:45:56 +12:00
										 |  |  |         m_session_history_traversal_queue->append_sync(steps, target_navigable); | 
					
						
							| 
									
										
										
										
											2023-11-03 19:18:18 -06:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-30 20:55:24 -07:00
										 |  |  |     String window_handle() const { return m_window_handle; } | 
					
						
							|  |  |  |     void set_window_handle(String window_handle) { m_window_handle = move(window_handle); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-26 16:59:04 +02:00
										 |  |  |     [[nodiscard]] JS::GCPtr<DOM::Node> currently_focused_area(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-25 16:43:39 +02:00
										 |  |  |     void paint(Web::DevicePixelRect const&, Painting::BackingStore&, Web::PaintOptions); | 
					
						
							| 
									
										
										
										
											2024-06-10 02:58:32 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-02 23:56:26 +01:00
										 |  |  |     enum class CheckIfUnloadingIsCanceledResult { | 
					
						
							|  |  |  |         CanceledByBeforeUnload, | 
					
						
							|  |  |  |         CanceledByNavigate, | 
					
						
							|  |  |  |         Continue, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     CheckIfUnloadingIsCanceledResult check_if_unloading_is_canceled(Vector<JS::Handle<Navigable>> navigables_that_need_before_unload); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-12 12:01:09 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2023-12-03 16:56:04 +13:00
										 |  |  |     TraversableNavigable(JS::NonnullGCPtr<Page>); | 
					
						
							| 
									
										
										
										
											2022-12-12 12:01:09 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtual void visit_edges(Cell::Visitor&) override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-27 22:59:57 -06:00
										 |  |  |     // FIXME: Fix spec typo cancelation --> cancellation
 | 
					
						
							|  |  |  |     HistoryStepResult apply_the_history_step( | 
					
						
							|  |  |  |         int step, | 
					
						
							|  |  |  |         bool check_for_cancelation, | 
					
						
							|  |  |  |         Optional<SourceSnapshotParams>, | 
					
						
							|  |  |  |         JS::GCPtr<Navigable> initiator_to_check, | 
					
						
							| 
									
										
										
										
											2024-03-28 12:19:57 +01:00
										 |  |  |         Optional<UserNavigationInvolvement> user_involvement_for_navigate_events, | 
					
						
							| 
									
										
										
										
											2024-04-05 16:02:52 +02:00
										 |  |  |         Optional<Bindings::NavigationType> navigation_type, | 
					
						
							|  |  |  |         SynchronousNavigation); | 
					
						
							| 
									
										
										
										
											2023-09-03 22:20:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-02 23:56:26 +01:00
										 |  |  |     CheckIfUnloadingIsCanceledResult check_if_unloading_is_canceled(Vector<JS::Handle<Navigable>> navigables_that_need_before_unload, JS::GCPtr<TraversableNavigable> traversable, Optional<int> target_step, Optional<UserNavigationInvolvement> user_involvement_for_navigate_events); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-27 22:56:11 -06:00
										 |  |  |     Vector<JS::NonnullGCPtr<SessionHistoryEntry>> get_session_history_entries_for_the_navigation_api(JS::NonnullGCPtr<Navigable>, int); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-16 12:18:48 +02:00
										 |  |  |     [[nodiscard]] bool can_go_forward() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-12 12:01:09 +01:00
										 |  |  |     // https://html.spec.whatwg.org/multipage/document-sequences.html#tn-current-session-history-step
 | 
					
						
							|  |  |  |     int m_current_session_history_step { 0 }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/document-sequences.html#tn-session-history-entries
 | 
					
						
							|  |  |  |     Vector<JS::NonnullGCPtr<SessionHistoryEntry>> m_session_history_entries; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // FIXME: https://html.spec.whatwg.org/multipage/document-sequences.html#tn-session-history-traversal-queue
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/document-sequences.html#tn-running-nested-apply-history-step
 | 
					
						
							|  |  |  |     bool m_running_nested_apply_history_step { false }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/document-sequences.html#system-visibility-state
 | 
					
						
							| 
									
										
										
										
											2024-10-28 15:21:53 -04:00
										 |  |  |     VisibilityState m_system_visibility_state { VisibilityState::Hidden }; | 
					
						
							| 
									
										
										
										
											2023-07-25 01:22:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-10 04:43:51 +02:00
										 |  |  |     JS::NonnullGCPtr<SessionHistoryTraversalQueue> m_session_history_traversal_queue; | 
					
						
							| 
									
										
										
										
											2023-08-22 15:42:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-30 20:55:24 -07:00
										 |  |  |     String m_window_handle; | 
					
						
							| 
									
										
										
										
											2024-06-26 17:56:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-25 14:25:43 +02:00
										 |  |  |     RefPtr<Gfx::SkiaBackendContext> m_skia_backend_context; | 
					
						
							| 
									
										
										
										
											2024-07-03 19:23:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef AK_OS_MACOS
 | 
					
						
							| 
									
										
										
										
											2024-09-26 17:01:07 +02:00
										 |  |  |     OwnPtr<Gfx::MetalContext> m_metal_context; | 
					
						
							| 
									
										
										
										
											2024-06-26 17:56:55 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2022-12-12 12:01:09 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-03 21:46:36 +02:00
										 |  |  | struct BrowsingContextAndDocument { | 
					
						
							|  |  |  |     JS::NonnullGCPtr<HTML::BrowsingContext> browsing_context; | 
					
						
							|  |  |  |     JS::NonnullGCPtr<DOM::Document> document; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-03 16:56:04 +13:00
										 |  |  | WebIDL::ExceptionOr<BrowsingContextAndDocument> create_a_new_top_level_browsing_context_and_document(JS::NonnullGCPtr<Page> page); | 
					
						
							| 
									
										
										
										
											2024-03-28 12:19:57 +01:00
										 |  |  | 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); | 
					
						
							| 
									
										
										
										
											2023-08-20 14:28:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-12 12:01:09 +01:00
										 |  |  | } |