2022-12-12 12:01:09 +01:00
|
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
2025-06-22 20:26:03 +02:00
|
|
|
|
* Copyright (c) 2025, Jelle Raaijmakers <jelle@ladybird.org>
|
2025-06-26 22:33:58 +02:00
|
|
|
|
* Copyright (c) 2023-2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
2022-12-12 12:01:09 +01:00
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/Vector.h>
|
2025-07-19 19:35:33 -07:00
|
|
|
|
#include <LibWeb/Export.h>
|
2025-06-22 20:26:03 +02:00
|
|
|
|
#include <LibWeb/Geolocation/Geolocation.h>
|
2022-12-12 12:01:09 +01:00
|
|
|
|
#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-12-26 11:56:03 +13:00
|
|
|
|
#include <LibWeb/StorageAPI/StorageShed.h>
|
2024-07-03 19:23:27 +02:00
|
|
|
|
|
2025-01-29 10:26:57 +01:00
|
|
|
|
#ifdef AK_OS_MACOS
|
|
|
|
|
# include <LibGfx/MetalContext.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-01-29 10:24:57 +01:00
|
|
|
|
#ifdef USE_VULKAN
|
|
|
|
|
# include <LibGfx/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
|
2025-07-19 19:35:33 -07:00
|
|
|
|
class WEB_API TraversableNavigable final : public Navigable {
|
2024-11-15 04:01:23 +13:00
|
|
|
|
GC_CELL(TraversableNavigable, Navigable);
|
|
|
|
|
GC_DECLARE_ALLOCATOR(TraversableNavigable);
|
2022-12-12 12:01:09 +01:00
|
|
|
|
|
|
|
|
|
public:
|
2024-11-15 04:01:23 +13:00
|
|
|
|
static WebIDL::ExceptionOr<GC::Ref<TraversableNavigable>> create_a_new_top_level_traversable(GC::Ref<Page>, GC::Ptr<BrowsingContext> opener, String target_name);
|
|
|
|
|
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 {});
|
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; }
|
2024-11-15 04:01:23 +13:00
|
|
|
|
Vector<GC::Ref<SessionHistoryEntry>>& session_history_entries() { return m_session_history_entries; }
|
|
|
|
|
Vector<GC::Ref<SessionHistoryEntry>> const& session_history_entries() const { return m_session_history_entries; }
|
2023-07-07 22:48:11 -04:00
|
|
|
|
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
|
|
|
|
|
2025-05-03 13:49:38 +01:00
|
|
|
|
bool is_created_by_web_content() const { return m_is_created_by_web_content; }
|
|
|
|
|
void set_is_created_by_web_content(bool value) { m_is_created_by_web_content = value; }
|
|
|
|
|
|
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,
|
|
|
|
|
};
|
|
|
|
|
|
2024-11-25 14:30:12 +00:00
|
|
|
|
HistoryStepResult apply_the_traverse_history_step(int, GC::Ptr<SourceSnapshotParams>, GC::Ptr<Navigable>, UserNavigationInvolvement);
|
2025-01-07 14:58:48 +00:00
|
|
|
|
HistoryStepResult apply_the_reload_history_step(UserNavigationInvolvement);
|
2024-04-05 16:02:52 +02:00
|
|
|
|
enum class SynchronousNavigation : bool {
|
|
|
|
|
Yes,
|
|
|
|
|
No,
|
|
|
|
|
};
|
2025-01-07 14:58:48 +00:00
|
|
|
|
HistoryStepResult apply_the_push_or_replace_history_step(int step, HistoryHandlingBehavior history_handling, UserNavigationInvolvement, 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;
|
2024-11-15 04:01:23 +13:00
|
|
|
|
Vector<GC::Root<Navigable>> get_all_navigables_whose_current_session_history_entry_will_change_or_reload(int) const;
|
|
|
|
|
Vector<GC::Root<Navigable>> get_all_navigables_that_only_need_history_object_length_index_update(int) const;
|
|
|
|
|
Vector<GC::Root<Navigable>> get_all_navigables_that_might_experience_a_cross_document_traversal(int) const;
|
2023-09-27 22:59:57 -06:00
|
|
|
|
|
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();
|
2024-11-25 14:30:12 +00:00
|
|
|
|
void traverse_the_history_by_delta(int delta, GC::Ptr<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-11-15 04:01:23 +13:00
|
|
|
|
void append_session_history_traversal_steps(GC::Ref<GC::Function<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-11-15 04:01:23 +13:00
|
|
|
|
void append_session_history_synchronous_navigation_steps(GC::Ref<Navigable> target_navigable, GC::Ref<GC::Function<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-11-15 04:01:23 +13:00
|
|
|
|
[[nodiscard]] GC::Ptr<DOM::Node> currently_focused_area();
|
2024-04-26 16:59:04 +02:00
|
|
|
|
|
2024-10-02 23:56:26 +01:00
|
|
|
|
enum class CheckIfUnloadingIsCanceledResult {
|
|
|
|
|
CanceledByBeforeUnload,
|
|
|
|
|
CanceledByNavigate,
|
|
|
|
|
Continue,
|
|
|
|
|
};
|
2024-11-15 04:01:23 +13:00
|
|
|
|
CheckIfUnloadingIsCanceledResult check_if_unloading_is_canceled(Vector<GC::Root<Navigable>> navigables_that_need_before_unload);
|
2024-10-02 23:56:26 +01:00
|
|
|
|
|
2024-12-26 11:56:03 +13:00
|
|
|
|
StorageAPI::StorageShed& storage_shed() { return m_storage_shed; }
|
|
|
|
|
StorageAPI::StorageShed const& storage_shed() const { return m_storage_shed; }
|
|
|
|
|
|
2025-06-22 20:26:03 +02:00
|
|
|
|
// https://w3c.github.io/geolocation/#dfn-emulated-position-data
|
|
|
|
|
Geolocation::EmulatedPositionData const& emulated_position_data() const;
|
|
|
|
|
void set_emulated_position_data(Geolocation::EmulatedPositionData data);
|
|
|
|
|
|
2025-06-26 22:33:58 +02:00
|
|
|
|
void process_screenshot_requests();
|
|
|
|
|
void queue_screenshot_task(Optional<UniqueNodeID> node_id)
|
|
|
|
|
{
|
|
|
|
|
m_screenshot_tasks.enqueue({ node_id });
|
|
|
|
|
set_needs_repaint();
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-12 12:01:09 +01:00
|
|
|
|
private:
|
2024-11-15 04:01:23 +13:00
|
|
|
|
TraversableNavigable(GC::Ref<Page>);
|
2022-12-12 12:01:09 +01:00
|
|
|
|
|
2025-04-18 10:25:56 +02:00
|
|
|
|
virtual bool is_traversable() const override { return true; }
|
|
|
|
|
|
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,
|
2024-11-25 14:30:12 +00:00
|
|
|
|
GC::Ptr<SourceSnapshotParams>,
|
2024-11-15 04:01:23 +13:00
|
|
|
|
GC::Ptr<Navigable> initiator_to_check,
|
2025-01-07 14:58:48 +00:00
|
|
|
|
UserNavigationInvolvement user_involvement,
|
2024-04-05 16:02:52 +02:00
|
|
|
|
Optional<Bindings::NavigationType> navigation_type,
|
|
|
|
|
SynchronousNavigation);
|
2023-09-03 22:20:32 +02:00
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
|
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);
|
2024-10-02 23:56:26 +01:00
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
|
Vector<GC::Ref<SessionHistoryEntry>> get_session_history_entries_for_the_navigation_api(GC::Ref<Navigable>, int);
|
2023-09-27 22:56:11 -06:00
|
|
|
|
|
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
|
2024-11-15 04:01:23 +13:00
|
|
|
|
Vector<GC::Ref<SessionHistoryEntry>> m_session_history_entries;
|
2022-12-12 12:01:09 +01:00
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2025-05-03 13:49:38 +01:00
|
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#is-created-by-web-content
|
|
|
|
|
bool m_is_created_by_web_content { false };
|
|
|
|
|
|
2024-12-26 11:56:03 +13:00
|
|
|
|
// https://storage.spec.whatwg.org/#traversable-navigable-storage-shed
|
|
|
|
|
// A traversable navigable holds a storage shed, which is a storage shed. A traversable navigable’s storage shed holds all session storage data.
|
2025-06-11 18:51:22 +02:00
|
|
|
|
GC::Ref<StorageAPI::StorageShed> m_storage_shed;
|
2024-12-26 11:56:03 +13:00
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
|
GC::Ref<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
|
|
|
|
|
2025-06-22 20:26:03 +02:00
|
|
|
|
// https://w3c.github.io/geolocation/#dfn-emulated-position-data
|
|
|
|
|
Geolocation::EmulatedPositionData m_emulated_position_data;
|
2025-06-26 22:33:58 +02:00
|
|
|
|
|
|
|
|
|
struct ScreenshotTask {
|
|
|
|
|
Optional<Web::UniqueNodeID> node_id;
|
|
|
|
|
};
|
|
|
|
|
Queue<ScreenshotTask> m_screenshot_tasks;
|
2022-12-12 12:01:09 +01:00
|
|
|
|
};
|
|
|
|
|
|
2023-09-03 21:46:36 +02:00
|
|
|
|
struct BrowsingContextAndDocument {
|
2024-11-15 04:01:23 +13:00
|
|
|
|
GC::Ref<HTML::BrowsingContext> browsing_context;
|
|
|
|
|
GC::Ref<DOM::Document> document;
|
2023-09-03 21:46:36 +02:00
|
|
|
|
};
|
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
|
WebIDL::ExceptionOr<BrowsingContextAndDocument> create_a_new_top_level_browsing_context_and_document(GC::Ref<Page> page);
|
2025-01-07 14:58:48 +00:00
|
|
|
|
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, UserNavigationInvolvement);
|
2023-08-20 14:28:33 +02:00
|
|
|
|
|
2025-04-18 10:25:56 +02:00
|
|
|
|
template<>
|
|
|
|
|
inline bool Navigable::fast_is<TraversableNavigable>() const { return is_traversable(); }
|
|
|
|
|
|
2022-12-12 12:01:09 +01:00
|
|
|
|
}
|