TimeOrigin.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <AK/Time.h>
  8. #include <LibWeb/HighResolutionTime/TimeOrigin.h>
  9. namespace Web::HighResolutionTime {
  10. // https://w3c.github.io/hr-time/#dfn-coarsen-time
  11. DOMHighResTimeStamp coarsen_time(DOMHighResTimeStamp timestamp, bool cross_origin_isolated_capability)
  12. {
  13. // FIXME: Implement this.
  14. (void)cross_origin_isolated_capability;
  15. return timestamp;
  16. }
  17. // https://w3c.github.io/hr-time/#dfn-coarsened-shared-current-time
  18. DOMHighResTimeStamp coarsened_shared_current_time(bool cross_origin_isolated_capability)
  19. {
  20. // The coarsened shared current time given an optional boolean crossOriginIsolatedCapability (default false), must return the result of calling coarsen time with the unsafe shared current time and crossOriginIsolatedCapability.
  21. return coarsen_time(unsafe_shared_current_time(), cross_origin_isolated_capability);
  22. }
  23. // https://w3c.github.io/hr-time/#dfn-unsafe-shared-current-time
  24. DOMHighResTimeStamp unsafe_shared_current_time()
  25. {
  26. // The unsafe shared current time must return the current value of the shared monotonic clock.
  27. return Time::now_monotonic().to_nanoseconds() / 1e6;
  28. }
  29. }