2022-12-12 13:46:54 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
2023-01-01 19:46:00 +03:00
|
|
|
* Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
2022-12-12 13:46:54 +03:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-08-22 17:00:42 +03:00
|
|
|
#include <AK/HashTable.h>
|
2023-08-25 01:18:40 +03:00
|
|
|
#include <AK/String.h>
|
2022-12-12 13:46:54 +03:00
|
|
|
#include <LibJS/Heap/Cell.h>
|
2023-08-28 19:06:10 +03:00
|
|
|
#include <LibWeb/Bindings/NavigationPrototype.h>
|
2023-09-14 02:22:00 +03:00
|
|
|
#include <LibWeb/DOM/DocumentLoadEventDelayer.h>
|
2022-12-12 13:46:54 +03:00
|
|
|
#include <LibWeb/Forward.h>
|
2023-04-11 10:20:11 +03:00
|
|
|
#include <LibWeb/HTML/ActivateTab.h>
|
2023-01-01 19:46:00 +03:00
|
|
|
#include <LibWeb/HTML/HistoryHandlingBehavior.h>
|
2023-09-21 22:47:19 +03:00
|
|
|
#include <LibWeb/HTML/NavigationParams.h>
|
2023-01-01 19:46:00 +03:00
|
|
|
#include <LibWeb/HTML/POSTResource.h>
|
2023-08-28 19:06:10 +03:00
|
|
|
#include <LibWeb/HTML/SandboxingFlagSet.h>
|
2023-04-06 18:10:12 +03:00
|
|
|
#include <LibWeb/HTML/SourceSnapshotParams.h>
|
2023-08-28 19:06:10 +03:00
|
|
|
#include <LibWeb/HTML/StructuredSerialize.h>
|
2023-04-11 10:20:11 +03:00
|
|
|
#include <LibWeb/HTML/TokenizedFeatures.h>
|
2023-08-22 17:00:42 +03:00
|
|
|
#include <LibWeb/PixelUnits.h>
|
2023-08-28 19:06:10 +03:00
|
|
|
#include <LibWeb/XHR/FormDataEntry.h>
|
2022-12-12 13:46:54 +03:00
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
2023-05-07 19:47:38 +03:00
|
|
|
enum class CSPNavigationType {
|
|
|
|
Other,
|
|
|
|
FormSubmission,
|
|
|
|
};
|
|
|
|
|
2023-08-28 19:06:10 +03:00
|
|
|
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#user-navigation-involvement
|
2023-09-21 07:21:20 +03:00
|
|
|
enum class UserNavigationInvolvement {
|
2023-08-28 19:06:10 +03:00
|
|
|
BrowserUI,
|
|
|
|
Activation,
|
|
|
|
None,
|
|
|
|
};
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#target-snapshot-params
|
|
|
|
struct TargetSnapshotParams {
|
|
|
|
SandboxingFlagSet sandboxing_flags {};
|
|
|
|
};
|
|
|
|
|
2022-12-12 13:46:54 +03:00
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#navigable
|
|
|
|
class Navigable : public JS::Cell {
|
|
|
|
JS_CELL(Navigable, JS::Cell);
|
2023-11-19 21:47:52 +03:00
|
|
|
JS_DECLARE_ALLOCATOR(Navigable);
|
2022-12-12 13:46:54 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~Navigable() override;
|
|
|
|
|
2023-04-25 20:46:32 +03:00
|
|
|
ErrorOr<void> initialize_navigable(JS::NonnullGCPtr<DocumentState> document_state, JS::GCPtr<Navigable> parent);
|
|
|
|
|
2023-04-06 23:16:38 +03:00
|
|
|
Vector<JS::Handle<Navigable>> child_navigables() const;
|
|
|
|
|
2023-08-27 18:06:39 +03:00
|
|
|
bool is_traversable() const;
|
|
|
|
|
2023-07-08 05:48:11 +03:00
|
|
|
String const& id() const { return m_id; }
|
|
|
|
JS::GCPtr<Navigable> parent() const { return m_parent; }
|
2022-12-12 13:46:54 +03:00
|
|
|
|
2023-07-08 05:48:11 +03:00
|
|
|
bool is_closing() const { return m_closing; }
|
|
|
|
void set_closing(bool value) { m_closing = value; }
|
2022-12-12 13:46:54 +03:00
|
|
|
|
2023-09-14 02:22:00 +03:00
|
|
|
void set_delaying_load_events(bool value);
|
2023-11-24 18:18:57 +03:00
|
|
|
bool is_delaying_load_events() const { return m_delaying_the_load_event.has_value(); }
|
2022-12-12 13:46:54 +03:00
|
|
|
|
2023-07-08 05:48:11 +03:00
|
|
|
JS::GCPtr<SessionHistoryEntry> active_session_history_entry() const { return m_active_session_history_entry; }
|
2023-08-20 15:42:55 +03:00
|
|
|
void set_active_session_history_entry(JS::GCPtr<SessionHistoryEntry> entry) { m_active_session_history_entry = entry; }
|
2023-07-08 05:48:11 +03:00
|
|
|
JS::GCPtr<SessionHistoryEntry> current_session_history_entry() const { return m_current_session_history_entry; }
|
|
|
|
void set_current_session_history_entry(JS::GCPtr<SessionHistoryEntry> entry) { m_current_session_history_entry = entry; }
|
2022-12-12 13:46:54 +03:00
|
|
|
|
2023-04-06 18:08:44 +03:00
|
|
|
Vector<JS::NonnullGCPtr<SessionHistoryEntry>>& get_session_history_entries() const;
|
|
|
|
|
2023-04-06 23:33:21 +03:00
|
|
|
void activate_history_entry(JS::GCPtr<SessionHistoryEntry>);
|
|
|
|
|
2022-12-12 13:46:54 +03:00
|
|
|
JS::GCPtr<DOM::Document> active_document();
|
|
|
|
JS::GCPtr<BrowsingContext> active_browsing_context();
|
|
|
|
JS::GCPtr<WindowProxy> active_window_proxy();
|
|
|
|
JS::GCPtr<Window> active_window();
|
|
|
|
|
2023-04-06 23:30:02 +03:00
|
|
|
JS::GCPtr<SessionHistoryEntry> get_the_target_history_entry(int target_step) const;
|
|
|
|
|
2022-12-12 13:46:54 +03:00
|
|
|
String target_name() const;
|
|
|
|
|
|
|
|
JS::GCPtr<NavigableContainer> container() const;
|
2022-12-16 14:05:19 +03:00
|
|
|
JS::GCPtr<DOM::Document> container_document() const;
|
2022-12-12 13:46:54 +03:00
|
|
|
|
2023-04-06 12:06:45 +03:00
|
|
|
JS::GCPtr<TraversableNavigable> traversable_navigable() const;
|
2022-12-12 14:17:46 +03:00
|
|
|
JS::GCPtr<TraversableNavigable> top_level_traversable();
|
2022-12-12 14:07:41 +03:00
|
|
|
|
2023-08-28 19:00:52 +03:00
|
|
|
virtual bool is_top_level_traversable() const { return false; }
|
|
|
|
|
2023-04-11 10:20:11 +03:00
|
|
|
enum class WindowType {
|
|
|
|
ExistingOrNone,
|
|
|
|
NewAndUnrestricted,
|
|
|
|
NewWithNoOpener,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ChosenNavigable {
|
|
|
|
JS::GCPtr<Navigable> navigable;
|
|
|
|
WindowType window_type;
|
|
|
|
};
|
|
|
|
|
|
|
|
ChosenNavigable choose_a_navigable(StringView name, TokenizedFeature::NoOpener no_opener, ActivateTab = ActivateTab::Yes);
|
|
|
|
|
2023-01-01 19:43:05 +03:00
|
|
|
static JS::GCPtr<Navigable> navigable_with_active_document(JS::NonnullGCPtr<DOM::Document>);
|
|
|
|
|
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 16:22:50 +03:00
|
|
|
void set_ongoing_navigation(Variant<Empty, Traversal, String> ongoing_navigation);
|
2023-04-24 21:37:35 +03:00
|
|
|
|
2023-09-21 22:47:19 +03:00
|
|
|
WebIDL::ExceptionOr<void> populate_session_history_entry_document(
|
|
|
|
JS::GCPtr<SessionHistoryEntry> entry,
|
|
|
|
SourceSnapshotParams const& source_snapshot_params,
|
|
|
|
TargetSnapshotParams const& target_snapshot_params,
|
|
|
|
Optional<String> navigation_id = {},
|
|
|
|
Variant<Empty, NavigationParams, NonFetchSchemeNavigationParams> navigation_params = Empty {},
|
|
|
|
CSPNavigationType csp_navigation_type = CSPNavigationType::Other,
|
|
|
|
bool allow_POST = false,
|
|
|
|
Function<void()> completion_steps = [] {});
|
2023-04-06 18:10:12 +03:00
|
|
|
|
2023-10-10 17:05:38 +03:00
|
|
|
struct NavigateParams {
|
|
|
|
AK::URL const& url;
|
|
|
|
JS::NonnullGCPtr<DOM::Document> source_document;
|
|
|
|
Variant<Empty, String, POSTResource> document_resource = Empty {};
|
|
|
|
JS::GCPtr<Fetch::Infrastructure::Response> response = nullptr;
|
|
|
|
bool exceptions_enabled = false;
|
|
|
|
Bindings::NavigationHistoryBehavior history_handling = Bindings::NavigationHistoryBehavior::Auto;
|
|
|
|
Optional<SerializationRecord> navigation_api_state = {};
|
|
|
|
Optional<Vector<XHR::FormDataEntry>&> form_data_entry_list = {};
|
|
|
|
ReferrerPolicy::ReferrerPolicy referrer_policy = ReferrerPolicy::ReferrerPolicy::EmptyString;
|
|
|
|
UserNavigationInvolvement user_involvement = UserNavigationInvolvement::None;
|
|
|
|
};
|
|
|
|
|
|
|
|
WebIDL::ExceptionOr<void> navigate(NavigateParams);
|
2023-01-01 19:46:00 +03:00
|
|
|
|
|
|
|
WebIDL::ExceptionOr<void> navigate_to_a_fragment(AK::URL const&, HistoryHandlingBehavior, String navigation_id);
|
|
|
|
|
2023-09-13 16:03:44 +03:00
|
|
|
WebIDL::ExceptionOr<JS::GCPtr<DOM::Document>> evaluate_javascript_url(AK::URL const&, Origin const& new_document_origin, String navigation_id);
|
|
|
|
WebIDL::ExceptionOr<void> navigate_to_a_javascript_url(AK::URL const&, HistoryHandlingBehavior, Origin const& initiator_origin, CSPNavigationType csp_navigation_type, String navigation_id);
|
2023-01-01 19:46:00 +03:00
|
|
|
|
2023-04-07 00:08:39 +03:00
|
|
|
void reload();
|
|
|
|
|
2023-09-06 00:36:20 +03: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 17:00:42 +03:00
|
|
|
CSSPixelPoint to_top_level_position(CSSPixelPoint);
|
|
|
|
CSSPixelRect to_top_level_rect(CSSPixelRect const&);
|
|
|
|
|
|
|
|
CSSPixelSize size() const { return m_size; }
|
|
|
|
void set_size(CSSPixelSize);
|
|
|
|
|
|
|
|
CSSPixelPoint viewport_scroll_offset() const { return m_viewport_scroll_offset; }
|
|
|
|
CSSPixelRect viewport_rect() const { return { m_viewport_scroll_offset, m_size }; }
|
|
|
|
void set_viewport_rect(CSSPixelRect const&);
|
|
|
|
|
|
|
|
void set_needs_display();
|
|
|
|
void set_needs_display(CSSPixelRect const&);
|
|
|
|
|
2023-08-25 00:54:36 +03:00
|
|
|
void set_is_popup(TokenizedFeature::Popup is_popup) { m_is_popup = is_popup; }
|
|
|
|
|
2023-09-20 09:09:59 +03:00
|
|
|
// https://html.spec.whatwg.org/#rendering-opportunity
|
|
|
|
[[nodiscard]] bool has_a_rendering_opportunity() const;
|
|
|
|
|
2023-09-21 22:47:19 +03:00
|
|
|
[[nodiscard]] TargetSnapshotParams snapshot_target_snapshot_params();
|
|
|
|
|
2022-12-12 13:46:54 +03:00
|
|
|
protected:
|
|
|
|
Navigable();
|
|
|
|
|
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
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;
|
|
|
|
|
2023-08-25 00:54:36 +03:00
|
|
|
// https://html.spec.whatwg.org/multipage/browsers.html#is-popup
|
|
|
|
TokenizedFeature::Popup m_is_popup { TokenizedFeature::Popup::No };
|
|
|
|
|
2022-12-12 13:46:54 +03:00
|
|
|
private:
|
2023-08-28 19:06:10 +03:00
|
|
|
bool allowed_by_sandboxing_to_navigate(Navigable const& target, SourceSnapshotParams const&);
|
|
|
|
|
2023-08-22 17:00:42 +03:00
|
|
|
void scroll_offset_did_change();
|
|
|
|
|
2023-09-21 08:21:16 +03:00
|
|
|
void inform_the_navigation_api_about_aborting_navigation();
|
|
|
|
|
2022-12-12 13:46:54 +03: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
|
|
|
|
JS::GCPtr<Navigable> m_parent;
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-current-history-entry
|
|
|
|
JS::GCPtr<SessionHistoryEntry> m_current_session_history_entry;
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-active-history-entry
|
|
|
|
JS::GCPtr<SessionHistoryEntry> m_active_session_history_entry;
|
|
|
|
|
|
|
|
// 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 02:22:00 +03:00
|
|
|
Optional<DOM::DocumentLoadEventDelayer> m_delaying_the_load_event;
|
2022-12-12 13:46:54 +03:00
|
|
|
|
|
|
|
// Implied link between navigable and its container.
|
|
|
|
JS::GCPtr<NavigableContainer> m_container;
|
2023-09-06 00:36:20 +03:00
|
|
|
|
|
|
|
bool m_has_been_destroyed { false };
|
2023-08-22 17:00:42 +03:00
|
|
|
|
|
|
|
CSSPixelSize m_size;
|
|
|
|
CSSPixelPoint m_viewport_scroll_offset;
|
2022-12-12 13:46:54 +03:00
|
|
|
};
|
|
|
|
|
2023-09-06 00:36:20 +03:00
|
|
|
HashTable<Navigable*>& all_navigables();
|
|
|
|
|
2023-08-25 01:18:40 +03:00
|
|
|
bool navigation_must_be_a_replace(AK::URL const& url, DOM::Document const& document);
|
2023-08-28 19:06:10 +03:00
|
|
|
void finalize_a_cross_document_navigation(JS::NonnullGCPtr<Navigable>, HistoryHandlingBehavior, JS::NonnullGCPtr<SessionHistoryEntry>);
|
2023-08-20 15:42:55 +03:00
|
|
|
void perform_url_and_history_update_steps(DOM::Document& document, AK::URL new_url, HistoryHandlingBehavior history_handling = HistoryHandlingBehavior::Reload);
|
2023-08-25 01:18:40 +03:00
|
|
|
|
2022-12-12 13:46:54 +03:00
|
|
|
}
|