aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/performancetiming.rs
blob: 4d453dcb4bb7b3a84efd0f352b71924d29501c23 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* 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 http://mozilla.org/MPL/2.0/. */

use dom::bindings::codegen::Bindings::PerformanceTimingBinding;
use dom::bindings::codegen::Bindings::PerformanceTimingBinding::PerformanceTimingMethods;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::Root;
use dom::bindings::utils::{Reflector, reflect_dom_object};
use dom::window::Window;

#[dom_struct]
pub struct PerformanceTiming {
    reflector_: Reflector,
    navigationStart: u64,
    navigationStartPrecise: f64,
}

impl PerformanceTiming {
    fn new_inherited(navStart: u64, navStartPrecise: f64)
                         -> PerformanceTiming {
        PerformanceTiming {
            reflector_: Reflector::new(),
            navigationStart: navStart,
            navigationStartPrecise: navStartPrecise,
        }
    }

    #[allow(unrooted_must_root)]
    pub fn new(window: &Window,
               navigation_start: u64,
               navigation_start_precise: f64)
               -> Root<PerformanceTiming> {
        let timing = PerformanceTiming::new_inherited(navigation_start,
                                                      navigation_start_precise);
        reflect_dom_object(box timing, GlobalRef::Window(window),
                           PerformanceTimingBinding::Wrap)
    }
}

impl<'a> PerformanceTimingMethods for &'a PerformanceTiming {
    // https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/
    // NavigationTiming/Overview.html#dom-performancetiming-navigationstart
    fn NavigationStart(self) -> u64 {
        self.navigationStart
    }
}


impl PerformanceTiming {
    pub fn NavigationStartPrecise(&self) -> f64 {
        self.navigationStartPrecise
    }
}