Performance.cpp 1019 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/HTML/Window.h>
  11. #include <LibWeb/HighResolutionTime/Performance.h>
  12. namespace Web::HighResolutionTime {
  13. Performance::Performance(HTML::Window& window)
  14. : DOM::EventTarget()
  15. , m_window(window)
  16. , m_timing(make<NavigationTiming::PerformanceTiming>(window))
  17. {
  18. m_timer.start();
  19. }
  20. Performance::~Performance() = default;
  21. double Performance::time_origin() const
  22. {
  23. auto origin = m_timer.origin_time();
  24. return (origin.tv_sec * 1000.0) + (origin.tv_usec / 1000.0);
  25. }
  26. void Performance::ref_event_target()
  27. {
  28. m_window.ref();
  29. }
  30. void Performance::unref_event_target()
  31. {
  32. m_window.unref();
  33. }
  34. JS::Object* Performance::create_wrapper(JS::GlobalObject& global_object)
  35. {
  36. return Bindings::wrap(global_object, *this);
  37. }
  38. }