Skip to content

Commit

Permalink
Set navigation start value according to navigation timing spec
Browse files Browse the repository at this point in the history
  • Loading branch information
ferjm committed Jul 18, 2017
1 parent 66b9544 commit db044bd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
2 changes: 2 additions & 0 deletions components/script/dom/document.rs
Expand Up @@ -3659,6 +3659,8 @@ impl DocumentMethods for Document {
// Step 10.
// TODO: prompt to unload.

window_from_node(self).set_navigation_start();

// Step 11.
// TODO: unload.

Expand Down
22 changes: 15 additions & 7 deletions components/script/dom/window.rs
Expand Up @@ -184,8 +184,8 @@ pub struct Window {
history: MutNullableJS<History>,
custom_element_registry: MutNullableJS<CustomElementRegistry>,
performance: MutNullableJS<Performance>,
navigation_start: u64,
navigation_start_precise: f64,
navigation_start: Cell<u64>,
navigation_start_precise: Cell<f64>,
screen: MutNullableJS<Screen>,
session_storage: MutNullableJS<Storage>,
local_storage: MutNullableJS<Storage>,
Expand Down Expand Up @@ -702,8 +702,8 @@ impl WindowMethods for Window {
// NavigationTiming/Overview.html#sec-window.performance-attribute
fn Performance(&self) -> Root<Performance> {
self.performance.or_init(|| {
Performance::new(self, self.navigation_start,
self.navigation_start_precise)
Performance::new(self, self.navigation_start.get(),
self.navigation_start_precise.get())
})
}

Expand Down Expand Up @@ -1772,6 +1772,13 @@ impl Window {
pub fn unminified_js_dir(&self) -> Option<String> {
self.unminified_js_dir.borrow().clone()
}

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() as f64);
}
}

impl Window {
Expand Down Expand Up @@ -1799,6 +1806,8 @@ impl Window {
parent_info: Option<(PipelineId, FrameType)>,
window_size: Option<WindowSizeData>,
origin: MutableOrigin,
navigation_start: u64,
navigation_start_precise: f64,
webvr_thread: Option<IpcSender<WebVRMsg>>)
-> Root<Window> {
let layout_rpc: Box<LayoutRPC + Send> = {
Expand All @@ -1810,7 +1819,6 @@ impl Window {
pipelineid: id,
script_chan: Arc::new(Mutex::new(control_chan)),
};
let current_time = time::get_time();
let win = box Window {
globalscope:
GlobalScope::new_inherited(
Expand All @@ -1837,8 +1845,8 @@ impl Window {
window_proxy: Default::default(),
document: Default::default(),
performance: Default::default(),
navigation_start: (current_time.sec * 1000 + current_time.nsec as i64 / 1000000) as u64,
navigation_start_precise: time::precise_time_ns() as f64,
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(),
Expand Down
14 changes: 11 additions & 3 deletions components/script/script_thread.rs
Expand Up @@ -113,7 +113,7 @@ use task_source::file_reading::FileReadingTaskSource;
use task_source::history_traversal::HistoryTraversalTaskSource;
use task_source::networking::NetworkingTaskSource;
use task_source::user_interaction::{UserInteractionTask, UserInteractionTaskSource};
use time::Tm;
use time::{get_time, precise_time_ns, Tm};
use url::Position;
use webdriver_handlers;
use webvr_traits::{WebVREvent, WebVRMsg};
Expand Down Expand Up @@ -158,6 +158,10 @@ struct InProgressLoad {
url: ServoUrl,
/// The origin for the document
origin: MutableOrigin,
/// Timestamp reporting the time when the browser started this load.
navigation_start: u64,
/// High res timestamp reporting the time when the browser started this load.
navigation_start_precise: f64,
}

impl InProgressLoad {
Expand All @@ -170,6 +174,7 @@ impl InProgressLoad {
window_size: Option<WindowSizeData>,
url: ServoUrl,
origin: MutableOrigin) -> InProgressLoad {
let current_time = get_time();
InProgressLoad {
pipeline_id: id,
browsing_context_id: browsing_context_id,
Expand All @@ -181,6 +186,8 @@ impl InProgressLoad {
is_visible: true,
url: url,
origin: origin,
navigation_start: (current_time.sec * 1000 + current_time.nsec as i64 / 1000000) as u64,
navigation_start_precise: precise_time_ns() as f64,
}
}
}
Expand Down Expand Up @@ -1809,8 +1816,7 @@ impl ScriptThread {
fn handle_iframe_load_event(&self,
parent_id: PipelineId,
browsing_context_id: BrowsingContextId,
child_id: PipelineId)
{
child_id: PipelineId) {
let iframe = self.documents.borrow().find_iframe(parent_id, browsing_context_id);
match iframe {
Some(iframe) => iframe.iframe_load_event_steps(child_id),
Expand Down Expand Up @@ -1958,6 +1964,8 @@ impl ScriptThread {
incomplete.parent_info,
incomplete.window_size,
origin,
incomplete.navigation_start,
incomplete.navigation_start_precise,
self.webvr_thread.clone());

// Initialize the browsing context for the window.
Expand Down

0 comments on commit db044bd

Please sign in to comment.