2021-09-08 18:09:18 -03:00
|
|
|
/*
|
2022-09-24 07:04:06 -03:00
|
|
|
* Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org>
|
2021-09-08 18:09:18 -03:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/Function.h>
|
|
|
|
|
#include <AK/NonnullOwnPtr.h>
|
|
|
|
|
#include <AK/RefPtr.h>
|
2022-08-28 08:42:07 -03:00
|
|
|
#include <LibJS/Heap/Handle.h>
|
2022-09-24 07:04:06 -03:00
|
|
|
#include <LibJS/SafeFunction.h>
|
2021-09-08 18:09:18 -03:00
|
|
|
#include <LibWeb/Forward.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
|
2023-04-04 10:02:00 -03:00
|
|
|
struct UniqueTaskSource;
|
|
|
|
|
|
2021-09-08 18:09:18 -03:00
|
|
|
class Task {
|
|
|
|
|
public:
|
2021-09-08 18:53:55 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/webappapis.html#generic-task-sources
|
|
|
|
|
enum class Source {
|
|
|
|
|
Unspecified,
|
|
|
|
|
DOMManipulation,
|
|
|
|
|
UserInteraction,
|
|
|
|
|
Networking,
|
|
|
|
|
HistoryTraversal,
|
2021-09-16 18:43:08 -03:00
|
|
|
IdleTask,
|
2021-09-19 17:09:51 -03:00
|
|
|
PostedMessage,
|
2021-09-26 09:36:20 -03:00
|
|
|
Microtask,
|
2021-10-03 07:39:56 -03:00
|
|
|
TimerTask,
|
2022-02-06 00:32:26 -03:00
|
|
|
JavaScriptEngine,
|
2023-04-04 10:02:00 -03:00
|
|
|
|
2023-01-01 13:41:56 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/webappapis.html#navigation-and-traversal-task-source
|
|
|
|
|
NavigationAndTraversal,
|
2023-06-10 04:39:56 -03:00
|
|
|
|
|
|
|
|
// https://w3c.github.io/FileAPI/#fileReadingTaskSource
|
|
|
|
|
FileReading,
|
2023-06-30 07:44:20 -03:00
|
|
|
|
2023-07-06 19:44:07 -03:00
|
|
|
// https://www.w3.org/TR/intersection-observer/#intersectionobserver-task-source
|
|
|
|
|
IntersectionObserver,
|
|
|
|
|
|
2023-08-24 21:26:47 -03:00
|
|
|
// https://w3c.github.io/performance-timeline/#dfn-performance-timeline-task-source
|
|
|
|
|
PerformanceTimeline,
|
|
|
|
|
|
2023-08-02 20:29:31 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/canvas.html#canvas-blob-serialisation-task-source
|
|
|
|
|
CanvasBlobSerializationTask,
|
2023-08-29 14:13:50 -03: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 18:53:55 -03:00
|
|
|
};
|
|
|
|
|
|
2023-02-25 14:44:51 -03:00
|
|
|
static NonnullOwnPtr<Task> create(Source source, DOM::Document const* document, JS::SafeFunction<void()> steps)
|
2021-09-08 18:09:18 -03:00
|
|
|
{
|
2021-09-08 18:53:55 -03:00
|
|
|
return adopt_own(*new Task(source, document, move(steps)));
|
2021-09-08 18:09:18 -03:00
|
|
|
}
|
|
|
|
|
~Task();
|
|
|
|
|
|
2023-08-31 14:25:27 -03:00
|
|
|
int id() const { return m_id; }
|
2021-09-08 18:53:55 -03:00
|
|
|
Source source() const { return m_source; }
|
2021-09-08 18:09:18 -03:00
|
|
|
void execute();
|
|
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
DOM::Document const* document() const;
|
2021-09-08 18:09:18 -03:00
|
|
|
|
2021-10-03 10:38:11 -03:00
|
|
|
bool is_runnable() const;
|
|
|
|
|
|
2021-09-08 18:09:18 -03:00
|
|
|
private:
|
2023-02-25 14:44:51 -03:00
|
|
|
Task(Source, DOM::Document const*, JS::SafeFunction<void()> steps);
|
2021-09-08 18:09:18 -03:00
|
|
|
|
2023-08-31 14:25:27 -03:00
|
|
|
int m_id { 0 };
|
2021-09-08 18:53:55 -03:00
|
|
|
Source m_source { Source::Unspecified };
|
2022-09-24 07:04:06 -03:00
|
|
|
JS::SafeFunction<void()> m_steps;
|
2023-02-25 14:44:51 -03:00
|
|
|
JS::Handle<DOM::Document const> m_document;
|
2021-09-08 18:09:18 -03:00
|
|
|
};
|
|
|
|
|
|
2023-04-04 10:02:00 -03:00
|
|
|
struct UniqueTaskSource {
|
|
|
|
|
UniqueTaskSource();
|
|
|
|
|
~UniqueTaskSource();
|
|
|
|
|
|
|
|
|
|
Task::Source const source;
|
|
|
|
|
};
|
|
|
|
|
|
2021-09-08 18:09:18 -03:00
|
|
|
}
|