2016-06-09 13:43:56 +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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_PerformanceTiming_h
|
|
|
|
#define mozilla_dom_PerformanceTiming_h
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
2019-07-26 04:10:23 +03:00
|
|
|
#include "mozilla/StaticPrefs_dom.h"
|
2016-06-09 13:43:56 +03:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsDOMNavigationTiming.h"
|
2018-01-11 00:51:23 +03:00
|
|
|
#include "nsRFPService.h"
|
2016-06-09 13:43:56 +03:00
|
|
|
#include "nsWrapperCache.h"
|
2016-06-09 20:04:42 +03:00
|
|
|
#include "Performance.h"
|
2018-04-24 14:04:12 +03:00
|
|
|
#include "nsITimedChannel.h"
|
2016-06-09 13:43:56 +03:00
|
|
|
|
|
|
|
class nsIHttpChannel;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2018-01-24 19:17:32 +03:00
|
|
|
class PerformanceTiming;
|
|
|
|
|
2018-01-24 19:17:31 +03:00
|
|
|
class PerformanceTimingData final {
|
2018-01-24 19:17:32 +03:00
|
|
|
friend class PerformanceTiming;
|
|
|
|
|
2016-06-09 13:43:56 +03:00
|
|
|
public:
|
2018-01-24 19:17:32 +03:00
|
|
|
// This can return null.
|
|
|
|
static PerformanceTimingData* Create(nsITimedChannel* aChannel,
|
|
|
|
nsIHttpChannel* aHttpChannel,
|
|
|
|
DOMHighResTimeStamp aZeroTime,
|
|
|
|
nsAString& aInitiatorType,
|
|
|
|
nsAString& aEntryName);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-24 19:17:31 +03:00
|
|
|
PerformanceTimingData(nsITimedChannel* aChannel, nsIHttpChannel* aHttpChannel,
|
|
|
|
DOMHighResTimeStamp aZeroTime);
|
2018-01-24 19:17:31 +03:00
|
|
|
|
2018-08-03 14:08:32 +03:00
|
|
|
void SetPropertiesFromHttpChannel(nsIHttpChannel* aHttpChannel,
|
|
|
|
nsITimedChannel* aChannel);
|
2018-01-24 19:17:31 +03:00
|
|
|
|
|
|
|
bool IsInitialized() const { return mInitialized; }
|
2018-01-24 19:17:31 +03:00
|
|
|
|
2018-01-24 19:17:31 +03:00
|
|
|
const nsString& NextHopProtocol() const { return mNextHopProtocol; }
|
|
|
|
|
|
|
|
uint64_t TransferSize() const { return mTransferSize; }
|
|
|
|
|
|
|
|
uint64_t EncodedBodySize() const { return mEncodedBodySize; }
|
|
|
|
|
|
|
|
uint64_t DecodedBodySize() const { return mDecodedBodySize; }
|
2016-06-09 13:43:56 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param aStamp
|
|
|
|
* The TimeStamp recorded for a specific event. This TimeStamp can
|
|
|
|
* be null.
|
|
|
|
* @return the duration of an event with a given TimeStamp, relative to the
|
|
|
|
* navigationStart TimeStamp (the moment the user landed on the
|
|
|
|
* page), if the given TimeStamp is valid. Otherwise, it will return
|
|
|
|
* the FetchStart timing value.
|
|
|
|
*/
|
2018-01-24 19:17:31 +03:00
|
|
|
inline DOMHighResTimeStamp TimeStampToReducedDOMHighResOrFetchStart(
|
|
|
|
Performance* aPerformance, TimeStamp aStamp) {
|
|
|
|
MOZ_ASSERT(aPerformance);
|
|
|
|
|
2018-03-09 18:29:33 +03:00
|
|
|
if (aStamp.IsNull()) {
|
|
|
|
return FetchStartHighRes(aPerformance);
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMHighResTimeStamp rawTimestamp =
|
|
|
|
TimeStampToDOMHighRes(aPerformance, aStamp);
|
|
|
|
if (aPerformance->IsSystemPrincipal()) {
|
|
|
|
return rawTimestamp;
|
|
|
|
}
|
|
|
|
|
2018-03-13 20:36:34 +03:00
|
|
|
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
|
|
|
rawTimestamp, aPerformance->GetRandomTimelineSeed());
|
2016-06-09 13:43:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The nsITimedChannel records an absolute timestamp for each event.
|
|
|
|
* The nsDOMNavigationTiming will record the moment when the user landed on
|
|
|
|
* the page. This is a window.performance unique timestamp, so it can be used
|
|
|
|
* for all the events (navigation timing and resource timing events).
|
|
|
|
*
|
|
|
|
* The algorithm operates in 2 steps:
|
|
|
|
* 1. The first step is to subtract the two timestamps: the argument (the
|
2018-01-24 19:17:31 +03:00
|
|
|
* event's timestamp) and the navigation start timestamp. This will result in
|
2016-06-09 13:43:56 +03:00
|
|
|
* a relative timestamp of the event (relative to the navigation start -
|
|
|
|
* window.performance.timing.navigationStart).
|
|
|
|
* 2. The second step is to add any required offset (the mZeroTime). For now,
|
|
|
|
* this offset value is either 0 (for the resource timing), or equal to
|
|
|
|
* "performance.navigationStart" (for navigation timing).
|
|
|
|
* For the resource timing, mZeroTime is set to 0, causing the result to be a
|
|
|
|
* relative time.
|
|
|
|
* For the navigation timing, mZeroTime is set to
|
|
|
|
* "performance.navigationStart" causing the result be an absolute time.
|
|
|
|
*
|
|
|
|
* @param aStamp
|
|
|
|
* The TimeStamp recorded for a specific event. This TimeStamp can't
|
|
|
|
* be null.
|
|
|
|
* @return number of milliseconds value as one of:
|
|
|
|
* - relative to the navigation start time, time the user has landed on the
|
2018-01-24 19:17:31 +03:00
|
|
|
* page
|
2016-06-09 13:43:56 +03:00
|
|
|
* - an absolute wall clock time since the unix epoch
|
|
|
|
*/
|
2018-01-24 19:17:31 +03:00
|
|
|
inline DOMHighResTimeStamp TimeStampToDOMHighRes(Performance* aPerformance,
|
|
|
|
TimeStamp aStamp) const {
|
|
|
|
MOZ_ASSERT(aPerformance);
|
2016-06-09 13:43:56 +03:00
|
|
|
MOZ_ASSERT(!aStamp.IsNull());
|
2018-01-24 19:17:31 +03:00
|
|
|
|
2018-01-24 19:17:32 +03:00
|
|
|
TimeDuration duration = aStamp - aPerformance->CreationTimeStamp();
|
Bug 1429764 Do not call ReduceTimerPrecision twice for DOM Navigation timers r=bkelly,timhuang
Bug 1429764 details a test failure that was asserting that the performance navigation
timers were strictly increasing (or equal). fetchStart should have a timestamp before
domainLookupStart. But it didn't.
The problem is two-fold. This corrects the test and the issue by addressing one part
of the problem, the second part of the problem needs to be written up in a new bug
and addressed there. (That bug is not yet filed at writing, but see dependencies of
1429764 in the future to find it.)
The second, and underlying, problem is that calling ReduceTimerPrecision with the
same value multiple times may continually reduce it. Meaning that the first you call
it with, say, .75, (and a precision of .20), it will be reduced to .6. The second time
you call it (with .6), instead of staying at .6 it will be reduced to .4. This is
because floats are fuzzy. Inside ReduceTimerPrecision we are multiplying a decimal by
a decimal, so while floor(.6 / .20) should equal 3, sometimes it's actually 2.999...
which gets floors to 2, gets multiplied again by .2, and which results in .4
If that's the underlying problem, the first, and surface, problem is - why are we
calling ReduceTimerPrecision multiple times? We shouldn't be. That's what this
patch fixes.
TimeStampToDOMHighResOrFetchStart will return either TimeStampToDOMHighRes() or
FetchStartHighRes(). FetchStartHighRes() internally calls TimeStampToDOMHighRes
and then ReduceTimerPrecision - this is where (some of) the two reduction calls
happen - because TimeStampToDOMHighRes itself calls ReduceTimerPrecision also.
I remove the ReduceTimerPrecision from TimeStampToDOMHighRes. FetchStartHighRes
will now only call ReduceTimerPrecision once, at the end of the return.
But we have to fix places we call TimeStampToDOMHighResOrFetchStart, because the
callers of that function also call ReduceTimerPrecision. So if
TimeStampToDOMHighResOrFetchStart returned FetchStartHighRes, we'd be calling
ReduceTimerPrecision twice for those callers.
So inside first off, we remove the outer call to ReduceTimerPrecision. that
surrounds the 5 or so callsites of TimeStampToDOMHighResOrFetchStart. Then
inside of TimeStampToDOMHighResOrFetchStart we return either FetchStartHighRes
(which is has already called ReduceTimerPrecision) or we call
ReduceTimerPrecision with the value.
Now. TimeStampToDOMHighRes was used in more places than just FetchStartHighRes -
there were several other places where we were doing double rounding, and this
fixed those as well. AsyncOpenHighRes, WorkerStartHighRes, DomainLookupEndHighRes,
ConnectStartHighRes, SecureConnectionStartHighRes, ConnectEndHighRes, and
ResponseEndHighRes.
MozReview-Commit-ID: K5nHql135rb
--HG--
extra : rebase_source : e06785203f0f8b01fc7b694ce840f07dc09bc4a1
2018-01-12 22:36:04 +03:00
|
|
|
return duration.ToMilliseconds() + mZeroTime;
|
2016-06-09 13:43:56 +03:00
|
|
|
}
|
|
|
|
|
2018-01-24 19:17:31 +03:00
|
|
|
// The last channel's AsyncOpen time. This may occur before the FetchStart
|
|
|
|
// in some cases.
|
|
|
|
DOMHighResTimeStamp AsyncOpenHighRes(Performance* aPerformance);
|
|
|
|
|
|
|
|
// High resolution (used by resource timing)
|
|
|
|
DOMHighResTimeStamp WorkerStartHighRes(Performance* aPerformance);
|
|
|
|
DOMHighResTimeStamp FetchStartHighRes(Performance* aPerformance);
|
|
|
|
DOMHighResTimeStamp RedirectStartHighRes(Performance* aPerformance);
|
|
|
|
DOMHighResTimeStamp RedirectEndHighRes(Performance* aPerformance);
|
|
|
|
DOMHighResTimeStamp DomainLookupStartHighRes(Performance* aPerformance);
|
|
|
|
DOMHighResTimeStamp DomainLookupEndHighRes(Performance* aPerformance);
|
|
|
|
DOMHighResTimeStamp ConnectStartHighRes(Performance* aPerformance);
|
|
|
|
DOMHighResTimeStamp SecureConnectionStartHighRes(Performance* aPerformance);
|
|
|
|
DOMHighResTimeStamp ConnectEndHighRes(Performance* aPerformance);
|
|
|
|
DOMHighResTimeStamp RequestStartHighRes(Performance* aPerformance);
|
|
|
|
DOMHighResTimeStamp ResponseStartHighRes(Performance* aPerformance);
|
|
|
|
DOMHighResTimeStamp ResponseEndHighRes(Performance* aPerformance);
|
|
|
|
|
|
|
|
DOMHighResTimeStamp ZeroTime() const { return mZeroTime; }
|
|
|
|
|
|
|
|
uint8_t RedirectCountReal() const { return mRedirectCount; }
|
|
|
|
uint8_t GetRedirectCount() const;
|
|
|
|
|
|
|
|
bool AllRedirectsSameOrigin() const { return mAllRedirectsSameOrigin; }
|
|
|
|
|
|
|
|
// If this is false the values of redirectStart/End will be 0 This is false if
|
|
|
|
// no redirects occured, or if any of the responses failed the
|
|
|
|
// timing-allow-origin check in HttpBaseChannel::TimingAllowCheck
|
|
|
|
bool ShouldReportCrossOriginRedirect() const;
|
|
|
|
|
|
|
|
// Cached result of CheckAllowedOrigin. If false, security sensitive
|
|
|
|
// attributes of the resourceTiming object will be set to 0
|
|
|
|
bool TimingAllowed() const { return mTimingAllowed; }
|
|
|
|
|
2018-04-24 14:04:12 +03:00
|
|
|
nsTArray<nsCOMPtr<nsIServerTiming>> GetServerTiming();
|
2018-01-10 06:01:00 +03:00
|
|
|
|
2018-01-24 19:17:31 +03:00
|
|
|
private:
|
|
|
|
// Checks if the resource is either same origin as the page that started
|
|
|
|
// the load, or if the response contains the Timing-Allow-Origin header
|
|
|
|
// with a value of * or matching the domain of the loading Principal
|
|
|
|
bool CheckAllowedOrigin(nsIHttpChannel* aResourceChannel,
|
|
|
|
nsITimedChannel* aChannel);
|
|
|
|
|
2018-04-24 14:04:12 +03:00
|
|
|
nsTArray<nsCOMPtr<nsIServerTiming>> mServerTiming;
|
2018-01-24 19:17:31 +03:00
|
|
|
nsString mNextHopProtocol;
|
|
|
|
|
|
|
|
TimeStamp mAsyncOpen;
|
|
|
|
TimeStamp mRedirectStart;
|
|
|
|
TimeStamp mRedirectEnd;
|
|
|
|
TimeStamp mDomainLookupStart;
|
|
|
|
TimeStamp mDomainLookupEnd;
|
|
|
|
TimeStamp mConnectStart;
|
|
|
|
TimeStamp mSecureConnectionStart;
|
|
|
|
TimeStamp mConnectEnd;
|
|
|
|
TimeStamp mRequestStart;
|
|
|
|
TimeStamp mResponseStart;
|
|
|
|
TimeStamp mCacheReadStart;
|
|
|
|
TimeStamp mResponseEnd;
|
|
|
|
TimeStamp mCacheReadEnd;
|
|
|
|
|
|
|
|
// ServiceWorker interception timing information
|
|
|
|
TimeStamp mWorkerStart;
|
|
|
|
TimeStamp mWorkerRequestStart;
|
|
|
|
TimeStamp mWorkerResponseEnd;
|
|
|
|
|
|
|
|
// This is an offset that will be added to each timing ([ms] resolution).
|
|
|
|
// There are only 2 possible values: (1) logicaly equal to navigationStart
|
|
|
|
// TimeStamp (results are absolute timstamps - wallclock); (2) "0" (results
|
|
|
|
// are relative to the navigation start).
|
|
|
|
DOMHighResTimeStamp mZeroTime;
|
|
|
|
|
|
|
|
DOMHighResTimeStamp mFetchStart;
|
|
|
|
|
|
|
|
uint64_t mEncodedBodySize;
|
|
|
|
uint64_t mTransferSize;
|
|
|
|
uint64_t mDecodedBodySize;
|
|
|
|
|
|
|
|
uint8_t mRedirectCount;
|
|
|
|
|
|
|
|
bool mAllRedirectsSameOrigin;
|
|
|
|
|
|
|
|
// If the resourceTiming object should have non-zero redirectStart and
|
|
|
|
// redirectEnd attributes. It is false if there were no redirects, or if any
|
|
|
|
// of the responses didn't pass the timing-allow-check
|
|
|
|
bool mReportCrossOriginRedirect;
|
|
|
|
|
|
|
|
bool mSecureConnection;
|
|
|
|
|
|
|
|
bool mTimingAllowed;
|
|
|
|
|
|
|
|
bool mInitialized;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Script "performance.timing" object
|
|
|
|
class PerformanceTiming final : public nsWrapperCache {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @param aPerformance
|
|
|
|
* The performance object (the JS parent).
|
|
|
|
* This will allow access to "window.performance.timing" attribute
|
|
|
|
* for the navigation timing (can't be null).
|
|
|
|
* @param aChannel
|
|
|
|
* An nsITimedChannel used to gather all the networking timings by
|
|
|
|
* both the navigation timing and the resource timing (can't be null).
|
|
|
|
* @param aHttpChannel
|
|
|
|
* An nsIHttpChannel (the resource's http channel).
|
|
|
|
* This will be used by the resource timing cross-domain check
|
|
|
|
* algorithm.
|
|
|
|
* Argument is null for the navigation timing (navigation timing uses
|
|
|
|
* another algorithm for the cross-domain redirects).
|
|
|
|
* @param aZeroTime
|
|
|
|
* The offset that will be added to the timestamp of each event. This
|
|
|
|
* argument should be equal to performance.navigationStart for
|
|
|
|
* navigation timing and "0" for the resource timing.
|
|
|
|
*/
|
|
|
|
PerformanceTiming(Performance* aPerformance, nsITimedChannel* aChannel,
|
|
|
|
nsIHttpChannel* aHttpChannel,
|
|
|
|
DOMHighResTimeStamp aZeroTime);
|
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(PerformanceTiming)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(PerformanceTiming)
|
|
|
|
|
|
|
|
nsDOMNavigationTiming* GetDOMTiming() const {
|
|
|
|
return mPerformance->GetDOMTiming();
|
|
|
|
}
|
|
|
|
|
|
|
|
Performance* GetParentObject() const { return mPerformance; }
|
|
|
|
|
2016-06-09 13:43:56 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* cx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
|
|
|
// PerformanceNavigation WebIDL methods
|
|
|
|
DOMTimeMilliSec NavigationStart() const {
|
2019-05-02 00:06:59 +03:00
|
|
|
if (!StaticPrefs::dom_enable_performance() ||
|
2017-06-15 11:48:27 +03:00
|
|
|
nsContentUtils::ShouldResistFingerprinting()) {
|
2016-06-09 13:43:56 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2018-03-09 18:29:33 +03:00
|
|
|
if (mPerformance->IsSystemPrincipal()) {
|
|
|
|
return GetDOMTiming()->GetNavigationStart();
|
|
|
|
}
|
2018-01-11 00:51:23 +03:00
|
|
|
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
2018-03-13 20:36:34 +03:00
|
|
|
GetDOMTiming()->GetNavigationStart(),
|
|
|
|
mPerformance->GetRandomTimelineSeed());
|
2016-06-09 13:43:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
DOMTimeMilliSec UnloadEventStart() {
|
2019-05-02 00:06:59 +03:00
|
|
|
if (!StaticPrefs::dom_enable_performance() ||
|
2017-06-15 11:48:27 +03:00
|
|
|
nsContentUtils::ShouldResistFingerprinting()) {
|
2016-06-09 13:43:56 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2018-03-09 18:29:33 +03:00
|
|
|
if (mPerformance->IsSystemPrincipal()) {
|
|
|
|
return GetDOMTiming()->GetUnloadEventStart();
|
|
|
|
}
|
2018-01-11 00:51:23 +03:00
|
|
|
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
2018-03-13 20:36:34 +03:00
|
|
|
GetDOMTiming()->GetUnloadEventStart(),
|
|
|
|
mPerformance->GetRandomTimelineSeed());
|
2016-06-09 13:43:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
DOMTimeMilliSec UnloadEventEnd() {
|
2019-05-02 00:06:59 +03:00
|
|
|
if (!StaticPrefs::dom_enable_performance() ||
|
2017-06-15 11:48:27 +03:00
|
|
|
nsContentUtils::ShouldResistFingerprinting()) {
|
2016-06-09 13:43:56 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2018-03-09 18:29:33 +03:00
|
|
|
if (mPerformance->IsSystemPrincipal()) {
|
|
|
|
return GetDOMTiming()->GetUnloadEventEnd();
|
|
|
|
}
|
2018-01-11 00:51:23 +03:00
|
|
|
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
2018-03-13 20:36:34 +03:00
|
|
|
GetDOMTiming()->GetUnloadEventEnd(),
|
|
|
|
mPerformance->GetRandomTimelineSeed());
|
2016-06-09 13:43:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Low resolution (used by navigation timing)
|
|
|
|
DOMTimeMilliSec FetchStart();
|
|
|
|
DOMTimeMilliSec RedirectStart();
|
|
|
|
DOMTimeMilliSec RedirectEnd();
|
|
|
|
DOMTimeMilliSec DomainLookupStart();
|
|
|
|
DOMTimeMilliSec DomainLookupEnd();
|
|
|
|
DOMTimeMilliSec ConnectStart();
|
2017-07-10 22:01:35 +03:00
|
|
|
DOMTimeMilliSec SecureConnectionStart();
|
2016-06-09 13:43:56 +03:00
|
|
|
DOMTimeMilliSec ConnectEnd();
|
|
|
|
DOMTimeMilliSec RequestStart();
|
|
|
|
DOMTimeMilliSec ResponseStart();
|
|
|
|
DOMTimeMilliSec ResponseEnd();
|
|
|
|
|
|
|
|
DOMTimeMilliSec DomLoading() {
|
2019-05-02 00:06:59 +03:00
|
|
|
if (!StaticPrefs::dom_enable_performance() ||
|
2017-06-15 11:48:27 +03:00
|
|
|
nsContentUtils::ShouldResistFingerprinting()) {
|
2016-06-09 13:43:56 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2018-03-09 18:29:33 +03:00
|
|
|
if (mPerformance->IsSystemPrincipal()) {
|
|
|
|
return GetDOMTiming()->GetDomLoading();
|
|
|
|
}
|
2018-01-11 00:51:23 +03:00
|
|
|
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
2018-03-13 20:36:34 +03:00
|
|
|
GetDOMTiming()->GetDomLoading(), mPerformance->GetRandomTimelineSeed());
|
2016-06-09 13:43:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
DOMTimeMilliSec DomInteractive() const {
|
2019-05-02 00:06:59 +03:00
|
|
|
if (!StaticPrefs::dom_enable_performance() ||
|
2017-06-15 11:48:27 +03:00
|
|
|
nsContentUtils::ShouldResistFingerprinting()) {
|
2016-06-09 13:43:56 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2018-03-09 18:29:33 +03:00
|
|
|
if (mPerformance->IsSystemPrincipal()) {
|
|
|
|
return GetDOMTiming()->GetDomInteractive();
|
|
|
|
}
|
2018-01-11 00:51:23 +03:00
|
|
|
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
2018-03-13 20:36:34 +03:00
|
|
|
GetDOMTiming()->GetDomInteractive(),
|
|
|
|
mPerformance->GetRandomTimelineSeed());
|
2016-06-09 13:43:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
DOMTimeMilliSec DomContentLoadedEventStart() const {
|
2019-05-02 00:06:59 +03:00
|
|
|
if (!StaticPrefs::dom_enable_performance() ||
|
2017-06-15 11:48:27 +03:00
|
|
|
nsContentUtils::ShouldResistFingerprinting()) {
|
2016-06-09 13:43:56 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2018-03-09 18:29:33 +03:00
|
|
|
if (mPerformance->IsSystemPrincipal()) {
|
|
|
|
return GetDOMTiming()->GetDomContentLoadedEventStart();
|
|
|
|
}
|
2018-01-11 00:51:23 +03:00
|
|
|
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
2018-03-13 20:36:34 +03:00
|
|
|
GetDOMTiming()->GetDomContentLoadedEventStart(),
|
|
|
|
mPerformance->GetRandomTimelineSeed());
|
2016-06-09 13:43:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
DOMTimeMilliSec DomContentLoadedEventEnd() const {
|
2019-05-02 00:06:59 +03:00
|
|
|
if (!StaticPrefs::dom_enable_performance() ||
|
2017-06-15 11:48:27 +03:00
|
|
|
nsContentUtils::ShouldResistFingerprinting()) {
|
2016-06-09 13:43:56 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2018-03-09 18:29:33 +03:00
|
|
|
if (mPerformance->IsSystemPrincipal()) {
|
|
|
|
return GetDOMTiming()->GetDomContentLoadedEventEnd();
|
|
|
|
}
|
2018-01-11 00:51:23 +03:00
|
|
|
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
2018-03-13 20:36:34 +03:00
|
|
|
GetDOMTiming()->GetDomContentLoadedEventEnd(),
|
|
|
|
mPerformance->GetRandomTimelineSeed());
|
2016-06-09 13:43:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
DOMTimeMilliSec DomComplete() const {
|
2019-05-02 00:06:59 +03:00
|
|
|
if (!StaticPrefs::dom_enable_performance() ||
|
2017-06-15 11:48:27 +03:00
|
|
|
nsContentUtils::ShouldResistFingerprinting()) {
|
2016-06-09 13:43:56 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2018-03-09 18:29:33 +03:00
|
|
|
if (mPerformance->IsSystemPrincipal()) {
|
|
|
|
return GetDOMTiming()->GetDomComplete();
|
|
|
|
}
|
2018-01-11 00:51:23 +03:00
|
|
|
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
2018-03-13 20:36:34 +03:00
|
|
|
GetDOMTiming()->GetDomComplete(),
|
|
|
|
mPerformance->GetRandomTimelineSeed());
|
2016-06-09 13:43:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
DOMTimeMilliSec LoadEventStart() const {
|
2019-05-02 00:06:59 +03:00
|
|
|
if (!StaticPrefs::dom_enable_performance() ||
|
2017-06-15 11:48:27 +03:00
|
|
|
nsContentUtils::ShouldResistFingerprinting()) {
|
2016-06-09 13:43:56 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2018-03-09 18:29:33 +03:00
|
|
|
if (mPerformance->IsSystemPrincipal()) {
|
|
|
|
return GetDOMTiming()->GetLoadEventStart();
|
|
|
|
}
|
2018-01-11 00:51:23 +03:00
|
|
|
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
2018-03-13 20:36:34 +03:00
|
|
|
GetDOMTiming()->GetLoadEventStart(),
|
|
|
|
mPerformance->GetRandomTimelineSeed());
|
2016-06-09 13:43:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
DOMTimeMilliSec LoadEventEnd() const {
|
2019-05-02 00:06:59 +03:00
|
|
|
if (!StaticPrefs::dom_enable_performance() ||
|
2017-06-15 11:48:27 +03:00
|
|
|
nsContentUtils::ShouldResistFingerprinting()) {
|
2016-06-09 13:43:56 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2018-03-09 18:29:33 +03:00
|
|
|
if (mPerformance->IsSystemPrincipal()) {
|
|
|
|
return GetDOMTiming()->GetLoadEventEnd();
|
|
|
|
}
|
2018-01-11 00:51:23 +03:00
|
|
|
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
2018-03-13 20:36:34 +03:00
|
|
|
GetDOMTiming()->GetLoadEventEnd(),
|
|
|
|
mPerformance->GetRandomTimelineSeed());
|
2016-06-09 13:43:56 +03:00
|
|
|
}
|
|
|
|
|
2017-07-06 02:51:50 +03:00
|
|
|
DOMTimeMilliSec TimeToNonBlankPaint() const {
|
2019-05-02 00:06:59 +03:00
|
|
|
if (!StaticPrefs::dom_enable_performance() ||
|
2017-07-06 02:51:50 +03:00
|
|
|
nsContentUtils::ShouldResistFingerprinting()) {
|
|
|
|
return 0;
|
|
|
|
}
|
2018-03-09 18:29:33 +03:00
|
|
|
if (mPerformance->IsSystemPrincipal()) {
|
|
|
|
return GetDOMTiming()->GetTimeToNonBlankPaint();
|
|
|
|
}
|
2018-01-11 00:51:23 +03:00
|
|
|
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
2018-03-13 20:36:34 +03:00
|
|
|
GetDOMTiming()->GetTimeToNonBlankPaint(),
|
|
|
|
mPerformance->GetRandomTimelineSeed());
|
2017-07-06 02:51:50 +03:00
|
|
|
}
|
|
|
|
|
2018-10-18 23:16:45 +03:00
|
|
|
DOMTimeMilliSec TimeToContentfulPaint() const {
|
2019-05-02 00:06:59 +03:00
|
|
|
if (!StaticPrefs::dom_enable_performance() ||
|
2018-10-18 23:16:45 +03:00
|
|
|
nsContentUtils::ShouldResistFingerprinting()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (mPerformance->IsSystemPrincipal()) {
|
|
|
|
return GetDOMTiming()->GetTimeToContentfulPaint();
|
|
|
|
}
|
|
|
|
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
|
|
|
GetDOMTiming()->GetTimeToContentfulPaint(),
|
|
|
|
mPerformance->GetRandomTimelineSeed());
|
|
|
|
}
|
|
|
|
|
2018-04-27 01:36:52 +03:00
|
|
|
DOMTimeMilliSec TimeToDOMContentFlushed() const {
|
2019-05-02 00:06:59 +03:00
|
|
|
if (!StaticPrefs::dom_enable_performance() ||
|
2018-04-27 01:36:52 +03:00
|
|
|
nsContentUtils::ShouldResistFingerprinting()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (mPerformance->IsSystemPrincipal()) {
|
|
|
|
return GetDOMTiming()->GetTimeToDOMContentFlushed();
|
|
|
|
}
|
|
|
|
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
|
|
|
GetDOMTiming()->GetTimeToDOMContentFlushed(),
|
|
|
|
mPerformance->GetRandomTimelineSeed());
|
|
|
|
}
|
|
|
|
|
2018-10-11 20:23:28 +03:00
|
|
|
DOMTimeMilliSec TimeToFirstInteractive() const {
|
2019-05-02 00:06:59 +03:00
|
|
|
if (!StaticPrefs::dom_enable_performance() ||
|
2018-10-11 20:23:28 +03:00
|
|
|
nsContentUtils::ShouldResistFingerprinting()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (mPerformance->IsSystemPrincipal()) {
|
|
|
|
return GetDOMTiming()->GetTimeToTTFI();
|
|
|
|
}
|
|
|
|
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
|
|
|
GetDOMTiming()->GetTimeToTTFI(), mPerformance->GetRandomTimelineSeed());
|
|
|
|
}
|
|
|
|
|
2018-01-24 19:17:31 +03:00
|
|
|
PerformanceTimingData* Data() const { return mTimingData.get(); }
|
|
|
|
|
2016-06-09 13:43:56 +03:00
|
|
|
private:
|
|
|
|
~PerformanceTiming();
|
|
|
|
|
2017-04-19 09:00:00 +03:00
|
|
|
bool IsTopLevelContentDocument() const;
|
|
|
|
|
2016-06-09 20:04:42 +03:00
|
|
|
RefPtr<Performance> mPerformance;
|
2016-06-09 13:43:56 +03:00
|
|
|
|
2018-01-24 19:17:31 +03:00
|
|
|
UniquePtr<PerformanceTimingData> mTimingData;
|
2016-06-09 13:43:56 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_PerformanceTiming_h
|