Skip to main content

script/dom/performance/
performancenavigation.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use dom_struct::dom_struct;
6use js::context::JSContext;
7use script_bindings::reflector::{Reflector, reflect_dom_object_with_cx};
8
9use crate::dom::bindings::codegen::Bindings::PerformanceNavigationBinding::{
10    PerformanceNavigationConstants, PerformanceNavigationMethods,
11};
12use crate::dom::bindings::codegen::Bindings::WindowBinding::Window_Binding::WindowMethods;
13use crate::dom::bindings::reflector::DomGlobal;
14use crate::dom::bindings::root::DomRoot;
15use crate::dom::globalscope::GlobalScope;
16
17#[dom_struct]
18pub(crate) struct PerformanceNavigation {
19    reflector_: Reflector,
20}
21
22impl PerformanceNavigation {
23    fn new_inherited() -> PerformanceNavigation {
24        PerformanceNavigation {
25            reflector_: Reflector::new(),
26        }
27    }
28
29    pub(crate) fn new(cx: &mut JSContext, global: &GlobalScope) -> DomRoot<PerformanceNavigation> {
30        reflect_dom_object_with_cx(Box::new(PerformanceNavigation::new_inherited()), global, cx)
31    }
32}
33
34impl PerformanceNavigationMethods<crate::DomTypeHolder> for PerformanceNavigation {
35    /// <https://w3c.github.io/navigation-timing/#dom-performancenavigation-type>
36    fn Type(&self) -> u16 {
37        PerformanceNavigationConstants::TYPE_NAVIGATE
38    }
39
40    /// <https://w3c.github.io/navigation-timing/#dom-performancenavigation-redirectcount>
41    fn RedirectCount(&self) -> u16 {
42        self.global().as_window().Document().get_redirect_count()
43    }
44}