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)
|
|
|
|
{
|
LibWeb: Remove unecessary dependence on Window from assorted classes
These classes only needed Window to get at its realm. Pass a realm
directly to construct Crypto, Encoding, HRT, IntersectionObserver,
NavigationTiming, Page, RequestIdleCallback, Selection, Streams, URL,
and XML classes.
2022-09-25 18:11:21 -06:00
|
|
|
set_prototype(&Bindings::cached_web_prototype(realm(), "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());
|
2022-08-31 19:12:11 +02:00
|
|
|
visitor.visit(m_timing.ptr());
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::GCPtr<NavigationTiming::PerformanceTiming> Performance::timing()
|
|
|
|
{
|
|
|
|
if (!m_timing)
|
|
|
|
m_timing = heap().allocate<NavigationTiming::PerformanceTiming>(realm(), *m_window);
|
|
|
|
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
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|