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
|
|
|
*/
|
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
#include <LibWeb/Bindings/PerformancePrototype.h>
|
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>
|
|
|
|
|
|
|
|
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)
|
2021-01-18 15:06:13 +01:00
|
|
|
, m_timing(make<NavigationTiming::PerformanceTiming>(window))
|
2020-09-29 18:19:18 +02:00
|
|
|
{
|
2022-08-28 13:42:07 +02:00
|
|
|
set_prototype(&window.ensure_web_prototype<Bindings::PerformancePrototype>("Performance"));
|
2020-09-29 18:19:18 +02:00
|
|
|
m_timer.start();
|
|
|
|
}
|
|
|
|
|
2022-03-14 13:21:51 -06:00
|
|
|
Performance::~Performance() = default;
|
2020-09-29 18:19:18 +02: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());
|
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
|
|
|
{
|
2022-08-28 13:42:07 +02:00
|
|
|
auto origin = m_timer.origin_time();
|
|
|
|
return (origin.tv_sec * 1000.0) + (origin.tv_usec / 1000.0);
|
2020-09-29 18:19:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|