script/dom/
performancenavigationtiming.rs1use base::cross_process_instant::CrossProcessInstant;
6use dom_struct::dom_struct;
7
8use crate::dom::bindings::codegen::Bindings::PerformanceBinding::DOMHighResTimeStamp;
9use crate::dom::bindings::codegen::Bindings::PerformanceNavigationTimingBinding::{
10 NavigationTimingType, PerformanceNavigationTimingMethods,
11};
12use crate::dom::bindings::inheritance::Castable;
13use crate::dom::bindings::reflector::reflect_dom_object;
14use crate::dom::bindings::root::{Dom, DomRoot};
15use crate::dom::document::Document;
16use crate::dom::globalscope::GlobalScope;
17use crate::dom::performanceresourcetiming::{InitiatorType, PerformanceResourceTiming};
18use crate::script_runtime::CanGc;
19
20#[dom_struct]
21pub(crate) struct PerformanceNavigationTiming {
25 performanceresourcetiming: PerformanceResourceTiming,
27 document: Dom<Document>,
28 nav_type: NavigationTimingType,
29}
30
31impl PerformanceNavigationTiming {
32 fn new_inherited(
33 navigation_start: CrossProcessInstant,
34 document: &Document,
35 ) -> PerformanceNavigationTiming {
36 PerformanceNavigationTiming {
37 performanceresourcetiming: PerformanceResourceTiming::new_inherited(
38 document.url(),
39 InitiatorType::Navigation,
40 None,
41 Some(navigation_start),
42 ),
43 document: Dom::from_ref(document),
44 nav_type: NavigationTimingType::Navigate,
45 }
46 }
47
48 pub(crate) fn new(
49 global: &GlobalScope,
50 fetch_start: CrossProcessInstant,
51 document: &Document,
52 can_gc: CanGc,
53 ) -> DomRoot<PerformanceNavigationTiming> {
54 reflect_dom_object(
55 Box::new(PerformanceNavigationTiming::new_inherited(
56 fetch_start,
57 document,
58 )),
59 global,
60 can_gc,
61 )
62 }
63}
64
65impl PerformanceNavigationTimingMethods<crate::DomTypeHolder> for PerformanceNavigationTiming {
67 fn UnloadEventStart(&self) -> DOMHighResTimeStamp {
69 self.upcast::<PerformanceResourceTiming>()
70 .to_dom_high_res_time_stamp(self.document.get_unload_event_start())
71 }
72
73 fn UnloadEventEnd(&self) -> DOMHighResTimeStamp {
75 self.upcast::<PerformanceResourceTiming>()
76 .to_dom_high_res_time_stamp(self.document.get_unload_event_end())
77 }
78
79 fn DomInteractive(&self) -> DOMHighResTimeStamp {
81 self.upcast::<PerformanceResourceTiming>()
82 .to_dom_high_res_time_stamp(self.document.get_dom_interactive())
83 }
84
85 fn DomContentLoadedEventStart(&self) -> DOMHighResTimeStamp {
87 self.upcast::<PerformanceResourceTiming>()
88 .to_dom_high_res_time_stamp(self.document.get_dom_content_loaded_event_start())
89 }
90
91 fn DomContentLoadedEventEnd(&self) -> DOMHighResTimeStamp {
93 self.upcast::<PerformanceResourceTiming>()
94 .to_dom_high_res_time_stamp(self.document.get_dom_content_loaded_event_end())
95 }
96
97 fn DomComplete(&self) -> DOMHighResTimeStamp {
99 self.upcast::<PerformanceResourceTiming>()
100 .to_dom_high_res_time_stamp(self.document.get_dom_complete())
101 }
102
103 fn LoadEventStart(&self) -> DOMHighResTimeStamp {
105 self.upcast::<PerformanceResourceTiming>()
106 .to_dom_high_res_time_stamp(self.document.get_load_event_start())
107 }
108
109 fn LoadEventEnd(&self) -> DOMHighResTimeStamp {
111 self.upcast::<PerformanceResourceTiming>()
112 .to_dom_high_res_time_stamp(self.document.get_load_event_end())
113 }
114
115 fn Type(&self) -> NavigationTimingType {
117 self.nav_type
118 }
119
120 fn RedirectCount(&self) -> u16 {
122 self.document.get_redirect_count()
123 }
124
125 fn TopLevelDomComplete(&self) -> DOMHighResTimeStamp {
128 self.upcast::<PerformanceResourceTiming>()
129 .to_dom_high_res_time_stamp(self.document.get_top_level_dom_complete())
130 }
131}