Serenity Operating System
1/*
2 * Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#pragma once
8
9#include <AK/Function.h>
10#include <AK/NonnullOwnPtr.h>
11#include <AK/RefPtr.h>
12#include <LibJS/Heap/Handle.h>
13#include <LibJS/SafeFunction.h>
14#include <LibWeb/Forward.h>
15
16namespace Web::HTML {
17
18class Task {
19public:
20 // https://html.spec.whatwg.org/multipage/webappapis.html#generic-task-sources
21 enum class Source {
22 Unspecified,
23 DOMManipulation,
24 UserInteraction,
25 Networking,
26 HistoryTraversal,
27 IdleTask,
28 PostedMessage,
29 Microtask,
30 TimerTask,
31 JavaScriptEngine,
32 };
33
34 static NonnullOwnPtr<Task> create(Source source, DOM::Document const* document, JS::SafeFunction<void()> steps)
35 {
36 return adopt_own(*new Task(source, document, move(steps)));
37 }
38 ~Task();
39
40 Source source() const { return m_source; }
41 void execute();
42
43 DOM::Document const* document() const;
44
45 bool is_runnable() const;
46
47private:
48 Task(Source, DOM::Document const*, JS::SafeFunction<void()> steps);
49
50 Source m_source { Source::Unspecified };
51 JS::SafeFunction<void()> m_steps;
52 JS::Handle<DOM::Document const> m_document;
53};
54
55}