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 script_bindings::reflector::{Reflector, reflect_dom_object};
7
8use crate::dom::bindings::codegen::Bindings::PerformanceNavigationBinding::{
9    PerformanceNavigationConstants, PerformanceNavigationMethods,
10};
11use crate::dom::bindings::codegen::Bindings::WindowBinding::Window_Binding::WindowMethods;
12use crate::dom::bindings::reflector::DomGlobal;
13use crate::dom::bindings::root::DomRoot;
14use crate::dom::globalscope::GlobalScope;
15use crate::script_runtime::CanGc;
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(global: &GlobalScope, can_gc: CanGc) -> DomRoot<PerformanceNavigation> {
30        reflect_dom_object(
31            Box::new(PerformanceNavigation::new_inherited()),
32            global,
33            can_gc,
34        )
35    }
36}
37
38impl PerformanceNavigationMethods<crate::DomTypeHolder> for PerformanceNavigation {
39    /// <https://w3c.github.io/navigation-timing/#dom-performancenavigation-type>
40    fn Type(&self) -> u16 {
41        PerformanceNavigationConstants::TYPE_NAVIGATE
42    }
43
44    /// <https://w3c.github.io/navigation-timing/#dom-performancenavigation-redirectcount>
45    fn RedirectCount(&self) -> u16 {
46        self.global().as_window().Document().get_redirect_count()
47    }
48}