Skip to content

Commit bd9bd29

Browse files
committed
servo: Merge #17735 - Set navigation start value according to navigation timing spec (from ferjm:navigationstart); r=jdm
- [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #17651 Source-Repo: https://github.com/servo/servo Source-Revision: eb26194dd12f1430e9089512d54973d3b12b2e36
1 parent 2662071 commit bd9bd29

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

servo/components/script/dom/document.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3659,6 +3659,8 @@ impl DocumentMethods for Document {
36593659
// Step 10.
36603660
// TODO: prompt to unload.
36613661

3662+
window_from_node(self).set_navigation_start();
3663+
36623664
// Step 11.
36633665
// TODO: unload.
36643666

servo/components/script/dom/window.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ pub struct Window {
184184
history: MutNullableJS<History>,
185185
custom_element_registry: MutNullableJS<CustomElementRegistry>,
186186
performance: MutNullableJS<Performance>,
187-
navigation_start: u64,
188-
navigation_start_precise: f64,
187+
navigation_start: Cell<u64>,
188+
navigation_start_precise: Cell<f64>,
189189
screen: MutNullableJS<Screen>,
190190
session_storage: MutNullableJS<Storage>,
191191
local_storage: MutNullableJS<Storage>,
@@ -702,8 +702,8 @@ impl WindowMethods for Window {
702702
// NavigationTiming/Overview.html#sec-window.performance-attribute
703703
fn Performance(&self) -> Root<Performance> {
704704
self.performance.or_init(|| {
705-
Performance::new(self, self.navigation_start,
706-
self.navigation_start_precise)
705+
Performance::new(self, self.navigation_start.get(),
706+
self.navigation_start_precise.get())
707707
})
708708
}
709709

@@ -1772,6 +1772,13 @@ impl Window {
17721772
pub fn unminified_js_dir(&self) -> Option<String> {
17731773
self.unminified_js_dir.borrow().clone()
17741774
}
1775+
1776+
pub fn set_navigation_start(&self) {
1777+
let current_time = time::get_time();
1778+
let now = (current_time.sec * 1000 + current_time.nsec as i64 / 1000000) as u64;
1779+
self.navigation_start.set(now);
1780+
self.navigation_start_precise.set(time::precise_time_ns() as f64);
1781+
}
17751782
}
17761783

17771784
impl Window {
@@ -1799,6 +1806,8 @@ impl Window {
17991806
parent_info: Option<(PipelineId, FrameType)>,
18001807
window_size: Option<WindowSizeData>,
18011808
origin: MutableOrigin,
1809+
navigation_start: u64,
1810+
navigation_start_precise: f64,
18021811
webvr_thread: Option<IpcSender<WebVRMsg>>)
18031812
-> Root<Window> {
18041813
let layout_rpc: Box<LayoutRPC + Send> = {
@@ -1810,7 +1819,6 @@ impl Window {
18101819
pipelineid: id,
18111820
script_chan: Arc::new(Mutex::new(control_chan)),
18121821
};
1813-
let current_time = time::get_time();
18141822
let win = box Window {
18151823
globalscope:
18161824
GlobalScope::new_inherited(
@@ -1837,8 +1845,8 @@ impl Window {
18371845
window_proxy: Default::default(),
18381846
document: Default::default(),
18391847
performance: Default::default(),
1840-
navigation_start: (current_time.sec * 1000 + current_time.nsec as i64 / 1000000) as u64,
1841-
navigation_start_precise: time::precise_time_ns() as f64,
1848+
navigation_start: Cell::new(navigation_start),
1849+
navigation_start_precise: Cell::new(navigation_start_precise),
18421850
screen: Default::default(),
18431851
session_storage: Default::default(),
18441852
local_storage: Default::default(),

servo/components/script/script_thread.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ use task_source::file_reading::FileReadingTaskSource;
114114
use task_source::history_traversal::HistoryTraversalTaskSource;
115115
use task_source::networking::NetworkingTaskSource;
116116
use task_source::user_interaction::{UserInteractionTask, UserInteractionTaskSource};
117-
use time::Tm;
117+
use time::{get_time, precise_time_ns, Tm};
118118
use url::Position;
119119
use webdriver_handlers;
120120
use webvr_traits::{WebVREvent, WebVRMsg};
@@ -159,6 +159,10 @@ struct InProgressLoad {
159159
url: ServoUrl,
160160
/// The origin for the document
161161
origin: MutableOrigin,
162+
/// Timestamp reporting the time when the browser started this load.
163+
navigation_start: u64,
164+
/// High res timestamp reporting the time when the browser started this load.
165+
navigation_start_precise: f64,
162166
}
163167

164168
impl InProgressLoad {
@@ -171,6 +175,7 @@ impl InProgressLoad {
171175
window_size: Option<WindowSizeData>,
172176
url: ServoUrl,
173177
origin: MutableOrigin) -> InProgressLoad {
178+
let current_time = get_time();
174179
InProgressLoad {
175180
pipeline_id: id,
176181
browsing_context_id: browsing_context_id,
@@ -182,6 +187,8 @@ impl InProgressLoad {
182187
is_visible: true,
183188
url: url,
184189
origin: origin,
190+
navigation_start: (current_time.sec * 1000 + current_time.nsec as i64 / 1000000) as u64,
191+
navigation_start_precise: precise_time_ns() as f64,
185192
}
186193
}
187194
}
@@ -1833,8 +1840,7 @@ impl ScriptThread {
18331840
fn handle_iframe_load_event(&self,
18341841
parent_id: PipelineId,
18351842
browsing_context_id: BrowsingContextId,
1836-
child_id: PipelineId)
1837-
{
1843+
child_id: PipelineId) {
18381844
let iframe = self.documents.borrow().find_iframe(parent_id, browsing_context_id);
18391845
match iframe {
18401846
Some(iframe) => iframe.iframe_load_event_steps(child_id),
@@ -1982,6 +1988,8 @@ impl ScriptThread {
19821988
incomplete.parent_info,
19831989
incomplete.window_size,
19841990
origin,
1991+
incomplete.navigation_start,
1992+
incomplete.navigation_start_precise,
19851993
self.webvr_thread.clone());
19861994

19871995
// Initialize the browsing context for the window.

0 commit comments

Comments
 (0)