PerformanceEventTiming.cpp 4.4 KB

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