зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1443943 Port the performance APIs only to only clamping/jittering on non-System Principal r=baku
MozReview-Commit-ID: FKYLI5Yc1kX --HG-- extra : rebase_source : a50952a233eff12c523bb9d9006d3143fa744005
This commit is contained in:
Родитель
2a02bb226b
Коммит
ba0e15150d
|
@ -2366,7 +2366,7 @@ nsPIDOMWindowInner::CreatePerformanceObjectIfNeeded()
|
|||
timedChannel = nullptr;
|
||||
}
|
||||
if (timing) {
|
||||
mPerformance = Performance::CreateForMainThread(this, timing, timedChannel);
|
||||
mPerformance = Performance::CreateForMainThread(this, mDoc->NodePrincipal(), timing, timedChannel);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1862,6 +1862,7 @@ nsGlobalWindowOuter::SetNewDocument(nsIDocument* aDocument,
|
|||
if (currentInner->mPerformance) {
|
||||
newInnerWindow->mPerformance =
|
||||
Performance::CreateForMainThread(newInnerWindow->AsInner(),
|
||||
aDocument->NodePrincipal(),
|
||||
currentInner->mPerformance->GetDOMTiming(),
|
||||
currentInner->mPerformance->GetChannel());
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ NS_IMPL_RELEASE_INHERITED(Performance, DOMEventTargetHelper)
|
|||
|
||||
/* static */ already_AddRefed<Performance>
|
||||
Performance::CreateForMainThread(nsPIDOMWindowInner* aWindow,
|
||||
nsIPrincipal* aPrincipal,
|
||||
nsDOMNavigationTiming* aDOMTiming,
|
||||
nsITimedChannel* aChannel)
|
||||
{
|
||||
|
@ -56,6 +57,7 @@ Performance::CreateForMainThread(nsPIDOMWindowInner* aWindow,
|
|||
|
||||
RefPtr<Performance> performance =
|
||||
new PerformanceMainThread(aWindow, aDOMTiming, aChannel);
|
||||
performance->mSystemPrincipal = nsContentUtils::IsSystemPrincipal(aPrincipal);
|
||||
return performance.forget();
|
||||
}
|
||||
|
||||
|
@ -66,6 +68,7 @@ Performance::CreateForWorker(WorkerPrivate* aWorkerPrivate)
|
|||
aWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
RefPtr<Performance> performance = new PerformanceWorker(aWorkerPrivate);
|
||||
performance->mSystemPrincipal = aWorkerPrivate->UsesSystemPrincipal();
|
||||
return performance.forget();
|
||||
}
|
||||
|
||||
|
@ -91,7 +94,14 @@ DOMHighResTimeStamp
|
|||
Performance::Now() const
|
||||
{
|
||||
TimeDuration duration = TimeStamp::Now() - CreationTimeStamp();
|
||||
return RoundTime(duration.ToMilliseconds());
|
||||
DOMHighResTimeStamp rawTime = duration.ToMilliseconds();
|
||||
if (mSystemPrincipal) {
|
||||
return rawTime;
|
||||
}
|
||||
|
||||
const double maxResolutionMs = 0.020;
|
||||
DOMHighResTimeStamp minimallyClamped = floor(rawTime / maxResolutionMs) * maxResolutionMs;
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(minimallyClamped);
|
||||
}
|
||||
|
||||
DOMHighResTimeStamp
|
||||
|
@ -102,8 +112,12 @@ Performance::TimeOrigin()
|
|||
}
|
||||
|
||||
MOZ_ASSERT(mPerformanceService);
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
mPerformanceService->TimeOrigin(CreationTimeStamp()));
|
||||
DOMHighResTimeStamp rawTimeOrigin = mPerformanceService->TimeOrigin(CreationTimeStamp());
|
||||
if (mSystemPrincipal) {
|
||||
return rawTimeOrigin;
|
||||
}
|
||||
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(rawTimeOrigin);
|
||||
}
|
||||
|
||||
JSObject*
|
||||
|
@ -206,17 +220,6 @@ Performance::ClearResourceTimings()
|
|||
mResourceEntries.Clear();
|
||||
}
|
||||
|
||||
DOMHighResTimeStamp
|
||||
Performance::RoundTime(double aTime) const
|
||||
{
|
||||
// Round down to the nearest 20us, because if the timer is too accurate people
|
||||
// can do nasty timing attacks with it.
|
||||
const double maxResolutionMs = 0.020;
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
floor(aTime / maxResolutionMs) * maxResolutionMs);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Performance::Mark(const nsAString& aName, ErrorResult& aRv)
|
||||
{
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
|
||||
static already_AddRefed<Performance>
|
||||
CreateForMainThread(nsPIDOMWindowInner* aWindow,
|
||||
nsIPrincipal* aPrincipal,
|
||||
nsDOMNavigationTiming* aDOMTiming,
|
||||
nsITimedChannel* aChannel);
|
||||
|
||||
|
@ -100,6 +101,11 @@ public:
|
|||
|
||||
virtual TimeStamp CreationTimeStamp() const = 0;
|
||||
|
||||
uint64_t IsSystemPrincipal()
|
||||
{
|
||||
return mSystemPrincipal;
|
||||
}
|
||||
|
||||
void MemoryPressure();
|
||||
|
||||
size_t SizeOfUserEntries(mozilla::MallocSizeOf aMallocSizeOf) const;
|
||||
|
@ -143,8 +149,6 @@ protected:
|
|||
void RunNotificationObserversTask();
|
||||
void QueueEntry(PerformanceEntry* aEntry);
|
||||
|
||||
DOMHighResTimeStamp RoundTime(double aTime) const;
|
||||
|
||||
nsTObserverArray<PerformanceObserver*> mObservers;
|
||||
|
||||
protected:
|
||||
|
@ -159,6 +163,8 @@ protected:
|
|||
bool mPendingNotificationObserversTask;
|
||||
|
||||
RefPtr<PerformanceService> mPerformanceService;
|
||||
|
||||
bool mSystemPrincipal;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
@ -39,7 +39,11 @@ public:
|
|||
|
||||
DOMHighResTimeStamp Duration() const override
|
||||
{
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(LoadEventEnd() - StartTime());
|
||||
DOMHighResTimeStamp rawDuration = LoadEventEnd() - StartTime();
|
||||
if (mPerformance->IsSystemPrincipal()) {
|
||||
return rawDuration;
|
||||
}
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(rawDuration);
|
||||
}
|
||||
|
||||
DOMHighResTimeStamp StartTime() const override
|
||||
|
|
|
@ -81,7 +81,9 @@ PerformanceTiming::PerformanceTiming(Performance* aPerformance,
|
|||
MOZ_ASSERT(aPerformance, "Parent performance object should be provided");
|
||||
|
||||
mTimingData.reset(new PerformanceTimingData(aChannel, aHttpChannel,
|
||||
aZeroTime));
|
||||
aPerformance->IsSystemPrincipal()
|
||||
? aZeroTime
|
||||
: nsRFPService::ReduceTimePrecisionAsMSecs(aZeroTime)));
|
||||
|
||||
// Non-null aHttpChannel implies that this PerformanceTiming object is being
|
||||
// used for subresources, which is irrelevant to this probe.
|
||||
|
@ -112,8 +114,8 @@ PerformanceTimingData::PerformanceTimingData(nsITimedChannel* aChannel,
|
|||
, mInitialized(false)
|
||||
{
|
||||
mInitialized = !!aChannel;
|
||||
mZeroTime = aZeroTime;
|
||||
|
||||
mZeroTime = nsRFPService::ReduceTimePrecisionAsMSecs(aZeroTime);
|
||||
if (!nsContentUtils::IsPerformanceTimingEnabled() ||
|
||||
nsContentUtils::ShouldResistFingerprinting()) {
|
||||
mZeroTime = 0;
|
||||
|
@ -252,6 +254,9 @@ PerformanceTimingData::FetchStartHighRes(Performance* aPerformance)
|
|||
}
|
||||
}
|
||||
}
|
||||
if (aPerformance->IsSystemPrincipal()) {
|
||||
return mFetchStart;
|
||||
}
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(mFetchStart);
|
||||
}
|
||||
|
||||
|
@ -327,8 +332,11 @@ PerformanceTimingData::AsyncOpenHighRes(Performance* aPerformance)
|
|||
nsContentUtils::ShouldResistFingerprinting() || mAsyncOpen.IsNull()) {
|
||||
return mZeroTime;
|
||||
}
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
TimeStampToDOMHighRes(aPerformance, mAsyncOpen));
|
||||
DOMHighResTimeStamp rawValue = TimeStampToDOMHighRes(aPerformance, mAsyncOpen);
|
||||
if (aPerformance->IsSystemPrincipal()) {
|
||||
return rawValue;
|
||||
}
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(rawValue);
|
||||
}
|
||||
|
||||
DOMHighResTimeStamp
|
||||
|
@ -340,8 +348,11 @@ PerformanceTimingData::WorkerStartHighRes(Performance* aPerformance)
|
|||
nsContentUtils::ShouldResistFingerprinting() || mWorkerStart.IsNull()) {
|
||||
return mZeroTime;
|
||||
}
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
TimeStampToDOMHighRes(aPerformance, mWorkerStart));
|
||||
DOMHighResTimeStamp rawValue = TimeStampToDOMHighRes(aPerformance, mWorkerStart);
|
||||
if (aPerformance->IsSystemPrincipal()) {
|
||||
return rawValue;
|
||||
}
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(rawValue);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -447,10 +458,14 @@ PerformanceTimingData::DomainLookupEndHighRes(Performance* aPerformance)
|
|||
return mZeroTime;
|
||||
}
|
||||
// Bug 1155008 - nsHttpTransaction is racy. Return DomainLookupStart when null
|
||||
return mDomainLookupEnd.IsNull()
|
||||
? DomainLookupStartHighRes(aPerformance)
|
||||
: nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
TimeStampToDOMHighRes(aPerformance, mDomainLookupEnd));
|
||||
if (mDomainLookupEnd.IsNull()) {
|
||||
return DomainLookupStartHighRes(aPerformance);
|
||||
}
|
||||
DOMHighResTimeStamp rawValue = TimeStampToDOMHighRes(aPerformance, mDomainLookupEnd);
|
||||
if (aPerformance->IsSystemPrincipal()) {
|
||||
return rawValue;
|
||||
}
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(rawValue);
|
||||
}
|
||||
|
||||
DOMTimeMilliSec
|
||||
|
@ -468,10 +483,14 @@ PerformanceTimingData::ConnectStartHighRes(Performance* aPerformance)
|
|||
nsContentUtils::ShouldResistFingerprinting()) {
|
||||
return mZeroTime;
|
||||
}
|
||||
return mConnectStart.IsNull()
|
||||
? DomainLookupEndHighRes(aPerformance)
|
||||
: nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
TimeStampToDOMHighRes(aPerformance, mConnectStart));
|
||||
if (mConnectStart.IsNull()) {
|
||||
return DomainLookupEndHighRes(aPerformance);
|
||||
}
|
||||
DOMHighResTimeStamp rawValue = TimeStampToDOMHighRes(aPerformance, mConnectStart);
|
||||
if (aPerformance->IsSystemPrincipal()) {
|
||||
return rawValue;
|
||||
}
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(rawValue);
|
||||
}
|
||||
|
||||
DOMTimeMilliSec
|
||||
|
@ -489,13 +508,18 @@ PerformanceTimingData::SecureConnectionStartHighRes(Performance* aPerformance)
|
|||
nsContentUtils::ShouldResistFingerprinting()) {
|
||||
return mZeroTime;
|
||||
}
|
||||
return !mSecureConnection
|
||||
? 0 // We use 0 here, because mZeroTime is sometimes set to the navigation
|
||||
if (!mSecureConnection) {
|
||||
return 0; // We use 0 here, because mZeroTime is sometimes set to the navigation
|
||||
// start time.
|
||||
: (mSecureConnectionStart.IsNull()
|
||||
? mZeroTime
|
||||
: nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
TimeStampToDOMHighRes(aPerformance, mSecureConnectionStart)));
|
||||
}
|
||||
if (mSecureConnectionStart.IsNull()) {
|
||||
return mZeroTime;
|
||||
}
|
||||
DOMHighResTimeStamp rawValue = TimeStampToDOMHighRes(aPerformance, mSecureConnectionStart);
|
||||
if (aPerformance->IsSystemPrincipal()) {
|
||||
return rawValue;
|
||||
}
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(rawValue);
|
||||
}
|
||||
|
||||
DOMTimeMilliSec
|
||||
|
@ -514,10 +538,14 @@ PerformanceTimingData::ConnectEndHighRes(Performance* aPerformance)
|
|||
return mZeroTime;
|
||||
}
|
||||
// Bug 1155008 - nsHttpTransaction is racy. Return ConnectStart when null
|
||||
return mConnectEnd.IsNull()
|
||||
? ConnectStartHighRes(aPerformance)
|
||||
: nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
TimeStampToDOMHighRes(aPerformance, mConnectEnd));
|
||||
if (mConnectEnd.IsNull()) {
|
||||
return ConnectStartHighRes(aPerformance);
|
||||
}
|
||||
DOMHighResTimeStamp rawValue = TimeStampToDOMHighRes(aPerformance, mConnectEnd);
|
||||
if (aPerformance->IsSystemPrincipal()) {
|
||||
return rawValue;
|
||||
}
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(rawValue);
|
||||
}
|
||||
|
||||
DOMTimeMilliSec
|
||||
|
@ -593,10 +621,14 @@ PerformanceTimingData::ResponseEndHighRes(Performance* aPerformance)
|
|||
mResponseEnd = mWorkerResponseEnd;
|
||||
}
|
||||
// Bug 1155008 - nsHttpTransaction is racy. Return ResponseStart when null
|
||||
return mResponseEnd.IsNull()
|
||||
? ResponseStartHighRes(aPerformance)
|
||||
: nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
TimeStampToDOMHighRes(aPerformance, mResponseEnd));
|
||||
if (mResponseEnd.IsNull()) {
|
||||
return ResponseStartHighRes(aPerformance);
|
||||
}
|
||||
DOMHighResTimeStamp rawValue = TimeStampToDOMHighRes(aPerformance, mResponseEnd);
|
||||
if (aPerformance->IsSystemPrincipal()) {
|
||||
return rawValue;
|
||||
}
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(rawValue);
|
||||
}
|
||||
|
||||
DOMTimeMilliSec
|
||||
|
|
|
@ -82,10 +82,16 @@ public:
|
|||
{
|
||||
MOZ_ASSERT(aPerformance);
|
||||
|
||||
return (!aStamp.IsNull())
|
||||
? nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
TimeStampToDOMHighRes(aPerformance, aStamp))
|
||||
: FetchStartHighRes(aPerformance);
|
||||
if(aStamp.IsNull()) {
|
||||
return FetchStartHighRes(aPerformance);
|
||||
}
|
||||
|
||||
DOMHighResTimeStamp rawTimestamp = TimeStampToDOMHighRes(aPerformance, aStamp);
|
||||
if (aPerformance->IsSystemPrincipal()) {
|
||||
return rawTimestamp;
|
||||
}
|
||||
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(rawTimestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -268,6 +274,9 @@ public:
|
|||
nsContentUtils::ShouldResistFingerprinting()) {
|
||||
return 0;
|
||||
}
|
||||
if (mPerformance->IsSystemPrincipal()) {
|
||||
return GetDOMTiming()->GetNavigationStart();
|
||||
}
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
GetDOMTiming()->GetNavigationStart());
|
||||
}
|
||||
|
@ -278,6 +287,9 @@ public:
|
|||
nsContentUtils::ShouldResistFingerprinting()) {
|
||||
return 0;
|
||||
}
|
||||
if (mPerformance->IsSystemPrincipal()) {
|
||||
return GetDOMTiming()->GetUnloadEventStart();
|
||||
}
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
GetDOMTiming()->GetUnloadEventStart());
|
||||
}
|
||||
|
@ -288,6 +300,9 @@ public:
|
|||
nsContentUtils::ShouldResistFingerprinting()) {
|
||||
return 0;
|
||||
}
|
||||
if (mPerformance->IsSystemPrincipal()) {
|
||||
return GetDOMTiming()->GetUnloadEventEnd();
|
||||
}
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
GetDOMTiming()->GetUnloadEventEnd());
|
||||
}
|
||||
|
@ -311,6 +326,9 @@ public:
|
|||
nsContentUtils::ShouldResistFingerprinting()) {
|
||||
return 0;
|
||||
}
|
||||
if (mPerformance->IsSystemPrincipal()) {
|
||||
return GetDOMTiming()->GetDomLoading();
|
||||
}
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
GetDOMTiming()->GetDomLoading());
|
||||
}
|
||||
|
@ -321,6 +339,9 @@ public:
|
|||
nsContentUtils::ShouldResistFingerprinting()) {
|
||||
return 0;
|
||||
}
|
||||
if (mPerformance->IsSystemPrincipal()) {
|
||||
return GetDOMTiming()->GetDomInteractive();
|
||||
}
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
GetDOMTiming()->GetDomInteractive());
|
||||
}
|
||||
|
@ -331,6 +352,9 @@ public:
|
|||
nsContentUtils::ShouldResistFingerprinting()) {
|
||||
return 0;
|
||||
}
|
||||
if (mPerformance->IsSystemPrincipal()) {
|
||||
return GetDOMTiming()->GetDomContentLoadedEventStart();
|
||||
}
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
GetDOMTiming()->GetDomContentLoadedEventStart());
|
||||
}
|
||||
|
@ -341,6 +365,9 @@ public:
|
|||
nsContentUtils::ShouldResistFingerprinting()) {
|
||||
return 0;
|
||||
}
|
||||
if (mPerformance->IsSystemPrincipal()) {
|
||||
return GetDOMTiming()->GetDomContentLoadedEventEnd();
|
||||
}
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
GetDOMTiming()->GetDomContentLoadedEventEnd());
|
||||
}
|
||||
|
@ -351,6 +378,9 @@ public:
|
|||
nsContentUtils::ShouldResistFingerprinting()) {
|
||||
return 0;
|
||||
}
|
||||
if (mPerformance->IsSystemPrincipal()) {
|
||||
return GetDOMTiming()->GetDomComplete();
|
||||
}
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
GetDOMTiming()->GetDomComplete());
|
||||
}
|
||||
|
@ -361,6 +391,9 @@ public:
|
|||
nsContentUtils::ShouldResistFingerprinting()) {
|
||||
return 0;
|
||||
}
|
||||
if (mPerformance->IsSystemPrincipal()) {
|
||||
return GetDOMTiming()->GetLoadEventStart();
|
||||
}
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
GetDOMTiming()->GetLoadEventStart());
|
||||
}
|
||||
|
@ -371,6 +404,9 @@ public:
|
|||
nsContentUtils::ShouldResistFingerprinting()) {
|
||||
return 0;
|
||||
}
|
||||
if (mPerformance->IsSystemPrincipal()) {
|
||||
return GetDOMTiming()->GetLoadEventEnd();
|
||||
}
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
GetDOMTiming()->GetLoadEventEnd());
|
||||
}
|
||||
|
@ -381,6 +417,9 @@ public:
|
|||
nsContentUtils::ShouldResistFingerprinting()) {
|
||||
return 0;
|
||||
}
|
||||
if (mPerformance->IsSystemPrincipal()) {
|
||||
return GetDOMTiming()->GetTimeToNonBlankPaint();
|
||||
}
|
||||
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
||||
GetDOMTiming()->GetTimeToNonBlankPaint());
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче