Implement PerformanceNavigation interface

This commit is contained in:
Iulian Gabriel Radu 2019-04-11 00:26:01 +03:00
parent e100af57a5
commit 62f0785c2c
19 changed files with 411 additions and 69 deletions

View file

@ -428,6 +428,7 @@ pub mod performance;
pub mod performanceentry;
pub mod performancemark;
pub mod performancemeasure;
pub mod performancenavigation;
pub mod performancenavigationtiming;
pub mod performanceobserver;
pub mod performanceobserverentrylist;

View file

@ -19,6 +19,7 @@ use crate::dom::globalscope::GlobalScope;
use crate::dom::performanceentry::PerformanceEntry;
use crate::dom::performancemark::PerformanceMark;
use crate::dom::performancemeasure::PerformanceMeasure;
use crate::dom::performancenavigation::PerformanceNavigation;
use crate::dom::performancenavigationtiming::PerformanceNavigationTiming;
use crate::dom::performanceobserver::PerformanceObserver as DOMPerformanceObserver;
use crate::dom::window::Window;
@ -372,6 +373,11 @@ impl PerformanceMethods for Performance {
unreachable!("Are we trying to expose Performance.timing in workers?");
}
// https://w3c.github.io/navigation-timing/#dom-performance-navigation
fn Navigation(&self) -> DomRoot<PerformanceNavigation> {
PerformanceNavigation::new(&self.global())
}
// https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/HighResolutionTime/Overview.html#dom-performance-now
fn Now(&self) -> DOMHighResTimeStamp {
Finite::wrap(self.now())

View file

@ -0,0 +1,45 @@
/* 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 https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::codegen::Bindings::PerformanceNavigationBinding::{
self, PerformanceNavigationConstants, PerformanceNavigationMethods,
};
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
#[dom_struct]
pub struct PerformanceNavigation {
reflector_: Reflector,
}
impl PerformanceNavigation {
fn new_inherited() -> PerformanceNavigation {
PerformanceNavigation {
reflector_: Reflector::new(),
}
}
pub fn new(global: &GlobalScope) -> DomRoot<PerformanceNavigation> {
reflect_dom_object(
Box::new(PerformanceNavigation::new_inherited()),
global,
PerformanceNavigationBinding::Wrap,
)
}
}
impl PerformanceNavigationMethods for PerformanceNavigation {
// https://w3c.github.io/navigation-timing/#dom-performancenavigation-type
fn Type(&self) -> u16 {
PerformanceNavigationConstants::TYPE_NAVIGATE
}
// https://w3c.github.io/navigation-timing/#dom-performancenavigation-redirectcount
fn RedirectCount(&self) -> u16 {
self.global().as_window().Document().get_redirect_count()
}
}

View file

@ -49,3 +49,8 @@ partial interface Performance {
partial interface Performance {
PerformanceNavigationTiming timing();
};
// https://w3c.github.io/navigation-timing/#extensions-to-the-performance-interface
partial interface Performance {
[SameObject, Exposed=Window]
readonly attribute PerformanceNavigation navigation;
};

View file

@ -0,0 +1,18 @@
/* 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 https://mozilla.org/MPL/2.0/. */
/*
* The origin of this IDL file is
* https://w3c.github.io/navigation-timing/#the-performancenavigation-interface
*/
[Exposed=Window]
interface PerformanceNavigation {
const unsigned short TYPE_NAVIGATE = 0;
const unsigned short TYPE_RELOAD = 1;
const unsigned short TYPE_BACK_FORWARD = 2;
const unsigned short TYPE_RESERVED = 255;
readonly attribute unsigned short type;
readonly attribute unsigned short redirectCount;
// [Default] object toJSON();
};