diff options
author | Tom Ritter <tom@mozilla.com> | 2018-02-20 12:18:30 -0600 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-03-14 11:27:26 +0100 |
commit | a32b7f7c4e4e31669e0787e6321d74e4db71e514 (patch) | |
tree | e83acb2eb895162f010e7ff9ee2d39548c4d90b4 /dom/performance | |
parent | bd819cc43653220abdbfe040ba5c721e9861241c (diff) | |
download | uxp-a32b7f7c4e4e31669e0787e6321d74e4db71e514.tar.gz |
Bug 1430173 - Reduce the precision of all explicit clocks to 2ms. r=baku, a=RyanVM
Backport to ESR where we don't have the ResistFingerprinting component.
MozReview-Commit-ID: 9bjycHjR3SF
--HG--
extra : transplant_source : %EA%03%21%0A%E9%3F%8E%CD%7C%D79f%96%85%96%00%5D%7F%95X
Diffstat (limited to 'dom/performance')
-rwxr-xr-x[-rw-r--r--] | dom/performance/Performance.cpp | 5 | ||||
-rwxr-xr-x[-rw-r--r--] | dom/performance/PerformanceTiming.cpp | 22 | ||||
-rwxr-xr-x[-rw-r--r--] | dom/performance/PerformanceTiming.h | 25 |
3 files changed, 27 insertions, 25 deletions
diff --git a/dom/performance/Performance.cpp b/dom/performance/Performance.cpp index 17273c55df..8dc239b05b 100644..100755 --- a/dom/performance/Performance.cpp +++ b/dom/performance/Performance.cpp @@ -21,6 +21,7 @@ #include "mozilla/dom/PerformanceObserverBinding.h" #include "mozilla/IntegerPrintfMacros.h" #include "mozilla/Preferences.h" +#include "mozilla/TimerClamping.h" #include "WorkerPrivate.h" #include "WorkerRunnable.h" @@ -228,9 +229,9 @@ Performance::ClearResourceTimings() DOMHighResTimeStamp Performance::RoundTime(double aTime) const { - // Round down to the nearest 20us, because if the timer is too accurate people + // Round down to the nearest 2ms, because if the timer is too accurate people // can do nasty timing attacks with it. - const double maxResolutionMs = 0.020; + const double maxResolutionMs = 2; return floor(aTime / maxResolutionMs) * maxResolutionMs; } diff --git a/dom/performance/PerformanceTiming.cpp b/dom/performance/PerformanceTiming.cpp index 4070b6a0f9..97bbcb0ca7 100644..100755 --- a/dom/performance/PerformanceTiming.cpp +++ b/dom/performance/PerformanceTiming.cpp @@ -21,7 +21,7 @@ PerformanceTiming::PerformanceTiming(Performance* aPerformance, DOMHighResTimeStamp aZeroTime) : mPerformance(aPerformance), mFetchStart(0.0), - mZeroTime(aZeroTime), + mZeroTime(TimerClamping::ReduceMsTimeValue(aZeroTime)), mRedirectCount(0), mTimingAllowed(true), mAllRedirectsSameOrigin(true), @@ -117,7 +117,7 @@ PerformanceTiming::FetchStartHighRes() ? TimeStampToDOMHighRes(mAsyncOpen) : 0.0; } - return mFetchStart; + return TimerClamping::ReduceMsTimeValue(mFetchStart); } DOMTimeMilliSec @@ -203,7 +203,7 @@ PerformanceTiming::RedirectStartHighRes() if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) { return mZeroTime; } - return TimeStampToDOMHighResOrFetchStart(mRedirectStart); + return TimeStampToReducedDOMHighResOrFetchStart(mRedirectStart); } DOMTimeMilliSec @@ -236,7 +236,7 @@ PerformanceTiming::RedirectEndHighRes() if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) { return mZeroTime; } - return TimeStampToDOMHighResOrFetchStart(mRedirectEnd); + return TimeStampToReducedDOMHighResOrFetchStart(mRedirectEnd); } DOMTimeMilliSec @@ -259,7 +259,7 @@ PerformanceTiming::DomainLookupStartHighRes() if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) { return mZeroTime; } - return TimeStampToDOMHighResOrFetchStart(mDomainLookupStart); + return TimeStampToReducedDOMHighResOrFetchStart(mDomainLookupStart); } DOMTimeMilliSec @@ -276,7 +276,7 @@ PerformanceTiming::DomainLookupEndHighRes() } // Bug 1155008 - nsHttpTransaction is racy. Return DomainLookupStart when null return mDomainLookupEnd.IsNull() ? DomainLookupStartHighRes() - : TimeStampToDOMHighRes(mDomainLookupEnd); + : TimerClamping::ReduceMsTimeValue(TimeStampToDOMHighRes(mDomainLookupEnd)); } DOMTimeMilliSec @@ -292,7 +292,7 @@ PerformanceTiming::ConnectStartHighRes() return mZeroTime; } return mConnectStart.IsNull() ? DomainLookupEndHighRes() - : TimeStampToDOMHighRes(mConnectStart); + : TimerClamping::ReduceMsTimeValue(TimeStampToDOMHighRes(mConnectStart)); } DOMTimeMilliSec @@ -329,7 +329,7 @@ PerformanceTiming::ConnectEndHighRes() } // Bug 1155008 - nsHttpTransaction is racy. Return ConnectStart when null return mConnectEnd.IsNull() ? ConnectStartHighRes() - : TimeStampToDOMHighRes(mConnectEnd); + : TimerClamping::ReduceMsTimeValue(TimeStampToDOMHighRes(mConnectEnd)); } DOMTimeMilliSec @@ -344,7 +344,7 @@ PerformanceTiming::RequestStartHighRes() if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) { return mZeroTime; } - return TimeStampToDOMHighResOrFetchStart(mRequestStart); + return TimeStampToReducedDOMHighResOrFetchStart(mRequestStart); } DOMTimeMilliSec @@ -363,7 +363,7 @@ PerformanceTiming::ResponseStartHighRes() (!mCacheReadStart.IsNull() && mCacheReadStart < mResponseStart)) { mResponseStart = mCacheReadStart; } - return TimeStampToDOMHighResOrFetchStart(mResponseStart); + return TimeStampToReducedDOMHighResOrFetchStart(mResponseStart); } DOMTimeMilliSec @@ -384,7 +384,7 @@ PerformanceTiming::ResponseEndHighRes() } // Bug 1155008 - nsHttpTransaction is racy. Return ResponseStart when null return mResponseEnd.IsNull() ? ResponseStartHighRes() - : TimeStampToDOMHighRes(mResponseEnd); + : TimerClamping::ReduceMsTimeValue(TimeStampToDOMHighRes(mResponseEnd)); } DOMTimeMilliSec diff --git a/dom/performance/PerformanceTiming.h b/dom/performance/PerformanceTiming.h index 0bc73fd3ff..edfac8d027 100644..100755 --- a/dom/performance/PerformanceTiming.h +++ b/dom/performance/PerformanceTiming.h @@ -10,6 +10,7 @@ #include "mozilla/Attributes.h" #include "nsContentUtils.h" #include "nsDOMNavigationTiming.h" +#include "mozilla/TimerClamping.h" #include "nsWrapperCache.h" #include "Performance.h" @@ -68,10 +69,10 @@ public: * page), if the given TimeStamp is valid. Otherwise, it will return * the FetchStart timing value. */ - inline DOMHighResTimeStamp TimeStampToDOMHighResOrFetchStart(TimeStamp aStamp) + inline DOMHighResTimeStamp TimeStampToReducedDOMHighResOrFetchStart(TimeStamp aStamp) { return (!aStamp.IsNull()) - ? TimeStampToDOMHighRes(aStamp) + ? TimerClamping::ReduceMsTimeValue(TimeStampToDOMHighRes(aStamp)) : FetchStartHighRes(); } @@ -119,7 +120,7 @@ public: if (!nsContentUtils::IsPerformanceTimingEnabled()) { return 0; } - return GetDOMTiming()->GetNavigationStart(); + return TimerClamping::ReduceMsTimeValue(GetDOMTiming()->GetNavigationStart()); } DOMTimeMilliSec UnloadEventStart() @@ -127,7 +128,7 @@ public: if (!nsContentUtils::IsPerformanceTimingEnabled()) { return 0; } - return GetDOMTiming()->GetUnloadEventStart(); + return TimerClamping::ReduceMsTimeValue(GetDOMTiming()->GetUnloadEventStart()); } DOMTimeMilliSec UnloadEventEnd() @@ -135,7 +136,7 @@ public: if (!nsContentUtils::IsPerformanceTimingEnabled()) { return 0; } - return GetDOMTiming()->GetUnloadEventEnd(); + return TimerClamping::ReduceMsTimeValue(GetDOMTiming()->GetUnloadEventEnd()); } uint16_t GetRedirectCount() const; @@ -185,7 +186,7 @@ public: if (!nsContentUtils::IsPerformanceTimingEnabled()) { return 0; } - return GetDOMTiming()->GetDomLoading(); + return TimerClamping::ReduceMsTimeValue(GetDOMTiming()->GetDomLoading()); } DOMTimeMilliSec DomInteractive() const @@ -193,7 +194,7 @@ public: if (!nsContentUtils::IsPerformanceTimingEnabled()) { return 0; } - return GetDOMTiming()->GetDomInteractive(); + return TimerClamping::ReduceMsTimeValue(GetDOMTiming()->GetDomInteractive()); } DOMTimeMilliSec DomContentLoadedEventStart() const @@ -201,7 +202,7 @@ public: if (!nsContentUtils::IsPerformanceTimingEnabled()) { return 0; } - return GetDOMTiming()->GetDomContentLoadedEventStart(); + return TimerClamping::ReduceMsTimeValue(GetDOMTiming()->GetDomContentLoadedEventStart()); } DOMTimeMilliSec DomContentLoadedEventEnd() const @@ -209,7 +210,7 @@ public: if (!nsContentUtils::IsPerformanceTimingEnabled()) { return 0; } - return GetDOMTiming()->GetDomContentLoadedEventEnd(); + return TimerClamping::ReduceMsTimeValue(GetDOMTiming()->GetDomContentLoadedEventEnd()); } DOMTimeMilliSec DomComplete() const @@ -217,7 +218,7 @@ public: if (!nsContentUtils::IsPerformanceTimingEnabled()) { return 0; } - return GetDOMTiming()->GetDomComplete(); + return TimerClamping::ReduceMsTimeValue(GetDOMTiming()->GetDomComplete()); } DOMTimeMilliSec LoadEventStart() const @@ -225,7 +226,7 @@ public: if (!nsContentUtils::IsPerformanceTimingEnabled()) { return 0; } - return GetDOMTiming()->GetLoadEventStart(); + return TimerClamping::ReduceMsTimeValue(GetDOMTiming()->GetLoadEventStart()); } DOMTimeMilliSec LoadEventEnd() const @@ -233,7 +234,7 @@ public: if (!nsContentUtils::IsPerformanceTimingEnabled()) { return 0; } - return GetDOMTiming()->GetLoadEventEnd(); + return TimerClamping::ReduceMsTimeValue(GetDOMTiming()->GetLoadEventEnd()); } private: |