Add Performance object to Window and implement Performance::Now()

This commit is contained in:
Gulshan Singh 2014-05-01 16:23:32 -04:00
parent 0ab3444af9
commit fb0c433b70
9 changed files with 223 additions and 1 deletions

View file

@ -13,6 +13,7 @@ use dom::eventtarget::{EventTarget, WindowTypeId};
use dom::console::Console;
use dom::location::Location;
use dom::navigator::Navigator;
use dom::performance::Performance;
use layout_interface::{ReflowForDisplay, DocumentDamageLevel};
use script_task::{ExitWindowMsg, FireTimerMsg, Page, ScriptChan};
@ -32,6 +33,8 @@ use std::hash::{Hash, sip};
use std::io::timer::Timer;
use std::rc::Rc;
use time;
use serialize::{Encoder, Encodable};
use url::Url;
@ -71,6 +74,9 @@ pub struct Window {
pub compositor: Untraceable<~ScriptListener>,
pub browser_context: Option<BrowserContext>,
pub page: Rc<Page>,
pub performance: Option<JS<Performance>>,
pub navigationStart: u64,
pub navigationStartPrecise: f64,
}
impl Window {
@ -131,6 +137,7 @@ pub trait WindowMethods {
fn ClearInterval(&mut self, handle: i32);
fn Window(&self) -> Temporary<Window>;
fn Self(&self) -> Temporary<Window>;
fn Performance(&mut self) -> Temporary<Performance>;
}
impl<'a> WindowMethods for JSRef<'a, Window> {
@ -248,6 +255,14 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
fn Self(&self) -> Temporary<Window> {
self.Window()
}
fn Performance(&mut self) -> Temporary<Performance> {
if self.performance.is_none() {
let performance = Performance::new(self);
self.performance.assign(Some(performance));
}
Temporary::new(self.performance.get_ref().clone())
}
}
impl Reflectable for Window {
@ -355,6 +370,9 @@ impl Window {
active_timers: ~HashMap::new(),
next_timer_handle: 0,
browser_context: None,
performance: None,
navigationStart: time::get_time().sec as u64,
navigationStartPrecise: time::precise_time_s(),
};
WindowBinding::Wrap(cx, win)