script: Create a CrossProcessInstant to enable serializable monotonic time (#33282)

Up until now, Servo was using a very old version of time to get a
cross-process monotonic timestamp (using `time::precise_time_ns()`).
This change replaces the usage of old time with a new serializable
monotonic time called `CrossProcessInstant` and uses it where `u64`
timestamps were stored before. The standard library doesn't provide this
functionality because it isn't something you can do reliably on all
platforms. The idea is that we do our best and then fall back
gracefully.

This is a big change, because Servo was using `u64` timestamps all over
the place some as raw values taken from `time::precise_time_ns()` and
some as relative offsets from the "navigation start," which is a concept
similar to DOM's `timeOrigin` (but not exactly the same). It's very
difficult to fix this situation without fixing it everywhere as the
`Instant` concept is supposed to be opaque. The good thing is that this
change clears up all ambiguity when passing times as a `time::Duration`
is unit agnostic and a `CrossProcessInstant` represents an absolute
moment in time.

The `time` version of `Duration` is used because it can both be negative
and is also serializable.

Good things:
 - No need too pass around `time` and `time_precise` any longer.
   `CrossProcessInstant` is also precise and monotonic.
 - The distinction between a time that is unset or at `0` (at some kind
   of timer epoch) is now gone.

There still a lot of work to do to clean up timing, but this is the
first step. In general, I've tried to preserve existing behavior, even
when not spec compliant, as much as possible. I plan to submit followup
PRs fixing some of the issues I've noticed.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2024-09-05 11:50:09 -07:00 committed by GitHub
parent 35baf056f6
commit 312cf0df08
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
51 changed files with 854 additions and 665 deletions

View file

@ -14,6 +14,7 @@ use std::slice::from_ref;
use std::sync::LazyLock;
use std::time::{Duration, Instant};
use base::cross_process_instant::CrossProcessInstant;
use base::id::BrowsingContextId;
use canvas_traits::webgl::{self, WebGLContextId, WebGLMsg};
use content_security_policy::{self as csp, CspList};
@ -342,16 +343,24 @@ pub struct Document {
active_touch_points: DomRefCell<Vec<Dom<Touch>>>,
/// Navigation Timing properties:
/// <https://w3c.github.io/navigation-timing/#sec-PerformanceNavigationTiming>
dom_loading: Cell<u64>,
dom_interactive: Cell<u64>,
dom_content_loaded_event_start: Cell<u64>,
dom_content_loaded_event_end: Cell<u64>,
dom_complete: Cell<u64>,
top_level_dom_complete: Cell<u64>,
load_event_start: Cell<u64>,
load_event_end: Cell<u64>,
unload_event_start: Cell<u64>,
unload_event_end: Cell<u64>,
#[no_trace]
dom_interactive: Cell<Option<CrossProcessInstant>>,
#[no_trace]
dom_content_loaded_event_start: Cell<Option<CrossProcessInstant>>,
#[no_trace]
dom_content_loaded_event_end: Cell<Option<CrossProcessInstant>>,
#[no_trace]
dom_complete: Cell<Option<CrossProcessInstant>>,
#[no_trace]
top_level_dom_complete: Cell<Option<CrossProcessInstant>>,
#[no_trace]
load_event_start: Cell<Option<CrossProcessInstant>>,
#[no_trace]
load_event_end: Cell<Option<CrossProcessInstant>>,
#[no_trace]
unload_event_start: Cell<Option<CrossProcessInstant>>,
#[no_trace]
unload_event_end: Cell<Option<CrossProcessInstant>>,
/// <https://html.spec.whatwg.org/multipage/#concept-document-https-state>
#[no_trace]
https_state: Cell<HttpsState>,
@ -1068,15 +1077,14 @@ impl Document {
self.send_to_embedder(EmbedderMsg::LoadStart);
self.send_to_embedder(EmbedderMsg::Status(None));
}
update_with_current_time_ms(&self.dom_loading);
},
DocumentReadyState::Complete => {
if self.window().is_top_level() {
self.send_to_embedder(EmbedderMsg::LoadComplete);
}
update_with_current_time_ms(&self.dom_complete);
update_with_current_instant(&self.dom_complete);
},
DocumentReadyState::Interactive => update_with_current_time_ms(&self.dom_interactive),
DocumentReadyState::Interactive => update_with_current_instant(&self.dom_interactive),
};
self.ready_state.set(state);
@ -2153,8 +2161,8 @@ impl Document {
let loader = self.loader.borrow();
// Servo measures when the top-level content (not iframes) is loaded.
if (self.top_level_dom_complete.get() == 0) && loader.is_only_blocked_by_iframes() {
update_with_current_time_ms(&self.top_level_dom_complete);
if self.top_level_dom_complete.get().is_none() && loader.is_only_blocked_by_iframes() {
update_with_current_instant(&self.top_level_dom_complete);
}
if loader.is_blocked() || loader.events_inhibited() {
@ -2347,7 +2355,7 @@ impl Document {
event.set_trusted(true);
// http://w3c.github.io/navigation-timing/#widl-PerformanceNavigationTiming-loadEventStart
update_with_current_time_ms(&document.load_event_start);
update_with_current_instant(&document.load_event_start);
debug!("About to dispatch load for {:?}", document.url());
// FIXME(nox): Why are errors silenced here?
@ -2356,7 +2364,7 @@ impl Document {
);
// http://w3c.github.io/navigation-timing/#widl-PerformanceNavigationTiming-loadEventEnd
update_with_current_time_ms(&document.load_event_end);
update_with_current_instant(&document.load_event_end);
if let Some(fragment) = document.url().fragment() {
document.check_and_scroll_fragment(fragment);
@ -2592,7 +2600,7 @@ impl Document {
"Complete before DOMContentLoaded?"
);
update_with_current_time_ms(&self.dom_content_loaded_event_start);
update_with_current_instant(&self.dom_content_loaded_event_start);
// Step 4.1.
let window = self.window();
@ -2604,7 +2612,7 @@ impl Document {
task!(fire_dom_content_loaded_event: move || {
let document = document.root();
document.upcast::<EventTarget>().fire_bubbling_event(atom!("DOMContentLoaded"));
update_with_current_time_ms(&document.dom_content_loaded_event_end);
update_with_current_instant(&document.dom_content_loaded_event_end);
}),
window.upcast(),
)
@ -2690,15 +2698,11 @@ impl Document {
.find(|node| node.browsing_context_id() == Some(browsing_context_id))
}
pub fn get_dom_loading(&self) -> u64 {
self.dom_loading.get()
}
pub fn get_dom_interactive(&self) -> u64 {
pub fn get_dom_interactive(&self) -> Option<CrossProcessInstant> {
self.dom_interactive.get()
}
pub fn set_navigation_start(&self, navigation_start: u64) {
pub fn set_navigation_start(&self, navigation_start: CrossProcessInstant) {
self.interactive_time
.borrow_mut()
.set_navigation_start(navigation_start);
@ -2712,35 +2716,35 @@ impl Document {
self.get_interactive_metrics().get_tti().is_some()
}
pub fn get_dom_content_loaded_event_start(&self) -> u64 {
pub fn get_dom_content_loaded_event_start(&self) -> Option<CrossProcessInstant> {
self.dom_content_loaded_event_start.get()
}
pub fn get_dom_content_loaded_event_end(&self) -> u64 {
pub fn get_dom_content_loaded_event_end(&self) -> Option<CrossProcessInstant> {
self.dom_content_loaded_event_end.get()
}
pub fn get_dom_complete(&self) -> u64 {
pub fn get_dom_complete(&self) -> Option<CrossProcessInstant> {
self.dom_complete.get()
}
pub fn get_top_level_dom_complete(&self) -> u64 {
pub fn get_top_level_dom_complete(&self) -> Option<CrossProcessInstant> {
self.top_level_dom_complete.get()
}
pub fn get_load_event_start(&self) -> u64 {
pub fn get_load_event_start(&self) -> Option<CrossProcessInstant> {
self.load_event_start.get()
}
pub fn get_load_event_end(&self) -> u64 {
pub fn get_load_event_end(&self) -> Option<CrossProcessInstant> {
self.load_event_end.get()
}
pub fn get_unload_event_start(&self) -> u64 {
pub fn get_unload_event_start(&self) -> Option<CrossProcessInstant> {
self.unload_event_start.get()
}
pub fn get_unload_event_end(&self) -> u64 {
pub fn get_unload_event_end(&self) -> Option<CrossProcessInstant> {
self.unload_event_end.get()
}
@ -3236,7 +3240,6 @@ impl Document {
pending_restyles: DomRefCell::new(HashMap::new()),
needs_paint: Cell::new(false),
active_touch_points: DomRefCell::new(Vec::new()),
dom_loading: Cell::new(Default::default()),
dom_interactive: Cell::new(Default::default()),
dom_content_loaded_event_start: Cell::new(Default::default()),
dom_content_loaded_event_end: Cell::new(Default::default()),
@ -4101,11 +4104,8 @@ impl Document {
self.visibility_state.set(visibility_state);
// Step 3 Queue a new VisibilityStateEntry whose visibility state is visibilityState and whose timestamp is
// the current high resolution time given document's relevant global object.
let entry = VisibilityStateEntry::new(
&self.global(),
visibility_state,
*self.global().performance().Now(),
);
let entry =
VisibilityStateEntry::new(&self.global(), visibility_state, CrossProcessInstant::now());
self.window
.Performance()
.queue_entry(entry.upcast::<PerformanceEntry>());
@ -5441,11 +5441,9 @@ impl DocumentMethods for Document {
}
}
fn update_with_current_time_ms(marker: &Cell<u64>) {
if marker.get() == 0 {
let time = time::get_time();
let current_time_ms = time.sec * 1000 + time.nsec as i64 / 1000000;
marker.set(current_time_ms as u64);
fn update_with_current_instant(marker: &Cell<Option<CrossProcessInstant>>) {
if marker.get().is_none() {
marker.set(Some(CrossProcessInstant::now()))
}
}

View file

@ -5,10 +5,10 @@
use std::cell::Cell;
use std::default::Default;
use base::cross_process_instant::CrossProcessInstant;
use devtools_traits::{TimelineMarker, TimelineMarkerType};
use dom_struct::dom_struct;
use js::rust::HandleObject;
use metrics::ToMs;
use servo_atoms::Atom;
use crate::dom::bindings::callback::ExceptionHandling;
@ -16,7 +16,6 @@ use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::EventBinding;
use crate::dom::bindings::codegen::Bindings::EventBinding::{EventConstants, EventMethods};
use crate::dom::bindings::codegen::Bindings::PerformanceBinding::DOMHighResTimeStamp;
use crate::dom::bindings::codegen::Bindings::PerformanceBinding::Performance_Binding::PerformanceMethods;
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable;
@ -31,7 +30,6 @@ use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlinputelement::InputActivationState;
use crate::dom::mouseevent::MouseEvent;
use crate::dom::node::{Node, ShadowIncluding};
use crate::dom::performance::reduce_timing_resolution;
use crate::dom::virtualmethods::vtable_for;
use crate::dom::window::Window;
use crate::script_runtime::CanGc;
@ -53,7 +51,8 @@ pub struct Event {
trusted: Cell<bool>,
dispatching: Cell<bool>,
initialized: Cell<bool>,
precise_time_ns: u64,
#[no_trace]
time_stamp: CrossProcessInstant,
}
impl Event {
@ -72,7 +71,7 @@ impl Event {
trusted: Cell::new(false),
dispatching: Cell::new(false),
initialized: Cell::new(false),
precise_time_ns: time::precise_time_ns(),
time_stamp: CrossProcessInstant::now(),
}
}
@ -498,10 +497,9 @@ impl EventMethods for Event {
/// <https://dom.spec.whatwg.org/#dom-event-timestamp>
fn TimeStamp(&self) -> DOMHighResTimeStamp {
reduce_timing_resolution(
(self.precise_time_ns - (*self.global().performance().TimeOrigin()).round() as u64)
.to_ms(),
)
self.global()
.performance()
.to_dom_high_res_time_stamp(self.time_stamp)
}
/// <https://dom.spec.whatwg.org/#dom-event-initevent>

View file

@ -579,6 +579,9 @@ macro_rules! rooted_vec {
/// DOM struct implementation for simple interfaces inheriting from PerformanceEntry.
macro_rules! impl_performance_entry_struct(
($binding:ident, $struct:ident, $type:expr) => (
use base::cross_process_instant::CrossProcessInstant;
use time_03::Duration;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
@ -592,12 +595,12 @@ macro_rules! impl_performance_entry_struct(
}
impl $struct {
fn new_inherited(name: DOMString, start_time: f64, duration: f64)
fn new_inherited(name: DOMString, start_time: CrossProcessInstant, duration: Duration)
-> $struct {
$struct {
entry: PerformanceEntry::new_inherited(name,
DOMString::from($type),
start_time,
Some(start_time),
duration)
}
}
@ -605,8 +608,8 @@ macro_rules! impl_performance_entry_struct(
#[allow(crown::unrooted_must_root)]
pub fn new(global: &GlobalScope,
name: DOMString,
start_time: f64,
duration: f64) -> DomRoot<$struct> {
start_time: CrossProcessInstant,
duration: Duration) -> DomRoot<$struct> {
let entry = $struct::new_inherited(name, start_time, duration);
reflect_dom_object(Box::new(entry), global)
}

View file

@ -6,8 +6,9 @@ use std::cell::Cell;
use std::cmp::Ordering;
use std::collections::VecDeque;
use base::cross_process_instant::CrossProcessInstant;
use dom_struct::dom_struct;
use metrics::ToMs;
use time_03::Duration;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::PerformanceBinding::{
@ -105,16 +106,12 @@ impl PerformanceEntryList {
&self,
name: DOMString,
entry_type: DOMString,
) -> f64 {
match self
.entries
) -> Option<CrossProcessInstant> {
self.entries
.iter()
.rev()
.find(|e| *e.entry_type() == *entry_type && *e.name() == *name)
{
Some(entry) => entry.start_time(),
None => 0.,
}
.and_then(|entry| entry.start_time())
}
}
@ -139,7 +136,10 @@ pub struct Performance {
buffer: DomRefCell<PerformanceEntryList>,
observers: DomRefCell<Vec<PerformanceObserver>>,
pending_notification_observers_task: Cell<bool>,
navigation_start_precise: u64,
#[no_trace]
/// The `timeOrigin` as described in
/// <https://html.spec.whatwg.org/multipage/#concept-settings-object-time-origin>.
time_origin: CrossProcessInstant,
/// <https://w3c.github.io/performance-timeline/#dfn-maxbuffersize>
/// The max-size of the buffer, set to 0 once the pipeline exits.
/// TODO: have one max-size per entry type.
@ -150,13 +150,13 @@ pub struct Performance {
}
impl Performance {
fn new_inherited(navigation_start_precise: u64) -> Performance {
fn new_inherited(time_origin: CrossProcessInstant) -> Performance {
Performance {
eventtarget: EventTarget::new_inherited(),
buffer: DomRefCell::new(PerformanceEntryList::new(Vec::new())),
observers: DomRefCell::new(Vec::new()),
pending_notification_observers_task: Cell::new(false),
navigation_start_precise,
time_origin,
resource_timing_buffer_size_limit: Cell::new(250),
resource_timing_buffer_current_size: Cell::new(0),
resource_timing_buffer_pending_full_event: Cell::new(false),
@ -164,13 +164,30 @@ impl Performance {
}
}
pub fn new(global: &GlobalScope, navigation_start_precise: u64) -> DomRoot<Performance> {
pub fn new(
global: &GlobalScope,
navigation_start: CrossProcessInstant,
) -> DomRoot<Performance> {
reflect_dom_object(
Box::new(Performance::new_inherited(navigation_start_precise)),
Box::new(Performance::new_inherited(navigation_start)),
global,
)
}
pub(crate) fn to_dom_high_res_time_stamp(
&self,
instant: CrossProcessInstant,
) -> DOMHighResTimeStamp {
(instant - self.time_origin).to_dom_high_res_time_stamp()
}
pub(crate) fn maybe_to_dom_high_res_time_stamp(
&self,
instant: Option<CrossProcessInstant>,
) -> DOMHighResTimeStamp {
self.to_dom_high_res_time_stamp(instant.unwrap_or(self.time_origin))
}
/// Clear all buffered performance entries, and disable the buffer.
/// Called as part of the window's "clear_js_runtime" workflow,
/// performed when exiting a pipeline.
@ -329,10 +346,6 @@ impl Performance {
}
}
fn now(&self) -> f64 {
(time::precise_time_ns() - self.navigation_start_precise).to_ms()
}
fn can_add_resource_timing_entry(&self) -> bool {
self.resource_timing_buffer_current_size.get() <=
self.resource_timing_buffer_size_limit.get()
@ -423,12 +436,12 @@ impl PerformanceMethods for Performance {
// https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/HighResolutionTime/Overview.html#dom-performance-now
fn Now(&self) -> DOMHighResTimeStamp {
reduce_timing_resolution(self.now())
self.to_dom_high_res_time_stamp(CrossProcessInstant::now())
}
// https://www.w3.org/TR/hr-time-2/#dom-performance-timeorigin
fn TimeOrigin(&self) -> DOMHighResTimeStamp {
reduce_timing_resolution(self.navigation_start_precise as f64)
(self.time_origin - CrossProcessInstant::epoch()).to_dom_high_res_time_stamp()
}
// https://www.w3.org/TR/performance-timeline-2/#dom-performance-getentries
@ -465,7 +478,12 @@ impl PerformanceMethods for Performance {
}
// Steps 2 to 6.
let entry = PerformanceMark::new(&global, mark_name, self.now(), 0.);
let entry = PerformanceMark::new(
&global,
mark_name,
CrossProcessInstant::now(),
Duration::ZERO,
);
// Steps 7 and 8.
self.queue_entry(entry.upcast::<PerformanceEntry>());
@ -488,22 +506,23 @@ impl PerformanceMethods for Performance {
end_mark: Option<DOMString>,
) -> Fallible<()> {
// Steps 1 and 2.
let end_time = match end_mark {
Some(name) => self
.buffer
.borrow()
.get_last_entry_start_time_with_name_and_type(DOMString::from("mark"), name),
None => self.now(),
};
let end_time = end_mark
.map(|name| {
self.buffer
.borrow()
.get_last_entry_start_time_with_name_and_type(DOMString::from("mark"), name)
.unwrap_or(self.time_origin)
})
.unwrap_or_else(CrossProcessInstant::now);
// Step 3.
let start_time = match start_mark {
Some(name) => self
.buffer
.borrow()
.get_last_entry_start_time_with_name_and_type(DOMString::from("mark"), name),
None => 0.,
};
let start_time = start_mark
.and_then(|name| {
self.buffer
.borrow()
.get_last_entry_start_time_with_name_and_type(DOMString::from("mark"), name)
})
.unwrap_or(self.time_origin);
// Steps 4 to 8.
let entry = PerformanceMeasure::new(
@ -548,13 +567,18 @@ impl PerformanceMethods for Performance {
);
}
// https://www.w3.org/TR/hr-time-2/#clock-resolution
pub fn reduce_timing_resolution(exact: f64) -> DOMHighResTimeStamp {
// We need a granularity no finer than 5 microseconds.
// 5 microseconds isn't an exactly representable f64 so WPT tests
// might occasionally corner-case on rounding.
// web-platform-tests/wpt#21526 wants us to use an integer number of
// microseconds; the next divisor of milliseconds up from 5 microseconds
// is 10, which is 1/100th of a millisecond.
Finite::wrap((exact * 100.0).floor() / 100.0)
pub(crate) trait ToDOMHighResTimeStamp {
fn to_dom_high_res_time_stamp(&self) -> DOMHighResTimeStamp;
}
impl ToDOMHighResTimeStamp for Duration {
fn to_dom_high_res_time_stamp(&self) -> DOMHighResTimeStamp {
// https://www.w3.org/TR/hr-time-2/#clock-resolution
// We need a granularity no finer than 5 microseconds. 5 microseconds isn't an
// exactly representable f64 so WPT tests might occasionally corner-case on
// rounding. web-platform-tests/wpt#21526 wants us to use an integer number of
// microseconds; the next divisor of milliseconds up from 5 microseconds is 10.
let microseconds_rounded = (self.whole_microseconds() as f64 / 10.).floor() * 10.;
Finite::wrap(microseconds_rounded / 1000.)
}
}

View file

@ -2,31 +2,38 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use base::cross_process_instant::CrossProcessInstant;
use dom_struct::dom_struct;
use time_03::Duration;
use super::performance::ToDOMHighResTimeStamp;
use crate::dom::bindings::codegen::Bindings::PerformanceBinding::DOMHighResTimeStamp;
use crate::dom::bindings::codegen::Bindings::PerformanceEntryBinding::PerformanceEntryMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::performance::reduce_timing_resolution;
#[dom_struct]
pub struct PerformanceEntry {
reflector_: Reflector,
name: DOMString,
entry_type: DOMString,
start_time: f64,
duration: f64,
#[no_trace]
start_time: Option<CrossProcessInstant>,
/// The duration of this [`PerformanceEntry`]. This is a [`time_03::Duration`],
/// because it can be negative and `std::time::Duration` cannot be.
#[no_trace]
#[ignore_malloc_size_of = "No MallocSizeOf support for `time` crate"]
duration: Duration,
}
impl PerformanceEntry {
pub fn new_inherited(
name: DOMString,
entry_type: DOMString,
start_time: f64,
duration: f64,
start_time: Option<CrossProcessInstant>,
duration: Duration,
) -> PerformanceEntry {
PerformanceEntry {
reflector_: Reflector::new(),
@ -42,10 +49,10 @@ impl PerformanceEntry {
global: &GlobalScope,
name: DOMString,
entry_type: DOMString,
start_time: f64,
duration: f64,
start_time: CrossProcessInstant,
duration: Duration,
) -> DomRoot<PerformanceEntry> {
let entry = PerformanceEntry::new_inherited(name, entry_type, start_time, duration);
let entry = PerformanceEntry::new_inherited(name, entry_type, Some(start_time), duration);
reflect_dom_object(Box::new(entry), global)
}
@ -57,11 +64,11 @@ impl PerformanceEntry {
&self.name
}
pub fn start_time(&self) -> f64 {
pub fn start_time(&self) -> Option<CrossProcessInstant> {
self.start_time
}
pub fn duration(&self) -> f64 {
pub fn duration(&self) -> Duration {
self.duration
}
}
@ -79,11 +86,13 @@ impl PerformanceEntryMethods for PerformanceEntry {
// https://w3c.github.io/performance-timeline/#dom-performanceentry-starttime
fn StartTime(&self) -> DOMHighResTimeStamp {
reduce_timing_resolution(self.start_time)
self.global()
.performance()
.maybe_to_dom_high_res_time_stamp(self.start_time)
}
// https://w3c.github.io/performance-timeline/#dom-performanceentry-duration
fn Duration(&self) -> DOMHighResTimeStamp {
reduce_timing_resolution(self.duration)
self.duration.to_dom_high_res_time_stamp()
}
}

View file

@ -2,13 +2,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use base::cross_process_instant::CrossProcessInstant;
use dom_struct::dom_struct;
use crate::dom::bindings::codegen::Bindings::PerformanceBinding::DOMHighResTimeStamp;
use crate::dom::bindings::codegen::Bindings::PerformanceNavigationTimingBinding::{
NavigationTimingType, PerformanceNavigationTimingMethods,
};
use crate::dom::bindings::num::Finite;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::document::Document;
@ -22,16 +23,13 @@ use crate::dom::performanceresourcetiming::{InitiatorType, PerformanceResourceTi
pub struct PerformanceNavigationTiming {
// https://w3c.github.io/navigation-timing/#PerformanceResourceTiming
performanceresourcetiming: PerformanceResourceTiming,
navigation_start: u64,
navigation_start_precise: u64,
document: Dom<Document>,
nav_type: NavigationTimingType,
}
impl PerformanceNavigationTiming {
fn new_inherited(
nav_start: u64,
nav_start_precise: u64,
navigation_start: CrossProcessInstant,
document: &Document,
) -> PerformanceNavigationTiming {
PerformanceNavigationTiming {
@ -39,10 +37,8 @@ impl PerformanceNavigationTiming {
document.url(),
InitiatorType::Navigation,
None,
nav_start_precise as f64,
Some(navigation_start),
),
navigation_start: nav_start,
navigation_start_precise: nav_start_precise,
document: Dom::from_ref(document),
nav_type: NavigationTimingType::Navigate,
}
@ -50,14 +46,12 @@ impl PerformanceNavigationTiming {
pub fn new(
global: &GlobalScope,
nav_start: u64,
nav_start_precise: u64,
fetch_start: CrossProcessInstant,
document: &Document,
) -> DomRoot<PerformanceNavigationTiming> {
reflect_dom_object(
Box::new(PerformanceNavigationTiming::new_inherited(
nav_start,
nav_start_precise,
fetch_start,
document,
)),
global,
@ -69,42 +63,50 @@ impl PerformanceNavigationTiming {
impl PerformanceNavigationTimingMethods for PerformanceNavigationTiming {
// https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming-unloadeventstart
fn UnloadEventStart(&self) -> DOMHighResTimeStamp {
Finite::wrap(self.document.get_unload_event_start() as f64)
self.upcast::<PerformanceResourceTiming>()
.to_dom_high_res_time_stamp(self.document.get_unload_event_start())
}
// https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming-unloadeventend
fn UnloadEventEnd(&self) -> DOMHighResTimeStamp {
Finite::wrap(self.document.get_unload_event_end() as f64)
self.upcast::<PerformanceResourceTiming>()
.to_dom_high_res_time_stamp(self.document.get_unload_event_end())
}
// https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming-dominteractive
fn DomInteractive(&self) -> DOMHighResTimeStamp {
Finite::wrap(self.document.get_dom_interactive() as f64)
self.upcast::<PerformanceResourceTiming>()
.to_dom_high_res_time_stamp(self.document.get_dom_interactive())
}
// https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming-domcontentloadedeventstart
fn DomContentLoadedEventStart(&self) -> DOMHighResTimeStamp {
Finite::wrap(self.document.get_dom_content_loaded_event_start() as f64)
self.upcast::<PerformanceResourceTiming>()
.to_dom_high_res_time_stamp(self.document.get_dom_content_loaded_event_start())
}
// https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming-domcontentloadedeventstart
fn DomContentLoadedEventEnd(&self) -> DOMHighResTimeStamp {
Finite::wrap(self.document.get_dom_content_loaded_event_end() as f64)
self.upcast::<PerformanceResourceTiming>()
.to_dom_high_res_time_stamp(self.document.get_dom_content_loaded_event_end())
}
// https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming-domcomplete
fn DomComplete(&self) -> DOMHighResTimeStamp {
Finite::wrap(self.document.get_dom_complete() as f64)
self.upcast::<PerformanceResourceTiming>()
.to_dom_high_res_time_stamp(self.document.get_dom_complete())
}
// https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming-loadeventstart
fn LoadEventStart(&self) -> DOMHighResTimeStamp {
Finite::wrap(self.document.get_load_event_start() as f64)
self.upcast::<PerformanceResourceTiming>()
.to_dom_high_res_time_stamp(self.document.get_load_event_start())
}
// https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming-loadeventend
fn LoadEventEnd(&self) -> DOMHighResTimeStamp {
Finite::wrap(self.document.get_load_event_end() as f64)
self.upcast::<PerformanceResourceTiming>()
.to_dom_high_res_time_stamp(self.document.get_load_event_end())
}
// https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming-type
@ -120,6 +122,7 @@ impl PerformanceNavigationTimingMethods for PerformanceNavigationTiming {
// check-tidy: no specs after this line
// Servo-only timing for when top-level content (not iframes) is complete
fn TopLevelDomComplete(&self) -> DOMHighResTimeStamp {
Finite::wrap(self.document.get_top_level_dom_complete() as f64)
self.upcast::<PerformanceResourceTiming>()
.to_dom_high_res_time_stamp(self.document.get_top_level_dom_complete())
}
}

View file

@ -2,9 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use base::cross_process_instant::CrossProcessInstant;
use dom_struct::dom_struct;
use metrics::ToMs;
use script_traits::ProgressiveWebMetricType;
use time_03::Duration;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::DomRoot;
@ -20,7 +21,7 @@ pub struct PerformancePaintTiming {
impl PerformancePaintTiming {
fn new_inherited(
metric_type: ProgressiveWebMetricType,
start_time: u64,
start_time: CrossProcessInstant,
) -> PerformancePaintTiming {
let name = match metric_type {
ProgressiveWebMetricType::FirstPaint => DOMString::from("first-paint"),
@ -33,8 +34,8 @@ impl PerformancePaintTiming {
entry: PerformanceEntry::new_inherited(
name,
DOMString::from("paint"),
start_time.to_ms(),
0.,
Some(start_time),
Duration::ZERO,
),
}
}
@ -43,7 +44,7 @@ impl PerformancePaintTiming {
pub fn new(
global: &GlobalScope,
metric_type: ProgressiveWebMetricType,
start_time: u64,
start_time: CrossProcessInstant,
) -> DomRoot<PerformancePaintTiming> {
let entry = PerformancePaintTiming::new_inherited(metric_type, start_time);
reflect_dom_object(Box::new(entry), global)

View file

@ -2,17 +2,18 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use base::cross_process_instant::CrossProcessInstant;
use dom_struct::dom_struct;
use net_traits::ResourceFetchTiming;
use servo_url::ServoUrl;
use time_03::Duration;
use crate::dom::bindings::codegen::Bindings::PerformanceBinding::DOMHighResTimeStamp;
use crate::dom::bindings::codegen::Bindings::PerformanceResourceTimingBinding::PerformanceResourceTimingMethods;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::performance::reduce_timing_resolution;
use crate::dom::performanceentry::PerformanceEntry;
// TODO UA may choose to limit how many resources are included as PerformanceResourceTiming objects
@ -37,18 +38,30 @@ pub struct PerformanceResourceTiming {
entry: PerformanceEntry,
initiator_type: InitiatorType,
next_hop: Option<DOMString>,
worker_start: f64,
redirect_start: f64,
redirect_end: f64,
fetch_start: f64,
domain_lookup_start: f64,
domain_lookup_end: f64,
connect_start: f64,
connect_end: f64,
secure_connection_start: f64,
request_start: f64,
response_start: f64,
response_end: f64,
#[no_trace]
worker_start: Option<CrossProcessInstant>,
#[no_trace]
redirect_start: Option<CrossProcessInstant>,
#[no_trace]
redirect_end: Option<CrossProcessInstant>,
#[no_trace]
fetch_start: Option<CrossProcessInstant>,
#[no_trace]
domain_lookup_start: Option<CrossProcessInstant>,
#[no_trace]
domain_lookup_end: Option<CrossProcessInstant>,
#[no_trace]
connect_start: Option<CrossProcessInstant>,
#[no_trace]
connect_end: Option<CrossProcessInstant>,
#[no_trace]
secure_connection_start: Option<CrossProcessInstant>,
#[no_trace]
request_start: Option<CrossProcessInstant>,
#[no_trace]
response_start: Option<CrossProcessInstant>,
#[no_trace]
response_end: Option<CrossProcessInstant>,
transfer_size: u64, //size in octets
encoded_body_size: u64, //size in octets
decoded_body_size: u64, //size in octets
@ -66,7 +79,7 @@ impl PerformanceResourceTiming {
url: ServoUrl,
initiator_type: InitiatorType,
next_hop: Option<DOMString>,
fetch_start: f64,
fetch_start: Option<CrossProcessInstant>,
) -> PerformanceResourceTiming {
let entry_type = if initiator_type == InitiatorType::Navigation {
DOMString::from("navigation")
@ -77,23 +90,23 @@ impl PerformanceResourceTiming {
entry: PerformanceEntry::new_inherited(
DOMString::from(url.into_string()),
entry_type,
0.,
0.,
None,
Duration::ZERO,
),
initiator_type,
next_hop,
worker_start: 0.,
redirect_start: 0.,
redirect_end: 0.,
worker_start: None,
redirect_start: None,
redirect_end: None,
fetch_start,
domain_lookup_end: 0.,
domain_lookup_start: 0.,
connect_start: 0.,
connect_end: 0.,
secure_connection_start: 0.,
request_start: 0.,
response_start: 0.,
response_end: 0.,
domain_lookup_end: None,
domain_lookup_start: None,
connect_start: None,
connect_end: None,
secure_connection_start: None,
request_start: None,
response_start: None,
response_end: None,
transfer_size: 0,
encoded_body_size: 0,
decoded_body_size: 0,
@ -108,28 +121,32 @@ impl PerformanceResourceTiming {
next_hop: Option<DOMString>,
resource_timing: &ResourceFetchTiming,
) -> PerformanceResourceTiming {
let duration = match (resource_timing.start_time, resource_timing.response_end) {
(Some(start_time), Some(end_time)) => end_time - start_time,
_ => Duration::ZERO,
};
PerformanceResourceTiming {
entry: PerformanceEntry::new_inherited(
DOMString::from(url.into_string()),
DOMString::from("resource"),
resource_timing.start_time as f64,
resource_timing.response_end as f64 - resource_timing.start_time as f64,
resource_timing.start_time,
duration,
),
initiator_type,
next_hop,
worker_start: 0.,
redirect_start: resource_timing.redirect_start as f64,
redirect_end: resource_timing.redirect_end as f64,
fetch_start: resource_timing.fetch_start as f64,
domain_lookup_start: resource_timing.domain_lookup_start as f64,
worker_start: None,
redirect_start: resource_timing.redirect_start,
redirect_end: resource_timing.redirect_end,
fetch_start: resource_timing.fetch_start,
domain_lookup_start: resource_timing.domain_lookup_start,
//TODO (#21260)
domain_lookup_end: 0.,
connect_start: resource_timing.connect_start as f64,
connect_end: resource_timing.connect_end as f64,
secure_connection_start: resource_timing.secure_connection_start as f64,
request_start: resource_timing.request_start as f64,
response_start: resource_timing.response_start as f64,
response_end: resource_timing.response_end as f64,
domain_lookup_end: None,
connect_start: resource_timing.connect_start,
connect_end: resource_timing.connect_end,
secure_connection_start: resource_timing.secure_connection_start,
request_start: resource_timing.request_start,
response_start: resource_timing.response_start,
response_end: resource_timing.response_end,
transfer_size: 0,
encoded_body_size: 0,
decoded_body_size: 0,
@ -153,6 +170,18 @@ impl PerformanceResourceTiming {
global,
)
}
/// Convert an optional [`CrossProcessInstant`] to a [`DOMHighResTimeStamp`]. If none
/// return a timestamp for [`Self::fetch_start`] instead, so that timestamps are
/// always after that time.
pub(crate) fn to_dom_high_res_time_stamp(
&self,
instant: Option<CrossProcessInstant>,
) -> DOMHighResTimeStamp {
self.global()
.performance()
.maybe_to_dom_high_res_time_stamp(instant)
}
}
// https://w3c.github.io/resource-timing/
@ -180,17 +209,17 @@ impl PerformanceResourceTimingMethods for PerformanceResourceTiming {
// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-domainlookupstart
fn DomainLookupStart(&self) -> DOMHighResTimeStamp {
reduce_timing_resolution(self.domain_lookup_start)
self.to_dom_high_res_time_stamp(self.domain_lookup_start)
}
// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-domainlookupend
fn DomainLookupEnd(&self) -> DOMHighResTimeStamp {
reduce_timing_resolution(self.domain_lookup_end)
self.to_dom_high_res_time_stamp(self.domain_lookup_end)
}
// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-secureconnectionstart
fn SecureConnectionStart(&self) -> DOMHighResTimeStamp {
reduce_timing_resolution(self.secure_connection_start)
self.to_dom_high_res_time_stamp(self.secure_connection_start)
}
// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-transfersize
@ -210,41 +239,41 @@ impl PerformanceResourceTimingMethods for PerformanceResourceTiming {
// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-requeststart
fn RequestStart(&self) -> DOMHighResTimeStamp {
reduce_timing_resolution(self.request_start)
self.to_dom_high_res_time_stamp(self.request_start)
}
// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-redirectstart
fn RedirectStart(&self) -> DOMHighResTimeStamp {
reduce_timing_resolution(self.redirect_start)
self.to_dom_high_res_time_stamp(self.redirect_start)
}
// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-redirectend
fn RedirectEnd(&self) -> DOMHighResTimeStamp {
reduce_timing_resolution(self.redirect_end)
self.to_dom_high_res_time_stamp(self.redirect_end)
}
// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-responsestart
fn ResponseStart(&self) -> DOMHighResTimeStamp {
reduce_timing_resolution(self.response_start)
self.to_dom_high_res_time_stamp(self.response_start)
}
// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-fetchstart
fn FetchStart(&self) -> DOMHighResTimeStamp {
reduce_timing_resolution(self.fetch_start)
self.to_dom_high_res_time_stamp(self.fetch_start)
}
// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-connectstart
fn ConnectStart(&self) -> DOMHighResTimeStamp {
reduce_timing_resolution(self.connect_start)
self.to_dom_high_res_time_stamp(self.connect_start)
}
// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-connectend
fn ConnectEnd(&self) -> DOMHighResTimeStamp {
reduce_timing_resolution(self.connect_end)
self.to_dom_high_res_time_stamp(self.connect_end)
}
// https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-responseend
fn ResponseEnd(&self) -> DOMHighResTimeStamp {
reduce_timing_resolution(self.response_end)
self.to_dom_high_res_time_stamp(self.response_end)
}
}

View file

@ -1,103 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::codegen::Bindings::PerformanceTimingBinding;
use crate::dom::bindings::codegen::Bindings::PerformanceTimingBinding::PerformanceTimingMethods;
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::document::Document;
use crate::dom::window::Window;
use dom_struct::dom_struct;
#[dom_struct]
pub struct PerformanceTiming {
reflector_: Reflector,
navigation_start: u64,
navigation_start_precise: u64,
document: Dom<Document>,
}
impl PerformanceTiming {
fn new_inherited(
nav_start: u64,
nav_start_precise: u64,
document: &Document,
) -> PerformanceTiming {
PerformanceTiming {
reflector_: Reflector::new(),
navigation_start: nav_start,
navigation_start_precise: nav_start_precise,
document: Dom::from_ref(document),
}
}
#[allow(crown::unrooted_must_root)]
pub fn new(
window: &Window,
navigation_start: u64,
navigation_start_precise: u64,
) -> DomRoot<PerformanceTiming> {
let timing = PerformanceTiming::new_inherited(
navigation_start,
navigation_start_precise,
&window.Document(),
);
reflect_dom_object(Box::new(timing), window)
}
}
impl PerformanceTimingMethods for PerformanceTiming {
// https://w3c.github.io/navigation-timing/#widl-PerformanceTiming-navigationStart
fn NavigationStart(&self) -> u64 {
self.navigation_start
}
// https://w3c.github.io/navigation-timing/#widl-PerformanceTiming-domLoading
fn DomLoading(&self) -> u64 {
self.document.get_dom_loading()
}
// https://w3c.github.io/navigation-timing/#widl-PerformanceTiming-domInteractive
fn DomInteractive(&self) -> u64 {
self.document.get_dom_interactive()
}
// https://w3c.github.io/navigation-timing/#widl-PerformanceTiming-domContentLoadedEventStart
fn DomContentLoadedEventStart(&self) -> u64 {
self.document.get_dom_content_loaded_event_start()
}
// https://w3c.github.io/navigation-timing/#widl-PerformanceTiming-domContentLoadedEventEnd
fn DomContentLoadedEventEnd(&self) -> u64 {
self.document.get_dom_content_loaded_event_end()
}
// https://w3c.github.io/navigation-timing/#widl-PerformanceTiming-domComplete
fn DomComplete(&self) -> u64 {
self.document.get_dom_complete()
}
// https://w3c.github.io/navigation-timing/#widl-PerformanceTiming-loadEventStart
fn LoadEventStart(&self) -> u64 {
self.document.get_load_event_start()
}
// https://w3c.github.io/navigation-timing/#widl-PerformanceTiming-loadEventEnd
fn LoadEventEnd(&self) -> u64 {
self.document.get_load_event_end()
}
// check-tidy: no specs after this line
// Servo-only timing for when top-level content (not iframes) is complete
fn TopLevelDomComplete(&self) -> u64 {
self.document.get_top_level_dom_complete()
}
}
impl PerformanceTiming {
pub fn navigation_start_precise(&self) -> u64 {
self.navigation_start_precise
}
}

View file

@ -5,6 +5,7 @@
use std::borrow::Cow;
use std::cell::Cell;
use base::cross_process_instant::CrossProcessInstant;
use base::id::PipelineId;
use base64::engine::general_purpose;
use base64::Engine as _;
@ -937,11 +938,15 @@ impl FetchResponseListener for ParserContext {
parser.parse_sync();
}
//TODO only update if this is the current document resource
// TODO: Only update if this is the current document resource.
// TODO(mrobinson): Pass a proper fetch_start parameter here instead of `CrossProcessInstant::now()`.
if let Some(pushed_index) = self.pushed_entry_index {
let document = &parser.document;
let performance_entry =
PerformanceNavigationTiming::new(&document.global(), 0, 0, document);
let performance_entry = PerformanceNavigationTiming::new(
&document.global(),
CrossProcessInstant::now(),
document,
);
document
.global()
.performance()
@ -969,9 +974,12 @@ impl FetchResponseListener for ParserContext {
let document = &parser.document;
//TODO nav_start and nav_start_precise
let performance_entry =
PerformanceNavigationTiming::new(&document.global(), 0, 0, document);
// TODO: Pass a proper fetch start time here.
let performance_entry = PerformanceNavigationTiming::new(
&document.global(),
CrossProcessInstant::now(),
document,
);
self.pushed_entry_index = document
.global()
.performance()

View file

@ -4,7 +4,9 @@
use std::ops::Deref;
use base::cross_process_instant::CrossProcessInstant;
use dom_struct::dom_struct;
use time_03::Duration;
use crate::dom::bindings::codegen::Bindings::DocumentBinding::DocumentVisibilityState;
use crate::dom::bindings::codegen::Bindings::PerformanceEntryBinding::PerformanceEntryMethods;
@ -23,7 +25,10 @@ pub struct VisibilityStateEntry {
impl VisibilityStateEntry {
#[allow(crown::unrooted_must_root)]
fn new_inherited(state: DocumentVisibilityState, timestamp: f64) -> VisibilityStateEntry {
fn new_inherited(
state: DocumentVisibilityState,
timestamp: CrossProcessInstant,
) -> VisibilityStateEntry {
let name = match state {
DocumentVisibilityState::Visible => DOMString::from("visible"),
DocumentVisibilityState::Hidden => DOMString::from("hidden"),
@ -32,8 +37,8 @@ impl VisibilityStateEntry {
entry: PerformanceEntry::new_inherited(
name,
DOMString::from("visibility-state"),
timestamp,
0.,
Some(timestamp),
Duration::ZERO,
),
}
}
@ -41,7 +46,7 @@ impl VisibilityStateEntry {
pub fn new(
global: &GlobalScope,
state: DocumentVisibilityState,
timestamp: f64,
timestamp: CrossProcessInstant,
) -> DomRoot<VisibilityStateEntry> {
reflect_dom_object(
Box::new(VisibilityStateEntry::new_inherited(state, timestamp)),

View file

@ -17,6 +17,7 @@ use std::{cmp, env};
use app_units::Au;
use backtrace::Backtrace;
use base::cross_process_instant::CrossProcessInstant;
use base::id::{BrowsingContextId, PipelineId};
use base64::Engine;
use bluetooth_traits::BluetoothRequest;
@ -201,8 +202,8 @@ pub struct Window {
history: MutNullableDom<History>,
custom_element_registry: MutNullableDom<CustomElementRegistry>,
performance: MutNullableDom<Performance>,
navigation_start: Cell<u64>,
navigation_start_precise: Cell<u64>,
#[no_trace]
navigation_start: Cell<CrossProcessInstant>,
screen: MutNullableDom<Screen>,
session_storage: MutNullableDom<Storage>,
local_storage: MutNullableDom<Storage>,
@ -985,7 +986,7 @@ impl WindowMethods for Window {
fn Performance(&self) -> DomRoot<Performance> {
self.performance.or_init(|| {
let global_scope = self.upcast::<GlobalScope>();
Performance::new(global_scope, self.navigation_start_precise.get())
Performance::new(global_scope, self.navigation_start.get())
})
}
@ -1625,10 +1626,6 @@ impl Window {
self.paint_worklet.or_init(|| self.new_paint_worklet())
}
pub fn get_navigation_start(&self) -> u64 {
self.navigation_start_precise.get()
}
pub fn has_document(&self) -> bool {
self.document.get().is_some()
}
@ -2494,10 +2491,7 @@ impl Window {
}
pub fn set_navigation_start(&self) {
let current_time = time::get_time();
let now = (current_time.sec * 1000 + current_time.nsec as i64 / 1000000) as u64;
self.navigation_start.set(now);
self.navigation_start_precise.set(time::precise_time_ns());
self.navigation_start.set(CrossProcessInstant::now());
}
pub fn send_to_embedder(&self, msg: EmbedderMsg) {
@ -2547,8 +2541,7 @@ impl Window {
window_size: WindowSizeData,
origin: MutableOrigin,
creator_url: ServoUrl,
navigation_start: u64,
navigation_start_precise: u64,
navigation_start: CrossProcessInstant,
webgl_chan: Option<WebGLChan>,
webxr_registry: webxr_api::Registry,
microtask_queue: Rc<MicrotaskQueue>,
@ -2606,7 +2599,6 @@ impl Window {
document: Default::default(),
performance: Default::default(),
navigation_start: Cell::new(navigation_start),
navigation_start_precise: Cell::new(navigation_start_precise),
screen: Default::default(),
session_storage: Default::default(),
local_storage: Default::default(),

View file

@ -8,6 +8,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::Duration;
use base::cross_process_instant::CrossProcessInstant;
use base::id::{PipelineId, PipelineNamespace};
use crossbeam_channel::Receiver;
use devtools_traits::{DevtoolScriptControlMsg, WorkerId};
@ -22,7 +23,6 @@ use net_traits::request::{
use net_traits::IpcSend;
use script_traits::WorkerGlobalScopeInit;
use servo_url::{MutableOrigin, ServoUrl};
use time::precise_time_ns;
use uuid::Uuid;
use super::bindings::codegen::Bindings::MessagePortBinding::StructuredSerializeOptions;
@ -125,7 +125,8 @@ pub struct WorkerGlobalScope {
/// `IpcSender` doesn't exist
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
navigation_start_precise: u64,
#[no_trace]
navigation_start: CrossProcessInstant,
performance: MutNullableDom<Performance>,
}
@ -170,7 +171,7 @@ impl WorkerGlobalScope {
navigator: Default::default(),
from_devtools_sender: init.from_devtools_sender,
from_devtools_receiver,
navigation_start_precise: precise_time_ns(),
navigation_start: CrossProcessInstant::now(),
performance: Default::default(),
}
}
@ -415,7 +416,7 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
fn Performance(&self) -> DomRoot<Performance> {
self.performance.or_init(|| {
let global_scope = self.upcast::<GlobalScope>();
Performance::new(global_scope, self.navigation_start_precise)
Performance::new(global_scope, self.navigation_start)
})
}

View file

@ -8,6 +8,7 @@ use std::f64::consts::{FRAC_PI_2, PI};
use std::rc::Rc;
use std::{mem, ptr};
use base::cross_process_instant::CrossProcessInstant;
use dom_struct::dom_struct;
use euclid::{RigidTransform3D, Transform3D, Vector3D};
use ipc_channel::ipc::IpcReceiver;
@ -15,7 +16,6 @@ use ipc_channel::router::ROUTER;
use js::jsapi::JSObject;
use js::jsval::JSVal;
use js::typedarray::Float32Array;
use metrics::ToMs;
use profile_traits::ipc;
use servo_atoms::Atom;
use webxr_api::{
@ -52,7 +52,6 @@ use crate::dom::bindings::utils::to_frozen_array;
use crate::dom::event::Event;
use crate::dom::eventtarget::EventTarget;
use crate::dom::globalscope::GlobalScope;
use crate::dom::performance::reduce_timing_resolution;
use crate::dom::promise::Promise;
use crate::dom::xrboundedreferencespace::XRBoundedReferenceSpace;
use crate::dom::xrframe::XRFrame;
@ -203,7 +202,7 @@ impl XRSession {
frame_receiver.to_opaque(),
Box::new(move |message| {
let frame: Frame = message.to().unwrap();
let time = time::precise_time_ns();
let time = CrossProcessInstant::now();
let this = this.clone();
let _ = task_source.queue_with_canceller(
task!(xr_raf_callback: move || {
@ -377,7 +376,7 @@ impl XRSession {
}
/// <https://immersive-web.github.io/webxr/#xr-animation-frame>
fn raf_callback(&self, mut frame: Frame, time: u64) {
fn raf_callback(&self, mut frame: Frame, time: CrossProcessInstant) {
debug!("WebXR RAF callback {:?}", frame);
// Step 1-2 happen in the xebxr device thread
@ -427,10 +426,10 @@ impl XRSession {
assert!(current.is_empty());
mem::swap(&mut *self.raf_callback_list.borrow_mut(), &mut current);
}
let start = self.global().as_window().get_navigation_start();
let time = reduce_timing_resolution((time - start).to_ms());
let time = self.global().performance().to_dom_high_res_time_stamp(time);
let frame = XRFrame::new(&self.global(), self, frame);
// Step 8-9
frame.set_active(true);
frame.set_animation_frame(true);