Auto merge of #23203 - iulianR:22828, r=jdm

Implement PerformanceNavigation interface

<!-- Please describe your changes on the following line: -->
This is my first attempt. Please let me know if I should change anything.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #22828 (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because **not sure**

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23203)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-07-15 13:55:33 -04:00 committed by GitHub
commit 005320c08c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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();
};