Task.h 1.2 KB

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