| 
									
										
										
										
											2021-09-08 23:09:18 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:19:50 +02:00
										 |  |  |  * Copyright (c) 2021-2024, Andreas Kling <andreas@ladybird.org> | 
					
						
							| 
									
										
										
										
											2021-09-08 23:09:18 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-04 17:10:49 +02:00
										 |  |  | #include <AK/DistinctNumeric.h>
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  | #include <LibGC/CellAllocator.h>
 | 
					
						
							| 
									
										
										
										
											2024-04-04 12:06:50 +02:00
										 |  |  | #include <LibJS/Heap/Cell.h>
 | 
					
						
							| 
									
										
										
										
											2021-09-08 23:09:18 +02:00
										 |  |  | #include <LibWeb/Forward.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Web::HTML { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-04 09:02:00 -04:00
										 |  |  | struct UniqueTaskSource; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-04 17:10:49 +02:00
										 |  |  | AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(u64, TaskID, Comparison); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-04 12:06:50 +02:00
										 |  |  | class Task final : public JS::Cell { | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC_CELL(Task, JS::Cell); | 
					
						
							|  |  |  |     GC_DECLARE_ALLOCATOR(Task); | 
					
						
							| 
									
										
										
										
											2024-04-04 12:06:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 23:09:18 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2021-09-08 23:53:55 +02:00
										 |  |  |     // https://html.spec.whatwg.org/multipage/webappapis.html#generic-task-sources
 | 
					
						
							|  |  |  |     enum class Source { | 
					
						
							|  |  |  |         Unspecified, | 
					
						
							|  |  |  |         DOMManipulation, | 
					
						
							|  |  |  |         UserInteraction, | 
					
						
							|  |  |  |         Networking, | 
					
						
							|  |  |  |         HistoryTraversal, | 
					
						
							| 
									
										
										
										
											2021-09-16 23:43:08 +02:00
										 |  |  |         IdleTask, | 
					
						
							| 
									
										
										
										
											2021-09-19 22:09:51 +02:00
										 |  |  |         PostedMessage, | 
					
						
							| 
									
										
										
										
											2021-09-26 14:36:20 +02:00
										 |  |  |         Microtask, | 
					
						
							| 
									
										
										
										
											2021-10-03 12:39:56 +02:00
										 |  |  |         TimerTask, | 
					
						
							| 
									
										
										
										
											2022-02-06 03:32:26 +00:00
										 |  |  |         JavaScriptEngine, | 
					
						
							| 
									
										
										
										
											2023-04-04 09:02:00 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-01 17:41:56 +01:00
										 |  |  |         // https://html.spec.whatwg.org/multipage/webappapis.html#navigation-and-traversal-task-source
 | 
					
						
							|  |  |  |         NavigationAndTraversal, | 
					
						
							| 
									
										
										
										
											2023-06-10 19:39:56 +12:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // https://w3c.github.io/FileAPI/#fileReadingTaskSource
 | 
					
						
							|  |  |  |         FileReading, | 
					
						
							| 
									
										
										
										
											2023-06-30 05:44:20 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-06 23:44:07 +01:00
										 |  |  |         // https://www.w3.org/TR/intersection-observer/#intersectionobserver-task-source
 | 
					
						
							|  |  |  |         IntersectionObserver, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-25 01:26:47 +01:00
										 |  |  |         // https://w3c.github.io/performance-timeline/#dfn-performance-timeline-task-source
 | 
					
						
							|  |  |  |         PerformanceTimeline, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-03 01:29:31 +02:00
										 |  |  |         // https://html.spec.whatwg.org/multipage/canvas.html#canvas-blob-serialisation-task-source
 | 
					
						
							|  |  |  |         CanvasBlobSerializationTask, | 
					
						
							| 
									
										
										
										
											2023-08-29 12:13:50 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-10 13:29:20 -05:00
										 |  |  |         // https://w3c.github.io/clipboard-apis/#clipboard-task-source
 | 
					
						
							|  |  |  |         Clipboard, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // https://w3c.github.io/permissions/#permissions-task-source
 | 
					
						
							|  |  |  |         Permissions, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-13 12:02:38 -06:00
										 |  |  |         // https://drafts.csswg.org/css-font-loading/#task-source
 | 
					
						
							|  |  |  |         FontLoading, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-05 13:33:41 -04:00
										 |  |  |         // https://html.spec.whatwg.org/multipage/server-sent-events.html#remote-event-task-source
 | 
					
						
							|  |  |  |         RemoteEvent, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-03 17:44:57 +02:00
										 |  |  |         // https://html.spec.whatwg.org/multipage/webappapis.html#rendering-task-source
 | 
					
						
							|  |  |  |         Rendering, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-04 18:15:26 +01:00
										 |  |  |         // https://w3c.github.io/IndexedDB/#database-access-task-source
 | 
					
						
							|  |  |  |         DatabaseAccess, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 18:56:16 +01:00
										 |  |  |         // https://websockets.spec.whatwg.org/#websocket-task-source
 | 
					
						
							|  |  |  |         WebSocket, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-29 12:13:50 -05:00
										 |  |  |         // !!! IMPORTANT: Keep this field last!
 | 
					
						
							|  |  |  |         // This serves as the base value of all unique task sources.
 | 
					
						
							|  |  |  |         // Some elements, such as the HTMLMediaElement, must have a unique task source per instance.
 | 
					
						
							|  |  |  |         UniqueTaskSourceStart | 
					
						
							| 
									
										
										
										
											2021-09-08 23:53:55 +02:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     static GC::Ref<Task> create(JS::VM&, Source, GC::Ptr<DOM::Document const>, GC::Ref<GC::Function<void()>> steps); | 
					
						
							| 
									
										
										
										
											2024-04-04 12:06:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtual ~Task() override; | 
					
						
							| 
									
										
										
										
											2021-09-08 23:09:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-04 17:10:49 +02:00
										 |  |  |     [[nodiscard]] TaskID id() const { return m_id; } | 
					
						
							| 
									
										
										
										
											2021-09-08 23:53:55 +02:00
										 |  |  |     Source source() const { return m_source; } | 
					
						
							| 
									
										
										
										
											2021-09-08 23:09:18 +02:00
										 |  |  |     void execute(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  |     DOM::Document const* document() const; | 
					
						
							| 
									
										
										
										
											2021-09-08 23:09:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-03 15:38:11 +02:00
										 |  |  |     bool is_runnable() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 23:09:18 +02:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     Task(Source, GC::Ptr<DOM::Document const>, GC::Ref<GC::Function<void()>> steps); | 
					
						
							| 
									
										
										
										
											2024-04-04 12:06:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtual void visit_edges(Visitor&) override; | 
					
						
							| 
									
										
										
										
											2021-09-08 23:09:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-04 17:10:49 +02:00
										 |  |  |     TaskID m_id {}; | 
					
						
							| 
									
										
										
										
											2021-09-08 23:53:55 +02:00
										 |  |  |     Source m_source { Source::Unspecified }; | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC::Ref<GC::Function<void()>> m_steps; | 
					
						
							|  |  |  |     GC::Ptr<DOM::Document const> m_document; | 
					
						
							| 
									
										
										
										
											2021-09-08 23:09:18 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-04 09:02:00 -04:00
										 |  |  | struct UniqueTaskSource { | 
					
						
							|  |  |  |     UniqueTaskSource(); | 
					
						
							|  |  |  |     ~UniqueTaskSource(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Task::Source const source; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 23:09:18 +02:00
										 |  |  | } |