Performance.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/PerformanceWrapper.h>
  7. #include <LibWeb/DOM/Document.h>
  8. #include <LibWeb/DOM/Event.h>
  9. #include <LibWeb/DOM/EventDispatcher.h>
  10. #include <LibWeb/DOM/Window.h>
  11. #include <LibWeb/HighResolutionTime/Performance.h>
  12. namespace Web::HighResolutionTime {
  13. Performance::Performance(DOM::Window& window)
  14. : DOM::EventTarget(static_cast<Bindings::ScriptExecutionContext&>(window.document()))
  15. , m_window(window)
  16. , m_timing(make<NavigationTiming::PerformanceTiming>(window))
  17. {
  18. m_timer.start();
  19. }
  20. Performance::~Performance()
  21. {
  22. }
  23. double Performance::time_origin() const
  24. {
  25. auto origin = m_timer.origin_time();
  26. return (origin.tv_sec * 1000.0) + (origin.tv_usec / 1000.0);
  27. }
  28. void Performance::ref_event_target()
  29. {
  30. m_window.ref();
  31. }
  32. void Performance::unref_event_target()
  33. {
  34. m_window.unref();
  35. }
  36. bool Performance::dispatch_event(NonnullRefPtr<DOM::Event> event)
  37. {
  38. return DOM::EventDispatcher::dispatch(*this, event);
  39. }
  40. JS::Object* Performance::create_wrapper(JS::GlobalObject& global_object)
  41. {
  42. return Bindings::wrap(global_object, *this);
  43. }
  44. }