servo: Merge #10538 - Improve PerformanceTiming Interface (from izgzhen:performance_timing); r=Ms2ger

Solving https://github.com/servo/servo/issues/10428

- Fix timing precision in old `update_with_current_time`
- Correct time unit in `navigation_start`
- Add `LoadEventStart` and `LoadEventEnd` timing properties

There are still many properties left unimplemented. I tend to leave the for future PRs.

Welcome comments!

Source-Repo: https://github.com/servo/servo
Source-Revision: 421dcc92f05532e5d8bda850c8d14c9375da2bd9
This commit is contained in:
Zhen Zhang 2016-04-13 01:16:10 +05:01
Родитель b05eeec25c
Коммит abd44774f2
4 изменённых файлов: 43 добавлений и 12 удалений

Просмотреть файл

@ -209,13 +209,15 @@ pub struct Document {
modified_elements: DOMRefCell<HashMap<JS<Element>, ElementSnapshot>>,
/// http://w3c.github.io/touch-events/#dfn-active-touch-point
active_touch_points: DOMRefCell<Vec<JS<Touch>>>,
/// DOM-Related Navigation Timing properties:
/// http://w3c.github.io/navigation-timing/#widl-PerformanceTiming-domLoading
/// 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>,
load_event_start: Cell<u64>,
load_event_end: Cell<u64>,
/// Vector to store CSS errors
css_errors_store: DOMRefCell<Vec<CSSError>>,
/// https://html.spec.whatwg.org/multipage/#concept-document-https-state
@ -544,14 +546,14 @@ impl Document {
DocumentReadyState::Loading => {
// https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowserconnected
self.trigger_mozbrowser_event(MozBrowserEvent::Connected);
update_with_current_time(&self.dom_loading);
update_with_current_time_ms(&self.dom_loading);
},
DocumentReadyState::Complete => {
// https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowserloadend
self.trigger_mozbrowser_event(MozBrowserEvent::LoadEnd);
update_with_current_time(&self.dom_complete);
update_with_current_time_ms(&self.dom_complete);
},
DocumentReadyState::Interactive => update_with_current_time(&self.dom_interactive),
DocumentReadyState::Interactive => update_with_current_time_ms(&self.dom_interactive),
};
self.ready_state.set(state);
@ -1447,7 +1449,7 @@ impl Document {
}
self.domcontentloaded_dispatched.set(true);
update_with_current_time(&self.dom_content_loaded_event_start);
update_with_current_time_ms(&self.dom_content_loaded_event_start);
let chan = MainThreadScriptChan(self.window().main_thread_script_chan().clone()).clone();
let doctarget = Trusted::new(self.upcast::<EventTarget>(), chan);
@ -1458,7 +1460,7 @@ impl Document {
ReflowQueryType::NoQuery,
ReflowReason::DOMContentLoaded);
update_with_current_time(&self.dom_content_loaded_event_end);
update_with_current_time_ms(&self.dom_content_loaded_event_end);
}
pub fn notify_constellation_load(&self) {
@ -1513,6 +1515,14 @@ impl Document {
self.dom_complete.get()
}
pub fn get_load_event_start(&self) -> u64 {
self.load_event_start.get()
}
pub fn get_load_event_end(&self) -> u64 {
self.load_event_end.get()
}
// https://html.spec.whatwg.org/multipage/#fire-a-focus-event
fn fire_focus_event(&self, focus_event_type: FocusEventType, node: &Node, relatedTarget: Option<&EventTarget>) {
let (event_name, does_bubble) = match focus_event_type {
@ -1658,6 +1668,8 @@ impl Document {
dom_content_loaded_event_start: Cell::new(Default::default()),
dom_content_loaded_event_end: Cell::new(Default::default()),
dom_complete: Cell::new(Default::default()),
load_event_start: Cell::new(Default::default()),
load_event_end: Cell::new(Default::default()),
css_errors_store: DOMRefCell::new(vec![]),
https_state: Cell::new(HttpsState::None),
touchpad_pressure_phase: Cell::new(TouchpadPressurePhase::BeforeClick),
@ -2712,9 +2724,10 @@ fn is_scheme_host_port_tuple(url: &Url) -> bool {
url.host().is_some() && url.port_or_default().is_some()
}
fn update_with_current_time(marker: &Cell<u64>) {
fn update_with_current_time_ms(marker: &Cell<u64>) {
if marker.get() == Default::default() {
let current_time_ms = time::get_time().sec * 1000;
let time = time::get_time();
let current_time_ms = time.sec * 1000 + time.nsec as i64 / 1000000;
marker.set(current_time_ms as u64);
}
}
@ -2744,8 +2757,15 @@ impl DocumentProgressHandler {
EventCancelable::NotCancelable);
let wintarget = window.upcast::<EventTarget>();
event.set_trusted(true);
// http://w3c.github.io/navigation-timing/#widl-PerformanceNavigationTiming-loadEventStart
update_with_current_time_ms(&document.load_event_start);
let _ = wintarget.dispatch_event_with_target(document.upcast(), &event);
// http://w3c.github.io/navigation-timing/#widl-PerformanceNavigationTiming-loadEventEnd
update_with_current_time_ms(&document.load_event_end);
document.notify_constellation_load();
window.reflow(ReflowGoal::ForDisplay,

Просмотреть файл

@ -76,6 +76,16 @@ impl PerformanceTimingMethods for PerformanceTiming {
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()
}
}

Просмотреть файл

@ -27,6 +27,6 @@ interface PerformanceTiming {
readonly attribute unsigned long long domContentLoadedEventStart;
readonly attribute unsigned long long domContentLoadedEventEnd;
readonly attribute unsigned long long domComplete;
/* readonly attribute unsigned long long loadEventStart;
readonly attribute unsigned long long loadEventEnd; */
readonly attribute unsigned long long loadEventStart;
readonly attribute unsigned long long loadEventEnd;
};

Просмотреть файл

@ -1383,6 +1383,7 @@ impl Window {
pipelineid: id,
script_chan: Arc::new(Mutex::new(control_chan)),
};
let current_time = time::get_time();
let win = box Window {
eventtarget: EventTarget::new_inherited(),
script_chan: script_chan,
@ -1402,7 +1403,7 @@ impl Window {
devtools_chan: devtools_chan,
browsing_context: Default::default(),
performance: Default::default(),
navigation_start: time::get_time().sec as u64,
navigation_start: (current_time.sec * 1000 + current_time.nsec as i64 / 1000000) as u64,
navigation_start_precise: time::precise_time_ns() as f64,
screen: Default::default(),
session_storage: Default::default(),