/src/serenity/Userland/Libraries/LibWeb/EventTiming/PerformanceEventTiming.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2024, Noah Bright <noah.bright.1@gmail.com> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibWeb/Bindings/Intrinsics.h> |
8 | | #include <LibWeb/Bindings/PerformanceEventTimingPrototype.h> |
9 | | #include <LibWeb/DOM/Event.h> |
10 | | #include <LibWeb/EventTiming/PerformanceEventTiming.h> |
11 | | #include <LibWeb/PerformanceTimeline/EntryTypes.h> |
12 | | |
13 | | namespace Web::EventTiming { |
14 | | |
15 | | JS_DEFINE_ALLOCATOR(PerformanceEventTiming); |
16 | | |
17 | | // https://www.w3.org/TR/event-timing/#sec-init-event-timing |
18 | | PerformanceEventTiming::PerformanceEventTiming(JS::Realm& realm, String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration, |
19 | | DOM::Event const& event, HighResolutionTime::DOMHighResTimeStamp processing_start, unsigned long long interaction_id) |
20 | 0 | : PerformanceTimeline::PerformanceEntry(realm, name, start_time, duration) |
21 | 0 | , m_entry_type(PerformanceTimeline::EntryTypes::event) |
22 | 0 | , m_start_time(event.time_stamp()) |
23 | 0 | , m_processing_start(processing_start) |
24 | 0 | , m_cancelable(event.cancelable()) |
25 | 0 | , m_interaction_id(interaction_id) |
26 | | |
27 | 0 | { |
28 | 0 | } |
29 | | |
30 | 0 | PerformanceEventTiming::~PerformanceEventTiming() = default; |
31 | | |
32 | | FlyString const& PerformanceEventTiming::entry_type() const |
33 | 0 | { |
34 | 0 | return m_entry_type; |
35 | 0 | } |
36 | | |
37 | | HighResolutionTime::DOMHighResTimeStamp PerformanceEventTiming::processing_end() const |
38 | 0 | { |
39 | 0 | dbgln("FIXME: Implement PeformanceEventTiming processing_end()"); |
40 | 0 | return 0; |
41 | 0 | } |
42 | | |
43 | | HighResolutionTime::DOMHighResTimeStamp PerformanceEventTiming::processing_start() const |
44 | 0 | { |
45 | 0 | dbgln("FIXME: Implement PeformanceEventTiming processing_start()"); |
46 | 0 | return 0; |
47 | 0 | } |
48 | | |
49 | | bool PerformanceEventTiming::cancelable() const |
50 | 0 | { |
51 | 0 | return m_cancelable; |
52 | 0 | } |
53 | | |
54 | | JS::ThrowCompletionOr<JS::GCPtr<DOM::Node>> PerformanceEventTiming::target() |
55 | 0 | { |
56 | 0 | dbgln("FIXME: Implement PerformanceEventTiming::PeformanceEventTiming target()"); |
57 | 0 | return nullptr; |
58 | 0 | } |
59 | | |
60 | | unsigned long long PerformanceEventTiming::interaction_id() |
61 | 0 | { |
62 | 0 | dbgln("FIXME: Implement PeformanceEventTiming interaction_id()"); |
63 | 0 | return 0; |
64 | 0 | } |
65 | | |
66 | | // https://www.w3.org/TR/event-timing/#sec-should-add-performanceeventtiming |
67 | | PerformanceTimeline::ShouldAddEntry PerformanceEventTiming::should_add_performance_event_timing() const |
68 | 0 | { |
69 | 0 | dbgln("FIXME: Implement PeformanceEventTiming should_add_performance_event_timing()"); |
70 | | // 1. If entry’s entryType attribute value equals to "first-input", return true. |
71 | 0 | if (entry_type() == "first-input") |
72 | 0 | return PerformanceTimeline::ShouldAddEntry::Yes; |
73 | | |
74 | | // 2. Assert that entry’s entryType attribute value equals "event". |
75 | 0 | VERIFY(entry_type() == "event"); |
76 | | |
77 | | // FIXME: 3. Let minDuration be computed as follows: |
78 | | // FIXME: 3.1. If options is not present or if options’s durationThreshold is not present, let minDuration be 104. |
79 | | // FIXME: 3.2. Otherwise, let minDuration be the maximum between 16 and options’s durationThreshold value. |
80 | | |
81 | | // FIXME: 4. If entry’s duration attribute value is greater than or equal to minDuration, return true. |
82 | | |
83 | | // 5. Otherwise, return false. |
84 | 0 | return PerformanceTimeline::ShouldAddEntry::No; |
85 | 0 | } |
86 | | |
87 | | // https://w3c.github.io/timing-entrytypes-registry/#dfn-availablefromtimeline |
88 | | // FIXME: the output here depends on the type of the object instance, but this function is static |
89 | | // the commented out if statement won't compile |
90 | | PerformanceTimeline::AvailableFromTimeline PerformanceEventTiming::available_from_timeline() |
91 | 0 | { |
92 | 0 | dbgln("FIXME: Implement PeformanceEventTiming available_from_timeline()"); |
93 | | // if (entry_type() == "first-input") |
94 | 0 | return PerformanceTimeline::AvailableFromTimeline::Yes; |
95 | 0 | } |
96 | | |
97 | | // https://w3c.github.io/timing-entrytypes-registry/#dfn-maxbuffersize |
98 | | // FIXME: Same issue as available_from_timeline() above |
99 | | Optional<u64> PerformanceEventTiming::max_buffer_size() |
100 | 0 | { |
101 | 0 | dbgln("FIXME: Implement PeformanceEventTiming max_buffer_size()"); |
102 | 0 | if (true) //(entry_type() == "first-input") |
103 | 0 | return 1; |
104 | | // else return 150; |
105 | 0 | } |
106 | | |
107 | | // https://w3c.github.io/timing-entrytypes-registry/#dfn-should-add-entry |
108 | | PerformanceTimeline::ShouldAddEntry PerformanceEventTiming::should_add_entry(Optional<PerformanceTimeline::PerformanceObserverInit const&>) const |
109 | 0 | { |
110 | 0 | return should_add_performance_event_timing(); |
111 | 0 | } |
112 | | |
113 | | void PerformanceEventTiming::initialize(JS::Realm& realm) |
114 | 0 | { |
115 | 0 | Base::initialize(realm); |
116 | 0 | WEB_SET_PROTOTYPE_FOR_INTERFACE(PerformanceEventTiming); |
117 | 0 | } |
118 | | |
119 | | void PerformanceEventTiming::visit_edges(JS::Cell::Visitor& visitor) |
120 | 0 | { |
121 | 0 | Base::visit_edges(visitor); |
122 | 0 | visitor.visit(m_event_target); |
123 | 0 | } |
124 | | |
125 | | } |