2022-12-12 11:46:54 +01:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
2023-01-01 17:46:00 +01:00
|
|
|
* Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
2022-12-12 11:46:54 +01:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-08-22 16:00:42 +02:00
|
|
|
#include <AK/HashTable.h>
|
2023-08-24 16:18:40 -06:00
|
|
|
#include <AK/String.h>
|
2022-12-12 11:46:54 +01:00
|
|
|
#include <LibJS/Heap/Cell.h>
|
2023-08-28 18:06:10 +02:00
|
|
|
#include <LibWeb/Bindings/NavigationPrototype.h>
|
2023-09-14 01:22:00 +02:00
|
|
|
#include <LibWeb/DOM/DocumentLoadEventDelayer.h>
|
2022-12-12 11:46:54 +01:00
|
|
|
#include <LibWeb/Forward.h>
|
2023-04-11 10:20:11 +03:00
|
|
|
#include <LibWeb/HTML/ActivateTab.h>
|
2023-01-01 17:46:00 +01:00
|
|
|
#include <LibWeb/HTML/HistoryHandlingBehavior.h>
|
2023-09-21 13:47:19 -06:00
|
|
|
#include <LibWeb/HTML/NavigationParams.h>
|
2023-01-01 17:46:00 +01:00
|
|
|
#include <LibWeb/HTML/POSTResource.h>
|
2023-08-28 18:06:10 +02:00
|
|
|
#include <LibWeb/HTML/SandboxingFlagSet.h>
|
2023-04-06 18:10:12 +03:00
|
|
|
#include <LibWeb/HTML/SourceSnapshotParams.h>
|
2023-08-28 18:06:10 +02:00
|
|
|
#include <LibWeb/HTML/StructuredSerialize.h>
|
2023-04-11 10:20:11 +03:00
|
|
|
#include <LibWeb/HTML/TokenizedFeatures.h>
|
2024-09-02 16:47:32 +01:00
|
|
|
#include <LibWeb/InvalidateDisplayList.h>
|
2024-04-26 16:59:04 +02:00
|
|
|
#include <LibWeb/Page/EventHandler.h>
|
2023-08-22 16:00:42 +02:00
|
|
|
#include <LibWeb/PixelUnits.h>
|
2023-08-28 18:06:10 +02:00
|
|
|
#include <LibWeb/XHR/FormDataEntry.h>
|
2022-12-12 11:46:54 +01:00
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
2023-08-28 18:06:10 +02:00
|
|
|
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#target-snapshot-params
|
|
|
|
struct TargetSnapshotParams {
|
|
|
|
SandboxingFlagSet sandboxing_flags {};
|
|
|
|
};
|
|
|
|
|
2022-12-12 11:46:54 +01:00
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#navigable
|
2025-03-28 20:09:28 +00:00
|
|
|
class Navigable : public JS::Cell
|
|
|
|
, public Weakable<Navigable> {
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_CELL(Navigable, JS::Cell);
|
|
|
|
GC_DECLARE_ALLOCATOR(Navigable);
|
2022-12-12 11:46:54 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~Navigable() override;
|
|
|
|
|
2025-04-02 20:51:45 +13:00
|
|
|
using NullOrError = Optional<String>;
|
2024-11-13 19:08:01 -05:00
|
|
|
using NavigationParamsVariant = Variant<NullOrError, GC::Ref<NavigationParams>, GC::Ref<NonFetchSchemeNavigationParams>>;
|
2024-06-18 15:26:12 +02:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
ErrorOr<void> initialize_navigable(GC::Ref<DocumentState> document_state, GC::Ptr<Navigable> parent);
|
2023-04-25 20:46:32 +03:00
|
|
|
|
2024-10-25 10:26:01 -04:00
|
|
|
void register_navigation_observer(Badge<NavigationObserver>, NavigationObserver&);
|
|
|
|
void unregister_navigation_observer(Badge<NavigationObserver>, NavigationObserver&);
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
Vector<GC::Root<Navigable>> child_navigables() const;
|
2023-04-06 23:16:38 +03:00
|
|
|
|
2025-04-18 10:25:56 +02:00
|
|
|
virtual bool is_traversable() const { return false; }
|
2023-08-27 17:06:39 +02:00
|
|
|
|
2023-07-07 22:48:11 -04:00
|
|
|
String const& id() const { return m_id; }
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<Navigable> parent() const { return m_parent; }
|
|
|
|
bool is_ancestor_of(GC::Ref<Navigable>) const;
|
2022-12-12 11:46:54 +01:00
|
|
|
|
2023-07-07 22:48:11 -04:00
|
|
|
bool is_closing() const { return m_closing; }
|
|
|
|
void set_closing(bool value) { m_closing = value; }
|
2024-10-05 15:56:35 -04:00
|
|
|
bool is_script_closable();
|
2022-12-12 11:46:54 +01:00
|
|
|
|
2024-12-05 10:56:47 +01:00
|
|
|
void stop_loading();
|
|
|
|
|
2023-09-14 01:22:00 +02:00
|
|
|
void set_delaying_load_events(bool value);
|
2023-11-24 15:18:57 +00:00
|
|
|
bool is_delaying_load_events() const { return m_delaying_the_load_event.has_value(); }
|
2022-12-12 11:46:54 +01:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<SessionHistoryEntry> active_session_history_entry() const { return m_active_session_history_entry; }
|
|
|
|
void set_active_session_history_entry(GC::Ptr<SessionHistoryEntry> entry) { m_active_session_history_entry = entry; }
|
|
|
|
GC::Ptr<SessionHistoryEntry> current_session_history_entry() const { return m_current_session_history_entry; }
|
|
|
|
void set_current_session_history_entry(GC::Ptr<SessionHistoryEntry> entry) { m_current_session_history_entry = entry; }
|
2022-12-12 11:46:54 +01:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
Vector<GC::Ref<SessionHistoryEntry>>& get_session_history_entries() const;
|
2023-04-06 18:08:44 +03:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
void activate_history_entry(GC::Ptr<SessionHistoryEntry>);
|
2023-04-06 23:33:21 +03:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<DOM::Document> active_document();
|
|
|
|
GC::Ptr<BrowsingContext> active_browsing_context();
|
|
|
|
GC::Ptr<WindowProxy> active_window_proxy();
|
|
|
|
GC::Ptr<Window> active_window();
|
2022-12-12 11:46:54 +01:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<SessionHistoryEntry> get_the_target_history_entry(int target_step) const;
|
2023-04-06 23:30:02 +03:00
|
|
|
|
2022-12-12 11:46:54 +01:00
|
|
|
String target_name() const;
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<NavigableContainer> container() const;
|
|
|
|
GC::Ptr<DOM::Document> container_document() const;
|
2022-12-12 11:46:54 +01:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<TraversableNavigable> traversable_navigable() const;
|
|
|
|
GC::Ptr<TraversableNavigable> top_level_traversable();
|
2022-12-12 12:07:41 +01:00
|
|
|
|
2023-08-28 18:00:52 +02:00
|
|
|
virtual bool is_top_level_traversable() const { return false; }
|
|
|
|
|
2024-04-26 16:59:04 +02:00
|
|
|
[[nodiscard]] bool is_focused() const;
|
|
|
|
|
2023-04-11 10:20:11 +03:00
|
|
|
enum class WindowType {
|
|
|
|
ExistingOrNone,
|
|
|
|
NewAndUnrestricted,
|
|
|
|
NewWithNoOpener,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ChosenNavigable {
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<Navigable> navigable;
|
2023-04-11 10:20:11 +03:00
|
|
|
WindowType window_type;
|
|
|
|
};
|
|
|
|
|
2024-05-28 09:12:18 -06:00
|
|
|
ChosenNavigable choose_a_navigable(StringView name, TokenizedFeature::NoOpener no_opener, ActivateTab = ActivateTab::Yes, Optional<TokenizedFeature::Map const&> window_features = {});
|
2023-04-11 10:20:11 +03:00
|
|
|
|
2025-01-05 17:21:31 +00:00
|
|
|
GC::Ptr<Navigable> find_a_navigable_by_target_name(StringView name);
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
static GC::Ptr<Navigable> navigable_with_active_document(GC::Ref<DOM::Document>);
|
2023-01-01 17:43:05 +01:00
|
|
|
|
2023-04-24 21:37:35 +03:00
|
|
|
enum class Traversal {
|
|
|
|
Tag
|
|
|
|
};
|
|
|
|
|
|
|
|
Variant<Empty, Traversal, String> ongoing_navigation() const { return m_ongoing_navigation; }
|
2023-08-22 15:22:50 +02:00
|
|
|
void set_ongoing_navigation(Variant<Empty, Traversal, String> ongoing_navigation);
|
2023-04-24 21:37:35 +03:00
|
|
|
|
2023-09-21 13:47:19 -06:00
|
|
|
WebIDL::ExceptionOr<void> populate_session_history_entry_document(
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<SessionHistoryEntry> entry,
|
2023-09-21 13:47:19 -06:00
|
|
|
SourceSnapshotParams const& source_snapshot_params,
|
|
|
|
TargetSnapshotParams const& target_snapshot_params,
|
2025-01-07 14:58:48 +00:00
|
|
|
UserNavigationInvolvement user_involvement,
|
2023-09-21 13:47:19 -06:00
|
|
|
Optional<String> navigation_id = {},
|
2024-11-13 19:08:01 -05:00
|
|
|
NavigationParamsVariant navigation_params = Navigable::NullOrError {},
|
2024-11-25 17:10:33 +00:00
|
|
|
ContentSecurityPolicy::Directives::Directive::NavigationType csp_navigation_type = ContentSecurityPolicy::Directives::Directive::NavigationType::Other,
|
2023-09-21 13:47:19 -06:00
|
|
|
bool allow_POST = false,
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<GC::Function<void()>> completion_steps = {});
|
2023-04-06 18:10:12 +03:00
|
|
|
|
2023-10-10 16:05:38 +02:00
|
|
|
struct NavigateParams {
|
2025-02-27 00:22:12 +01:00
|
|
|
URL::URL url;
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<DOM::Document> source_document;
|
2023-10-10 16:05:38 +02:00
|
|
|
Variant<Empty, String, POSTResource> document_resource = Empty {};
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<Fetch::Infrastructure::Response> response = nullptr;
|
2023-10-10 16:05:38 +02:00
|
|
|
bool exceptions_enabled = false;
|
|
|
|
Bindings::NavigationHistoryBehavior history_handling = Bindings::NavigationHistoryBehavior::Auto;
|
|
|
|
Optional<SerializationRecord> navigation_api_state = {};
|
2025-02-27 00:22:12 +01:00
|
|
|
Optional<Vector<XHR::FormDataEntry>> form_data_entry_list = {};
|
2023-10-10 16:05:38 +02:00
|
|
|
ReferrerPolicy::ReferrerPolicy referrer_policy = ReferrerPolicy::ReferrerPolicy::EmptyString;
|
|
|
|
UserNavigationInvolvement user_involvement = UserNavigationInvolvement::None;
|
2025-01-30 14:14:13 +00:00
|
|
|
GC::Ptr<DOM::Element> source_element = nullptr;
|
2025-02-27 00:22:12 +01:00
|
|
|
|
|
|
|
void visit_edges(Cell::Visitor& visitor);
|
2023-10-10 16:05:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
WebIDL::ExceptionOr<void> navigate(NavigateParams);
|
2023-01-01 17:46:00 +01:00
|
|
|
|
2025-01-07 14:58:48 +00:00
|
|
|
GC::Ptr<DOM::Document> evaluate_javascript_url(URL::URL const&, URL::Origin const& new_document_origin, UserNavigationInvolvement, String navigation_id);
|
2023-01-01 17:46:00 +01:00
|
|
|
|
2023-09-27 22:59:57 -06:00
|
|
|
bool allowed_by_sandboxing_to_navigate(Navigable const& target, SourceSnapshotParams const&);
|
|
|
|
|
2025-01-07 14:58:48 +00:00
|
|
|
void reload(UserNavigationInvolvement = UserNavigationInvolvement::None);
|
2023-04-07 00:08:39 +03:00
|
|
|
|
2023-09-05 23:36:20 +02:00
|
|
|
// https://github.com/whatwg/html/issues/9690
|
|
|
|
[[nodiscard]] bool has_been_destroyed() const { return m_has_been_destroyed; }
|
|
|
|
void set_has_been_destroyed() { m_has_been_destroyed = true; }
|
|
|
|
|
2023-08-22 16:00:42 +02:00
|
|
|
CSSPixelPoint to_top_level_position(CSSPixelPoint);
|
|
|
|
CSSPixelRect to_top_level_rect(CSSPixelRect const&);
|
|
|
|
|
|
|
|
CSSPixelSize size() const { return m_size; }
|
|
|
|
|
|
|
|
CSSPixelPoint viewport_scroll_offset() const { return m_viewport_scroll_offset; }
|
|
|
|
CSSPixelRect viewport_rect() const { return { m_viewport_scroll_offset, m_size }; }
|
2025-01-29 10:24:57 +01:00
|
|
|
virtual void set_viewport_size(CSSPixelSize);
|
2024-02-03 10:43:01 +01:00
|
|
|
void perform_scroll_of_viewport(CSSPixelPoint position);
|
2023-08-22 16:00:42 +02:00
|
|
|
|
2025-02-04 13:01:46 +01:00
|
|
|
// https://html.spec.whatwg.org/multipage/webappapis.html#rendering-opportunity
|
2023-09-20 08:09:59 +02:00
|
|
|
[[nodiscard]] bool has_a_rendering_opportunity() const;
|
|
|
|
|
2023-09-21 13:47:19 -06:00
|
|
|
[[nodiscard]] TargetSnapshotParams snapshot_target_snapshot_params();
|
|
|
|
|
2024-04-26 14:55:54 +02:00
|
|
|
Page& page() { return m_page; }
|
|
|
|
Page const& page() const { return m_page; }
|
|
|
|
|
2024-04-26 16:59:04 +02:00
|
|
|
String selected_text() const;
|
|
|
|
void select_all();
|
|
|
|
void paste(String const&);
|
|
|
|
|
|
|
|
Web::EventHandler& event_handler() { return m_event_handler; }
|
|
|
|
Web::EventHandler const& event_handler() const { return m_event_handler; }
|
|
|
|
|
2025-02-27 00:22:12 +01:00
|
|
|
bool has_session_history_entry_and_ready_for_navigation() const { return m_has_session_history_entry_and_ready_for_navigation; }
|
|
|
|
void set_has_session_history_entry_and_ready_for_navigation();
|
|
|
|
|
2025-04-26 15:39:13 +12:00
|
|
|
void inform_the_navigation_api_about_child_navigable_destruction();
|
|
|
|
|
2025-02-27 00:22:12 +01:00
|
|
|
bool has_pending_navigations() const { return !m_pending_navigations.is_empty(); }
|
|
|
|
|
2025-04-18 10:25:56 +02:00
|
|
|
template<typename T>
|
|
|
|
bool fast_is() const = delete;
|
|
|
|
|
2022-12-12 11:46:54 +01:00
|
|
|
protected:
|
2024-11-15 04:01:23 +13:00
|
|
|
explicit Navigable(GC::Ref<Page>);
|
2022-12-12 11:46:54 +01:00
|
|
|
|
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
2025-01-17 14:18:36 +13:00
|
|
|
virtual void finalize() override;
|
2022-12-12 11:46:54 +01:00
|
|
|
|
2023-04-24 21:37:35 +03:00
|
|
|
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#ongoing-navigation
|
|
|
|
Variant<Empty, Traversal, String> m_ongoing_navigation;
|
|
|
|
|
2022-12-12 11:46:54 +01:00
|
|
|
private:
|
2025-02-27 00:22:12 +01:00
|
|
|
void begin_navigation(NavigateParams);
|
|
|
|
void navigate_to_a_fragment(URL::URL const&, HistoryHandlingBehavior, UserNavigationInvolvement, GC::Ptr<DOM::Element> source_element, Optional<SerializationRecord> navigation_api_state, String navigation_id);
|
2024-11-25 17:10:33 +00:00
|
|
|
void navigate_to_a_javascript_url(URL::URL const&, HistoryHandlingBehavior, GC::Ref<SourceSnapshotParams>, URL::Origin const& initiator_origin, UserNavigationInvolvement, ContentSecurityPolicy::Directives::Directive::NavigationType csp_navigation_type, String navigation_id);
|
2025-02-27 00:22:12 +01:00
|
|
|
|
2024-04-26 16:59:04 +02:00
|
|
|
void reset_cursor_blink_cycle();
|
|
|
|
|
2023-08-22 16:00:42 +02:00
|
|
|
void scroll_offset_did_change();
|
|
|
|
|
2023-09-20 23:21:16 -06:00
|
|
|
void inform_the_navigation_api_about_aborting_navigation();
|
|
|
|
|
2022-12-12 11:46:54 +01:00
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-id
|
|
|
|
String m_id;
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-parent
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<Navigable> m_parent;
|
2022-12-12 11:46:54 +01:00
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-current-history-entry
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<SessionHistoryEntry> m_current_session_history_entry;
|
2022-12-12 11:46:54 +01:00
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-active-history-entry
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<SessionHistoryEntry> m_active_session_history_entry;
|
2022-12-12 11:46:54 +01:00
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#is-closing
|
|
|
|
bool m_closing { false };
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#delaying-load-events-mode
|
2023-09-14 01:22:00 +02:00
|
|
|
Optional<DOM::DocumentLoadEventDelayer> m_delaying_the_load_event;
|
2022-12-12 11:46:54 +01:00
|
|
|
|
|
|
|
// Implied link between navigable and its container.
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<NavigableContainer> m_container;
|
2023-09-05 23:36:20 +02:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<Page> m_page;
|
2024-04-26 14:55:54 +02:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
HashTable<GC::Ref<NavigationObserver>> m_navigation_observers;
|
2024-10-25 10:26:01 -04:00
|
|
|
|
2023-09-05 23:36:20 +02:00
|
|
|
bool m_has_been_destroyed { false };
|
2023-08-22 16:00:42 +02:00
|
|
|
|
|
|
|
CSSPixelSize m_size;
|
|
|
|
CSSPixelPoint m_viewport_scroll_offset;
|
2024-02-23 22:10:35 +01:00
|
|
|
|
2024-04-26 16:59:04 +02:00
|
|
|
Web::EventHandler m_event_handler;
|
2025-02-27 00:22:12 +01:00
|
|
|
|
|
|
|
bool m_has_session_history_entry_and_ready_for_navigation { false };
|
|
|
|
|
|
|
|
Vector<NavigateParams> m_pending_navigations;
|
2022-12-12 11:46:54 +01:00
|
|
|
};
|
|
|
|
|
2025-01-17 14:18:36 +13:00
|
|
|
HashTable<GC::RawRef<Navigable>>& all_navigables();
|
2023-09-05 23:36:20 +02:00
|
|
|
|
2024-03-18 16:22:27 +13:00
|
|
|
bool navigation_must_be_a_replace(URL::URL const& url, DOM::Document const& document);
|
2025-01-07 14:58:48 +00:00
|
|
|
void finalize_a_cross_document_navigation(GC::Ref<Navigable>, HistoryHandlingBehavior, UserNavigationInvolvement, GC::Ref<SessionHistoryEntry>);
|
2024-03-28 12:58:43 +01:00
|
|
|
void perform_url_and_history_update_steps(DOM::Document& document, URL::URL new_url, Optional<SerializationRecord> = {}, HistoryHandlingBehavior history_handling = HistoryHandlingBehavior::Replace);
|
2024-01-18 12:52:13 -07:00
|
|
|
UserNavigationInvolvement user_navigation_involvement(DOM::Event const&);
|
2023-08-24 16:18:40 -06:00
|
|
|
|
2022-12-12 11:46:54 +01:00
|
|
|
}
|