2021-09-08 23:09:18 +02:00
|
|
|
/*
|
2024-04-04 12:06:50 +02:00
|
|
|
* Copyright (c) 2021-2024, Andreas Kling <kling@serenityos.org>
|
2021-09-08 23:09:18 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2024-04-04 12:06:50 +02:00
|
|
|
#include <LibJS/Heap/Cell.h>
|
|
|
|
#include <LibJS/Heap/CellAllocator.h>
|
2022-09-24 12:04:06 +02:00
|
|
|
#include <LibJS/SafeFunction.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-04-04 12:06:50 +02:00
|
|
|
class Task final : public JS::Cell {
|
|
|
|
JS_CELL(Task, Cell);
|
|
|
|
JS_DECLARE_ALLOCATOR(Task);
|
|
|
|
|
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,
|
|
|
|
|
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-04-04 12:06:50 +02:00
|
|
|
static JS::NonnullGCPtr<Task> create(JS::VM&, Source, JS::GCPtr<DOM::Document const>, JS::NonnullGCPtr<JS::HeapFunction<void()>> steps);
|
|
|
|
|
|
|
|
virtual ~Task() override;
|
|
|
|
virtual void finalize() override;
|
2021-09-08 23:09:18 +02:00
|
|
|
|
2023-08-31 13:25:27 -04:00
|
|
|
int 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-04-04 12:06:50 +02:00
|
|
|
Task(Source, JS::GCPtr<DOM::Document const>, JS::NonnullGCPtr<JS::HeapFunction<void()>> steps);
|
|
|
|
|
|
|
|
virtual void visit_edges(Visitor&) override;
|
2021-09-08 23:09:18 +02:00
|
|
|
|
2023-08-31 13:25:27 -04:00
|
|
|
int m_id { 0 };
|
2021-09-08 23:53:55 +02:00
|
|
|
Source m_source { Source::Unspecified };
|
2024-04-04 12:06:50 +02:00
|
|
|
JS::NonnullGCPtr<JS::HeapFunction<void()>> m_steps;
|
|
|
|
JS::GCPtr<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
|
|
|
}
|