2020-09-29 13:19:18 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2020, Andreas Kling <andreas@ladybird.org>
|
2023-03-22 16:12:57 -03:00
|
|
|
* Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
|
2020-09-29 13:19:18 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-09-29 13:19:18 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <LibCore/ElapsedTimer.h>
|
|
|
|
|
#include <LibWeb/DOM/EventTarget.h>
|
2024-03-30 07:04:31 -03:00
|
|
|
#include <LibWeb/HTML/WindowOrWorkerGlobalScope.h>
|
2023-03-23 14:07:52 -03:00
|
|
|
#include <LibWeb/UserTiming/PerformanceMark.h>
|
2023-05-13 09:34:28 -03:00
|
|
|
#include <LibWeb/UserTiming/PerformanceMeasure.h>
|
2020-09-29 13:19:18 -03:00
|
|
|
|
|
|
|
|
namespace Web::HighResolutionTime {
|
|
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
class Performance final : public DOM::EventTarget {
|
|
|
|
|
WEB_PLATFORM_OBJECT(Performance, DOM::EventTarget);
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DECLARE_ALLOCATOR(Performance);
|
2020-09-29 13:19:18 -03:00
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
public:
|
|
|
|
|
virtual ~Performance() override;
|
2020-09-29 13:19:18 -03:00
|
|
|
|
2024-10-05 13:01:19 -03:00
|
|
|
double now() const;
|
2020-09-29 13:31:07 -03:00
|
|
|
double time_origin() const;
|
2020-09-29 13:19:18 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
WebIDL::ExceptionOr<GC::Ref<UserTiming::PerformanceMark>> mark(String const& mark_name, UserTiming::PerformanceMarkOptions const& mark_options = {});
|
2023-03-23 14:07:52 -03:00
|
|
|
void clear_marks(Optional<String> mark_name);
|
2024-11-14 12:01:23 -03:00
|
|
|
WebIDL::ExceptionOr<GC::Ref<UserTiming::PerformanceMeasure>> measure(String const& measure_name, Variant<String, UserTiming::PerformanceMeasureOptions> const& start_or_measure_options, Optional<String> end_mark);
|
2023-05-13 09:34:28 -03:00
|
|
|
void clear_measures(Optional<String> measure_name);
|
2023-03-23 14:07:52 -03:00
|
|
|
|
2025-02-26 12:51:05 -03:00
|
|
|
void clear_resource_timings();
|
|
|
|
|
void set_resource_timing_buffer_size(u32 max_size);
|
|
|
|
|
void set_onresourcetimingbufferfull(WebIDL::CallbackType*);
|
|
|
|
|
WebIDL::CallbackType* onresourcetimingbufferfull();
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
WebIDL::ExceptionOr<Vector<GC::Root<PerformanceTimeline::PerformanceEntry>>> get_entries() const;
|
|
|
|
|
WebIDL::ExceptionOr<Vector<GC::Root<PerformanceTimeline::PerformanceEntry>>> get_entries_by_type(String const& type) const;
|
|
|
|
|
WebIDL::ExceptionOr<Vector<GC::Root<PerformanceTimeline::PerformanceEntry>>> get_entries_by_name(String const& name, Optional<String> type) const;
|
2023-03-22 16:12:57 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<NavigationTiming::PerformanceTiming> timing();
|
|
|
|
|
GC::Ptr<NavigationTiming::PerformanceNavigation> navigation();
|
2024-08-01 22:50:52 -03:00
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
private:
|
2024-04-05 22:04:01 -03:00
|
|
|
explicit Performance(JS::Realm&);
|
|
|
|
|
|
|
|
|
|
HTML::WindowOrWorkerGlobalScopeMixin& window_or_worker();
|
|
|
|
|
HTML::WindowOrWorkerGlobalScopeMixin const& window_or_worker() const;
|
2021-01-18 11:06:13 -03:00
|
|
|
|
2023-08-07 03:41:28 -03:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2022-08-28 08:42:07 -03:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
2020-09-29 13:19:18 -03:00
|
|
|
|
2023-05-13 09:34:28 -03:00
|
|
|
WebIDL::ExceptionOr<HighResolutionTime::DOMHighResTimeStamp> convert_name_to_timestamp(JS::Realm& realm, String const& name);
|
|
|
|
|
WebIDL::ExceptionOr<HighResolutionTime::DOMHighResTimeStamp> convert_mark_to_timestamp(JS::Realm& realm, Variant<String, HighResolutionTime::DOMHighResTimeStamp> mark);
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<NavigationTiming::PerformanceNavigation> m_navigation;
|
|
|
|
|
GC::Ptr<NavigationTiming::PerformanceTiming> m_timing;
|
2020-09-29 13:19:18 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|