WindowOrWorkerGlobalScope.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2023, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Forward.h>
  8. #include <AK/HashMap.h>
  9. #include <AK/IDAllocator.h>
  10. #include <AK/Variant.h>
  11. #include <LibWeb/Bindings/PlatformObject.h>
  12. #include <LibWeb/Fetch/Request.h>
  13. #include <LibWeb/Forward.h>
  14. #include <LibWeb/HTML/MessagePort.h>
  15. namespace Web::HTML {
  16. // https://html.spec.whatwg.org/#timerhandler
  17. using TimerHandler = Variant<JS::Handle<WebIDL::CallbackType>, DeprecatedString>;
  18. // https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope
  19. class WindowOrWorkerGlobalScopeMixin {
  20. public:
  21. virtual ~WindowOrWorkerGlobalScopeMixin();
  22. virtual Bindings::PlatformObject& this_impl() = 0;
  23. virtual Bindings::PlatformObject const& this_impl() const = 0;
  24. // JS API functions
  25. WebIDL::ExceptionOr<String> origin() const;
  26. bool is_secure_context() const;
  27. bool cross_origin_isolated() const;
  28. WebIDL::ExceptionOr<String> btoa(String const& data) const;
  29. WebIDL::ExceptionOr<String> atob(String const& data) const;
  30. void queue_microtask(WebIDL::CallbackType&);
  31. WebIDL::ExceptionOr<JS::Value> structured_clone(JS::Value, StructuredSerializeOptions const&) const;
  32. JS::NonnullGCPtr<JS::Promise> fetch(Fetch::RequestInfo const&, Fetch::RequestInit const&) const;
  33. i32 set_timeout(TimerHandler, i32 timeout, JS::MarkedVector<JS::Value> arguments);
  34. i32 set_interval(TimerHandler, i32 timeout, JS::MarkedVector<JS::Value> arguments);
  35. void clear_timeout(i32);
  36. void clear_interval(i32);
  37. protected:
  38. void visit_edges(JS::Cell::Visitor&);
  39. private:
  40. enum class Repeat {
  41. Yes,
  42. No,
  43. };
  44. i32 run_timer_initialization_steps(TimerHandler handler, i32 timeout, JS::MarkedVector<JS::Value> arguments, Repeat repeat, Optional<i32> previous_id = {}, Optional<AK::URL> base_url = {});
  45. IDAllocator m_timer_id_allocator;
  46. HashMap<int, JS::NonnullGCPtr<Timer>> m_timers;
  47. };
  48. }