2016-04-17 23:03:28 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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 http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/PerformanceNavigationTiming.h"
|
|
|
|
#include "mozilla/dom/PerformanceNavigationTimingBinding.h"
|
2020-05-07 19:33:38 +03:00
|
|
|
#include "mozilla/StaticPrefs_dom.h"
|
|
|
|
#include "mozilla/StaticPrefs_privacy.h"
|
2016-04-17 23:03:28 +03:00
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PerformanceNavigationTiming)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(PerformanceResourceTiming)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(PerformanceNavigationTiming, PerformanceResourceTiming)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(PerformanceNavigationTiming,
|
|
|
|
PerformanceResourceTiming)
|
|
|
|
|
|
|
|
JSObject* PerformanceNavigationTiming::WrapObject(
|
|
|
|
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return PerformanceNavigationTiming_Binding::Wrap(aCx, this, aGivenProto);
|
2016-04-17 23:03:28 +03:00
|
|
|
}
|
|
|
|
|
2020-03-25 17:09:42 +03:00
|
|
|
#define REDUCE_TIME_PRECISION \
|
|
|
|
return nsRFPService::ReduceTimePrecisionAsMSecs( \
|
|
|
|
rawValue, mPerformance->GetRandomTimelineSeed(), \
|
|
|
|
mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated())
|
2018-05-24 23:44:46 +03:00
|
|
|
|
2017-10-04 05:05:39 +03:00
|
|
|
DOMHighResTimeStamp PerformanceNavigationTiming::UnloadEventStart() const {
|
2019-07-09 10:19:50 +03:00
|
|
|
DOMHighResTimeStamp rawValue = 0;
|
|
|
|
/*
|
|
|
|
* Per Navigation Timing Level 2, the value is 0 if
|
|
|
|
* a. there is no previous document or
|
|
|
|
* b. the same-origin-check fails.
|
|
|
|
*
|
|
|
|
* The same-origin-check is defined as:
|
|
|
|
* 1. If the previous document exists and its origin is not same
|
|
|
|
* origin as the current document's origin, return "fail".
|
|
|
|
* 2. Let request be the current document's request.
|
|
|
|
* 3. If request's redirect count is not zero, and all of request's
|
|
|
|
* HTTP redirects have the same origin as the current document,
|
|
|
|
* return "pass".
|
|
|
|
* 4. Otherwise, return "fail".
|
|
|
|
*/
|
|
|
|
if (mTimingData->AllRedirectsSameOrigin()) { // same-origin-check:2/3
|
|
|
|
/*
|
|
|
|
* GetUnloadEventStartHighRes returns 0 if
|
|
|
|
* 1. there is no previous document (a, above) or
|
|
|
|
* 2. the current URI does not have the same origin as
|
|
|
|
* the previous document's URI. (same-origin-check:1)
|
|
|
|
*/
|
|
|
|
rawValue = mPerformance->GetDOMTiming()->GetUnloadEventStartHighRes();
|
|
|
|
}
|
2018-05-24 23:44:46 +03:00
|
|
|
|
|
|
|
REDUCE_TIME_PRECISION;
|
2016-04-17 23:03:28 +03:00
|
|
|
}
|
|
|
|
|
2017-10-04 05:05:39 +03:00
|
|
|
DOMHighResTimeStamp PerformanceNavigationTiming::UnloadEventEnd() const {
|
2019-07-09 10:19:50 +03:00
|
|
|
DOMHighResTimeStamp rawValue = 0;
|
|
|
|
|
|
|
|
// See comments in PerformanceNavigationTiming::UnloadEventEnd().
|
|
|
|
if (mTimingData->AllRedirectsSameOrigin()) {
|
|
|
|
rawValue = mPerformance->GetDOMTiming()->GetUnloadEventEndHighRes();
|
|
|
|
}
|
2018-05-24 23:44:46 +03:00
|
|
|
|
|
|
|
REDUCE_TIME_PRECISION;
|
2016-04-17 23:03:28 +03:00
|
|
|
}
|
|
|
|
|
2017-10-04 05:05:39 +03:00
|
|
|
DOMHighResTimeStamp PerformanceNavigationTiming::DomInteractive() const {
|
2018-05-24 23:44:46 +03:00
|
|
|
DOMHighResTimeStamp rawValue =
|
|
|
|
mPerformance->GetDOMTiming()->GetDomInteractiveHighRes();
|
|
|
|
|
|
|
|
REDUCE_TIME_PRECISION;
|
2016-04-17 23:03:28 +03:00
|
|
|
}
|
|
|
|
|
2017-10-04 05:05:39 +03:00
|
|
|
DOMHighResTimeStamp PerformanceNavigationTiming::DomContentLoadedEventStart()
|
|
|
|
const {
|
2018-05-24 23:44:46 +03:00
|
|
|
DOMHighResTimeStamp rawValue =
|
|
|
|
mPerformance->GetDOMTiming()->GetDomContentLoadedEventStartHighRes();
|
|
|
|
|
|
|
|
REDUCE_TIME_PRECISION;
|
2016-04-17 23:03:28 +03:00
|
|
|
}
|
|
|
|
|
2017-10-04 05:05:39 +03:00
|
|
|
DOMHighResTimeStamp PerformanceNavigationTiming::DomContentLoadedEventEnd()
|
|
|
|
const {
|
2018-05-24 23:44:46 +03:00
|
|
|
DOMHighResTimeStamp rawValue =
|
|
|
|
mPerformance->GetDOMTiming()->GetDomContentLoadedEventEndHighRes();
|
|
|
|
|
|
|
|
REDUCE_TIME_PRECISION;
|
2016-04-17 23:03:28 +03:00
|
|
|
}
|
|
|
|
|
2017-10-04 05:05:39 +03:00
|
|
|
DOMHighResTimeStamp PerformanceNavigationTiming::DomComplete() const {
|
2018-05-24 23:44:46 +03:00
|
|
|
DOMHighResTimeStamp rawValue =
|
|
|
|
mPerformance->GetDOMTiming()->GetDomCompleteHighRes();
|
|
|
|
|
|
|
|
REDUCE_TIME_PRECISION;
|
2016-04-17 23:03:28 +03:00
|
|
|
}
|
|
|
|
|
2017-10-04 05:05:39 +03:00
|
|
|
DOMHighResTimeStamp PerformanceNavigationTiming::LoadEventStart() const {
|
2018-05-24 23:44:46 +03:00
|
|
|
DOMHighResTimeStamp rawValue =
|
|
|
|
mPerformance->GetDOMTiming()->GetLoadEventStartHighRes();
|
|
|
|
|
|
|
|
REDUCE_TIME_PRECISION;
|
2016-04-17 23:03:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp PerformanceNavigationTiming::LoadEventEnd() const {
|
2018-05-24 23:44:46 +03:00
|
|
|
DOMHighResTimeStamp rawValue =
|
|
|
|
mPerformance->GetDOMTiming()->GetLoadEventEndHighRes();
|
|
|
|
|
|
|
|
REDUCE_TIME_PRECISION;
|
2016-04-17 23:03:28 +03:00
|
|
|
}
|
|
|
|
|
2017-10-04 05:05:39 +03:00
|
|
|
NavigationType PerformanceNavigationTiming::Type() const {
|
2018-01-24 19:17:31 +03:00
|
|
|
switch (mPerformance->GetDOMTiming()->GetType()) {
|
2016-04-17 23:03:28 +03:00
|
|
|
case nsDOMNavigationTiming::TYPE_NAVIGATE:
|
|
|
|
return NavigationType::Navigate;
|
|
|
|
break;
|
|
|
|
case nsDOMNavigationTiming::TYPE_RELOAD:
|
|
|
|
return NavigationType::Reload;
|
|
|
|
break;
|
|
|
|
case nsDOMNavigationTiming::TYPE_BACK_FORWARD:
|
|
|
|
return NavigationType::Back_forward;
|
|
|
|
break;
|
|
|
|
default:
|
2017-09-26 18:44:05 +03:00
|
|
|
// The type is TYPE_RESERVED or some other value that was later added.
|
|
|
|
// We fallback to the default of Navigate.
|
2016-04-17 23:03:28 +03:00
|
|
|
return NavigationType::Navigate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-04 05:05:39 +03:00
|
|
|
uint16_t PerformanceNavigationTiming::RedirectCount() const {
|
2018-01-24 19:17:31 +03:00
|
|
|
return mTimingData->GetRedirectCount();
|
2016-04-17 23:03:28 +03:00
|
|
|
}
|
2018-08-04 09:54:58 +03:00
|
|
|
|
|
|
|
void PerformanceNavigationTiming::UpdatePropertiesFromHttpChannel(
|
|
|
|
nsIHttpChannel* aHttpChannel, nsITimedChannel* aChannel) {
|
|
|
|
mTimingData->SetPropertiesFromHttpChannel(aHttpChannel, aChannel);
|
|
|
|
}
|
2020-05-07 19:33:38 +03:00
|
|
|
|
|
|
|
bool PerformanceNavigationTiming::Enabled(JSContext* aCx, JSObject* aGlobal) {
|
|
|
|
return (StaticPrefs::dom_enable_performance_navigation_timing() &&
|
|
|
|
!StaticPrefs::privacy_resistFingerprinting());
|
|
|
|
}
|