| 
									
										
										
										
											2022-12-12 11:46:54 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2022, Andreas Kling <kling@serenityos.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>
 | 
					
						
							|  |  |  | #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>
 | 
					
						
							| 
									
										
										
										
											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-05-07 12:47:38 -04:00
										 |  |  | enum class CSPNavigationType { | 
					
						
							|  |  |  |     Other, | 
					
						
							|  |  |  |     FormSubmission, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-28 18:06:10 +02:00
										 |  |  | // https://html.spec.whatwg.org/multipage/browsing-the-web.html#user-navigation-involvement
 | 
					
						
							|  |  |  | enum class UserNaviagationInvolvement { | 
					
						
							|  |  |  |     BrowserUI, | 
					
						
							|  |  |  |     Activation, | 
					
						
							|  |  |  |     None, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // 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
 | 
					
						
							|  |  |  | class Navigable : public JS::Cell { | 
					
						
							|  |  |  |     JS_CELL(Navigable, JS::Cell); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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 17:06:39 +02:00
										 |  |  |     bool is_traversable() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-07 22:48:11 -04:00
										 |  |  |     String const& id() const { return m_id; } | 
					
						
							|  |  |  |     JS::GCPtr<Navigable> parent() const { return m_parent; } | 
					
						
							| 
									
										
										
										
											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; } | 
					
						
							| 
									
										
										
										
											2022-12-12 11:46:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-14 01:22:00 +02:00
										 |  |  |     void set_delaying_load_events(bool value); | 
					
						
							| 
									
										
										
										
											2022-12-12 11:46:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-07 22:48:11 -04:00
										 |  |  |     JS::GCPtr<SessionHistoryEntry> active_session_history_entry() const { return m_active_session_history_entry; } | 
					
						
							| 
									
										
										
										
											2023-08-20 14:42:55 +02:00
										 |  |  |     void set_active_session_history_entry(JS::GCPtr<SessionHistoryEntry> entry) { m_active_session_history_entry = entry; } | 
					
						
							| 
									
										
										
										
											2023-07-07 22:48:11 -04: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 11:46:54 +01: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 11:46:54 +01: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 11:46:54 +01:00
										 |  |  |     String target_name() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     JS::GCPtr<NavigableContainer> container() const; | 
					
						
							| 
									
										
										
										
											2022-12-16 12:05:19 +01:00
										 |  |  |     JS::GCPtr<DOM::Document> container_document() const; | 
					
						
							| 
									
										
										
										
											2022-12-12 11:46:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-06 12:06:45 +03:00
										 |  |  |     JS::GCPtr<TraversableNavigable> traversable_navigable() const; | 
					
						
							| 
									
										
										
										
											2022-12-12 12:17:46 +01:00
										 |  |  |     JS::GCPtr<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; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 17:43:05 +01: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 15:22:50 +02:00
										 |  |  |     void set_ongoing_navigation(Variant<Empty, Traversal, String> ongoing_navigation); | 
					
						
							| 
									
										
										
										
											2023-04-24 21:37:35 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-14 15:07:57 +02:00
										 |  |  |     WebIDL::ExceptionOr<void> populate_session_history_entry_document(JS::GCPtr<SessionHistoryEntry>, Optional<NavigationParams>, Optional<String> navigation_id, SourceSnapshotParams const&, bool allow_POST, Function<void()>); | 
					
						
							| 
									
										
										
										
											2023-04-06 18:10:12 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-01 17:46:00 +01:00
										 |  |  |     WebIDL::ExceptionOr<void> navigate( | 
					
						
							|  |  |  |         AK::URL const&, | 
					
						
							|  |  |  |         JS::NonnullGCPtr<DOM::Document> source_document, | 
					
						
							|  |  |  |         Variant<Empty, String, POSTResource> document_resource = Empty {}, | 
					
						
							|  |  |  |         JS::GCPtr<Fetch::Infrastructure::Response> = nullptr, | 
					
						
							|  |  |  |         bool exceptions_enabled = false, | 
					
						
							| 
									
										
										
										
											2023-08-28 18:06:10 +02:00
										 |  |  |         Bindings::NavigationHistoryBehavior = Bindings::NavigationHistoryBehavior::Auto, | 
					
						
							|  |  |  |         Optional<SerializationRecord> navigation_api_state = {}, | 
					
						
							|  |  |  |         Optional<Vector<XHR::FormDataEntry>&> form_data_entry_list = {}, | 
					
						
							|  |  |  |         ReferrerPolicy::ReferrerPolicy = ReferrerPolicy::ReferrerPolicy::EmptyString, | 
					
						
							|  |  |  |         UserNaviagationInvolvement = UserNaviagationInvolvement::None); | 
					
						
							| 
									
										
										
										
											2023-01-01 17:46:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<void> navigate_to_a_fragment(AK::URL const&, HistoryHandlingBehavior, String navigation_id); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-13 15:03:44 +02: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 17:46:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-07 00:08:39 +03:00
										 |  |  |     void reload(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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; } | 
					
						
							|  |  |  |     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-24 23:54:36 +02:00
										 |  |  |     void set_is_popup(TokenizedFeature::Popup is_popup) { m_is_popup = is_popup; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-12 11:46:54 +01: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-24 23:54:36 +02:00
										 |  |  |     // https://html.spec.whatwg.org/multipage/browsers.html#is-popup
 | 
					
						
							|  |  |  |     TokenizedFeature::Popup m_is_popup { TokenizedFeature::Popup::No }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-12 11:46:54 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2023-08-28 18:06:10 +02:00
										 |  |  |     bool allowed_by_sandboxing_to_navigate(Navigable const& target, SourceSnapshotParams const&); | 
					
						
							|  |  |  |     TargetSnapshotParams snapshot_target_snapshot_params(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-22 16:00:42 +02:00
										 |  |  |     void scroll_offset_did_change(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
 | 
					
						
							|  |  |  |     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 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.
 | 
					
						
							|  |  |  |     JS::GCPtr<NavigableContainer> m_container; | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2022-12-12 11:46:54 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-05 23:36:20 +02:00
										 |  |  | HashTable<Navigable*>& all_navigables(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-24 16:18:40 -06:00
										 |  |  | bool navigation_must_be_a_replace(AK::URL const& url, DOM::Document const& document); | 
					
						
							| 
									
										
										
										
											2023-08-28 18:06:10 +02:00
										 |  |  | void finalize_a_cross_document_navigation(JS::NonnullGCPtr<Navigable>, HistoryHandlingBehavior, JS::NonnullGCPtr<SessionHistoryEntry>); | 
					
						
							| 
									
										
										
										
											2023-08-20 14:42:55 +02:00
										 |  |  | void perform_url_and_history_update_steps(DOM::Document& document, AK::URL new_url, HistoryHandlingBehavior history_handling = HistoryHandlingBehavior::Reload); | 
					
						
							| 
									
										
										
										
											2023-08-24 16:18:40 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-12 11:46:54 +01:00
										 |  |  | } |