2020-09-29 18:19:18 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-09-29 18:19:18 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibWeb/DOM/Document.h>
|
|
|
|
#include <LibWeb/DOM/Event.h>
|
|
|
|
#include <LibWeb/DOM/EventDispatcher.h>
|
2022-03-07 23:08:26 +01:00
|
|
|
#include <LibWeb/HTML/Window.h>
|
2020-09-29 18:19:18 +02:00
|
|
|
#include <LibWeb/HighResolutionTime/Performance.h>
|
2022-08-31 19:12:11 +02:00
|
|
|
#include <LibWeb/NavigationTiming/PerformanceTiming.h>
|
2020-09-29 18:19:18 +02:00
|
|
|
|
|
|
|
namespace Web::HighResolutionTime {
|
|
|
|
|
2022-03-07 23:08:26 +01:00
|
|
|
Performance::Performance(HTML::Window& window)
|
2022-08-28 13:42:07 +02:00
|
|
|
: DOM::EventTarget(window.realm())
|
2020-09-29 18:19:18 +02:00
|
|
|
, m_window(window)
|
|
|
|
{
|
|
|
|
m_timer.start();
|
|
|
|
}
|
|
|
|
|
2022-03-14 13:21:51 -06:00
|
|
|
Performance::~Performance() = default;
|
2020-09-29 18:19:18 +02:00
|
|
|
|
2023-01-28 12:33:35 -05:00
|
|
|
JS::ThrowCompletionOr<void> Performance::initialize(JS::Realm& realm)
|
2023-01-10 06:28:20 -05:00
|
|
|
{
|
2023-01-28 12:33:35 -05:00
|
|
|
MUST_OR_THROW_OOM(Base::initialize(realm));
|
2023-01-10 06:28:20 -05:00
|
|
|
set_prototype(&Bindings::ensure_web_prototype<Bindings::PerformancePrototype>(realm, "Performance"));
|
2023-01-28 12:33:35 -05:00
|
|
|
|
|
|
|
return {};
|
2023-01-10 06:28:20 -05:00
|
|
|
}
|
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
void Performance::visit_edges(Cell::Visitor& visitor)
|
2020-09-29 18:19:18 +02:00
|
|
|
{
|
2022-08-28 13:42:07 +02:00
|
|
|
Base::visit_edges(visitor);
|
|
|
|
visitor.visit(m_window.ptr());
|
2022-08-31 19:12:11 +02:00
|
|
|
visitor.visit(m_timing.ptr());
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::GCPtr<NavigationTiming::PerformanceTiming> Performance::timing()
|
|
|
|
{
|
|
|
|
if (!m_timing)
|
2023-01-28 13:39:44 -05:00
|
|
|
m_timing = heap().allocate<NavigationTiming::PerformanceTiming>(realm(), *m_window).release_allocated_value_but_fixme_should_propagate_errors();
|
2022-08-31 19:12:11 +02:00
|
|
|
return m_timing;
|
2020-09-29 18:19:18 +02:00
|
|
|
}
|
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
double Performance::time_origin() const
|
2020-09-29 18:19:18 +02:00
|
|
|
{
|
2023-01-01 22:30:31 -07:00
|
|
|
return static_cast<double>(m_timer.origin_time().to_milliseconds());
|
2020-09-29 18:19:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|