| 
									
										
										
										
											2022-10-13 19:21:50 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2022, Linus Groh <linusg@serenityos.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-19 09:15:16 -04:00
										 |  |  | #include <AK/Badge.h>
 | 
					
						
							| 
									
										
										
										
											2024-03-22 15:28:41 -04:00
										 |  |  | #include <AK/HashMap.h>
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  | #include <LibGC/Function.h>
 | 
					
						
							|  |  |  | #include <LibGC/Ptr.h>
 | 
					
						
							| 
									
										
										
										
											2022-10-13 19:21:50 +02:00
										 |  |  | #include <LibJS/Forward.h>
 | 
					
						
							|  |  |  | #include <LibJS/Heap/Cell.h>
 | 
					
						
							| 
									
										
										
										
											2023-09-25 18:04:10 +02:00
										 |  |  | #include <LibJS/Runtime/VM.h>
 | 
					
						
							| 
									
										
										
										
											2022-10-13 19:21:50 +02:00
										 |  |  | #include <LibWeb/Fetch/Infrastructure/FetchTimingInfo.h>
 | 
					
						
							| 
									
										
										
										
											2023-04-19 09:15:16 -04:00
										 |  |  | #include <LibWeb/Forward.h>
 | 
					
						
							| 
									
										
										
										
											2024-08-04 17:10:49 +02:00
										 |  |  | #include <LibWeb/HTML/EventLoop/Task.h>
 | 
					
						
							| 
									
										
										
										
											2022-10-13 19:21:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::Fetch::Infrastructure { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://fetch.spec.whatwg.org/#fetch-controller
 | 
					
						
							|  |  |  | class FetchController : public JS::Cell { | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC_CELL(FetchController, JS::Cell); | 
					
						
							|  |  |  |     GC_DECLARE_ALLOCATOR(FetchController); | 
					
						
							| 
									
										
										
										
											2022-10-13 19:21:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     enum class State { | 
					
						
							|  |  |  |         Ongoing, | 
					
						
							|  |  |  |         Terminated, | 
					
						
							|  |  |  |         Aborted, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     [[nodiscard]] static GC::Ref<FetchController> create(JS::VM&); | 
					
						
							| 
									
										
										
										
											2022-10-13 19:21:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     void set_full_timing_info(GC::Ref<FetchTimingInfo> full_timing_info) { m_full_timing_info = full_timing_info; } | 
					
						
							| 
									
										
										
										
											2023-09-25 18:04:10 +02:00
										 |  |  |     void set_report_timing_steps(Function<void(JS::Object const&)> report_timing_steps); | 
					
						
							|  |  |  |     void set_next_manual_redirect_steps(Function<void()> next_manual_redirect_steps); | 
					
						
							| 
									
										
										
										
											2022-10-13 19:21:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     [[nodiscard]] State state() const { return m_state; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void report_timing(JS::Object const&) const; | 
					
						
							|  |  |  |     void process_next_manual_redirect() const; | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     [[nodiscard]] GC::Ref<FetchTimingInfo> extract_full_timing_info() const; | 
					
						
							| 
									
										
										
										
											2023-02-28 17:45:49 +00:00
										 |  |  |     void abort(JS::Realm&, Optional<JS::Value>); | 
					
						
							| 
									
										
										
										
											2022-10-13 19:21:50 +02:00
										 |  |  |     void terminate(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     void set_fetch_params(Badge<FetchParams>, GC::Ref<FetchParams> fetch_params) { m_fetch_params = fetch_params; } | 
					
						
							| 
									
										
										
										
											2023-04-19 09:15:16 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void stop_fetch(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-22 15:28:41 -04:00
										 |  |  |     u64 next_fetch_task_id() { return m_next_fetch_task_id++; } | 
					
						
							| 
									
										
										
										
											2024-08-04 17:10:49 +02:00
										 |  |  |     void fetch_task_queued(u64 fetch_task_id, HTML::TaskID event_id); | 
					
						
							| 
									
										
										
										
											2024-03-22 15:28:41 -04:00
										 |  |  |     void fetch_task_complete(u64 fetch_task_id); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 19:21:50 +02:00
										 |  |  | private: | 
					
						
							|  |  |  |     FetchController(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual void visit_edges(JS::Cell::Visitor&) override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://fetch.spec.whatwg.org/#fetch-controller-state
 | 
					
						
							|  |  |  |     // state (default "ongoing")
 | 
					
						
							|  |  |  |     //    "ongoing", "terminated", or "aborted"
 | 
					
						
							|  |  |  |     State m_state { State::Ongoing }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://fetch.spec.whatwg.org/#fetch-controller-full-timing-info
 | 
					
						
							|  |  |  |     // full timing info (default null)
 | 
					
						
							|  |  |  |     //    Null or a fetch timing info.
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC::Ptr<FetchTimingInfo> m_full_timing_info; | 
					
						
							| 
									
										
										
										
											2022-10-13 19:21:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // https://fetch.spec.whatwg.org/#fetch-controller-report-timing-steps
 | 
					
						
							|  |  |  |     // report timing steps (default null)
 | 
					
						
							|  |  |  |     //    Null or an algorithm accepting a global object.
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC::Ptr<GC::Function<void(JS::Object const&)>> m_report_timing_steps; | 
					
						
							| 
									
										
										
										
											2022-10-13 19:21:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // https://fetch.spec.whatwg.org/#fetch-controller-report-timing-steps
 | 
					
						
							|  |  |  |     // FIXME: serialized abort reason (default null)
 | 
					
						
							|  |  |  |     //     Null or a Record (result of StructuredSerialize).
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://fetch.spec.whatwg.org/#fetch-controller-next-manual-redirect-steps
 | 
					
						
							|  |  |  |     // next manual redirect steps (default null)
 | 
					
						
							|  |  |  |     //     Null or an algorithm accepting nothing.
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC::Ptr<GC::Function<void()>> m_next_manual_redirect_steps; | 
					
						
							| 
									
										
										
										
											2023-04-19 09:15:16 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC::Ptr<FetchParams> m_fetch_params; | 
					
						
							| 
									
										
										
										
											2024-03-22 15:28:41 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-04 17:10:49 +02:00
										 |  |  |     HashMap<u64, HTML::TaskID> m_ongoing_fetch_tasks; | 
					
						
							| 
									
										
										
										
											2024-03-22 15:28:41 -04:00
										 |  |  |     u64 m_next_fetch_task_id { 0 }; | 
					
						
							| 
									
										
										
										
											2022-10-13 19:21:50 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |