Task.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2021, 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 <LibWeb/Forward.h>
  12. namespace Web::HTML {
  13. class Task {
  14. public:
  15. // https://html.spec.whatwg.org/multipage/webappapis.html#generic-task-sources
  16. enum class Source {
  17. Unspecified,
  18. DOMManipulation,
  19. UserInteraction,
  20. Networking,
  21. HistoryTraversal,
  22. IdleTask,
  23. PostedMessage,
  24. Microtask,
  25. TimerTask,
  26. JavaScriptEngine,
  27. };
  28. static NonnullOwnPtr<Task> create(Source source, DOM::Document* document, Function<void()> steps)
  29. {
  30. return adopt_own(*new Task(source, document, move(steps)));
  31. }
  32. ~Task();
  33. Source source() const { return m_source; }
  34. void execute();
  35. DOM::Document* document();
  36. DOM::Document const* document() const;
  37. bool is_runnable() const;
  38. private:
  39. Task(Source, DOM::Document*, Function<void()> steps);
  40. Source m_source { Source::Unspecified };
  41. Function<void()> m_steps;
  42. JS::Handle<DOM::Document> m_document;
  43. };
  44. }