2020-09-29 13:19:18 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-09-29 13:19:18 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibWeb/Bindings/PerformanceWrapper.h>
|
|
|
|
|
#include <LibWeb/DOM/Document.h>
|
|
|
|
|
#include <LibWeb/DOM/Event.h>
|
|
|
|
|
#include <LibWeb/DOM/EventDispatcher.h>
|
2022-03-07 19:08:26 -03:00
|
|
|
#include <LibWeb/HTML/Window.h>
|
2020-09-29 13:19:18 -03:00
|
|
|
#include <LibWeb/HighResolutionTime/Performance.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::HighResolutionTime {
|
|
|
|
|
|
2022-03-07 19:08:26 -03:00
|
|
|
Performance::Performance(HTML::Window& window)
|
2021-10-14 14:03:08 -03:00
|
|
|
: DOM::EventTarget()
|
2020-09-29 13:19:18 -03:00
|
|
|
, m_window(window)
|
2021-01-18 11:06:13 -03:00
|
|
|
, m_timing(make<NavigationTiming::PerformanceTiming>(window))
|
2020-09-29 13:19:18 -03:00
|
|
|
{
|
|
|
|
|
m_timer.start();
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-14 16:21:51 -03:00
|
|
|
Performance::~Performance() = default;
|
2020-09-29 13:19:18 -03:00
|
|
|
|
2020-09-29 13:31:07 -03:00
|
|
|
double Performance::time_origin() const
|
|
|
|
|
{
|
|
|
|
|
auto origin = m_timer.origin_time();
|
|
|
|
|
return (origin.tv_sec * 1000.0) + (origin.tv_usec / 1000.0);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-29 13:19:18 -03:00
|
|
|
void Performance::ref_event_target()
|
|
|
|
|
{
|
|
|
|
|
m_window.ref();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Performance::unref_event_target()
|
|
|
|
|
{
|
|
|
|
|
m_window.unref();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-18 08:15:02 -03:00
|
|
|
JS::Object* Performance::create_wrapper(JS::GlobalObject& global_object)
|
2020-09-29 13:19:18 -03:00
|
|
|
{
|
|
|
|
|
return Bindings::wrap(global_object, *this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|