blob: f35a6addc98e5a10296c94ef26c633c2bfd27926 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/PerformancePrototype.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/EventDispatcher.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/HighResolutionTime/Performance.h>
#include <LibWeb/NavigationTiming/PerformanceTiming.h>
namespace Web::HighResolutionTime {
Performance::Performance(HTML::Window& window)
: DOM::EventTarget(window.realm())
, m_window(window)
{
set_prototype(&window.ensure_web_prototype<Bindings::PerformancePrototype>("Performance"));
m_timer.start();
}
Performance::~Performance() = default;
void Performance::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_window.ptr());
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;
}
double Performance::time_origin() const
{
auto origin = m_timer.origin_time();
return (origin.tv_sec * 1000.0) + (origin.tv_usec / 1000.0);
}
}
|