script/dom/
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;
6
7use crate::dom::bindings::codegen::Bindings::PerformanceNavigationBinding::{
8    PerformanceNavigationConstants, PerformanceNavigationMethods,
9};
10use crate::dom::bindings::codegen::Bindings::WindowBinding::Window_Binding::WindowMethods;
11use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object};
12use crate::dom::bindings::root::DomRoot;
13use crate::dom::globalscope::GlobalScope;
14use crate::script_runtime::CanGc;
15
16#[dom_struct]
17pub(crate) struct PerformanceNavigation {
18    reflector_: Reflector,
19}
20
21impl PerformanceNavigation {
22    fn new_inherited() -> PerformanceNavigation {
23        PerformanceNavigation {
24            reflector_: Reflector::new(),
25        }
26    }
27
28    pub(crate) fn new(global: &GlobalScope, can_gc: CanGc) -> DomRoot<PerformanceNavigation> {
29        reflect_dom_object(
30            Box::new(PerformanceNavigation::new_inherited()),
31            global,
32            can_gc,
33        )
34    }
35}
36
37impl PerformanceNavigationMethods<crate::DomTypeHolder> for PerformanceNavigation {
38    // https://w3c.github.io/navigation-timing/#dom-performancenavigation-type
39    fn Type(&self) -> u16 {
40        PerformanceNavigationConstants::TYPE_NAVIGATE
41    }
42
43    // https://w3c.github.io/navigation-timing/#dom-performancenavigation-redirectcount
44    fn RedirectCount(&self) -> u16 {
45        self.global().as_window().Document().get_redirect_count()
46    }
47}