/* * Copyright (c) 2023, Linus Groh * Copyright (c) 2023, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include #include #include namespace Web::HTML { // https://html.spec.whatwg.org/#timerhandler using TimerHandler = Variant, String>; // https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope class WindowOrWorkerGlobalScopeMixin { public: virtual ~WindowOrWorkerGlobalScopeMixin(); virtual DOM::EventTarget& this_impl() = 0; virtual DOM::EventTarget const& this_impl() const = 0; // JS API functions String origin() const; bool is_secure_context() const; bool cross_origin_isolated() const; GC::Ref create_image_bitmap(ImageBitmapSource image, Optional options = {}) const; GC::Ref create_image_bitmap(ImageBitmapSource image, WebIDL::Long sx, WebIDL::Long sy, WebIDL::Long sw, WebIDL::Long sh, Optional options = {}) const; GC::Ref fetch(Fetch::RequestInfo const&, Fetch::RequestInit const&) const; i32 set_timeout(TimerHandler, i32 timeout, GC::MarkedVector arguments); i32 set_interval(TimerHandler, i32 timeout, GC::MarkedVector arguments); void clear_timeout(i32); void clear_interval(i32); void clear_map_of_active_timers(); PerformanceTimeline::PerformanceEntryTuple& relevant_performance_entry_tuple(FlyString const& entry_type); void queue_performance_entry(GC::Ref new_entry); void clear_performance_entry_buffer(Badge, FlyString const& entry_type); void remove_entries_from_performance_entry_buffer(Badge, FlyString const& entry_type, String entry_name); ErrorOr>> filter_buffer_map_by_name_and_type(Optional name, Optional type) const; void register_performance_observer(Badge, GC::Ref); void unregister_performance_observer(Badge, GC::Ref); bool has_registered_performance_observer(GC::Ref); void queue_the_performance_observer_task(); void register_event_source(Badge, GC::Ref); void unregister_event_source(Badge, GC::Ref); void forcibly_close_all_event_sources(); void run_steps_after_a_timeout(i32 timeout, Function completion_step); [[nodiscard]] GC::Ref performance(); GC::Ref supported_entry_types() const; GC::Ref indexed_db(); void report_error(JS::Value e); void report_an_exception(JS::Value const& e); [[nodiscard]] GC::Ref crypto(); protected: void initialize(JS::Realm&); void visit_edges(JS::Cell::Visitor&); void finalize(); private: enum class Repeat { Yes, No, }; i32 run_timer_initialization_steps(TimerHandler handler, i32 timeout, GC::MarkedVector arguments, Repeat repeat, Optional previous_id = {}); void run_steps_after_a_timeout_impl(i32 timeout, Function completion_step, Optional timer_key = {}); GC::Ref create_image_bitmap_impl(ImageBitmapSource& image, Optional sx, Optional sy, Optional sw, Optional sh, Optional& options) const; IDAllocator m_timer_id_allocator; HashMap> m_timers; // https://www.w3.org/TR/performance-timeline/#performance-timeline // Each global object has: // - a performance observer task queued flag bool m_performance_observer_task_queued { false }; // - a list of registered performance observer objects that is initially empty OrderedHashTable> m_registered_performance_observer_objects; // https://www.w3.org/TR/performance-timeline/#dfn-performance-entry-buffer-map // a performance entry buffer map map, keyed on a DOMString, representing the entry type to which the buffer belongs. The map's value is the following tuple: // NOTE: See the PerformanceEntryTuple struct above for the map's value tuple. OrderedHashMap m_performance_entry_buffer_map; HashTable> m_registered_event_sources; GC::Ptr m_performance; GC::Ptr m_indexed_db; mutable GC::Ptr m_supported_entry_types_array; GC::Ptr m_crypto; bool m_error_reporting_mode { false }; }; }