diff --git a/dom/performance/Performance.cpp b/dom/performance/Performance.cpp index 07f539bba0a3..bd5ae474e502 100644 --- a/dom/performance/Performance.cpp +++ b/dom/performance/Performance.cpp @@ -53,6 +53,7 @@ already_AddRefed Performance::CreateForMainThread( nsDOMNavigationTiming* aDOMTiming, nsITimedChannel* aChannel) { MOZ_ASSERT(NS_IsMainThread()); + MOZ_ASSERT(aWindow->AsGlobal()); RefPtr performance = new PerformanceMainThread( aWindow, aDOMTiming, aChannel, aPrincipal->IsSystemPrincipal()); return performance.forget(); @@ -89,12 +90,9 @@ Performance::~Performance() = default; DOMHighResTimeStamp Performance::Now() { DOMHighResTimeStamp rawTime = NowUnclamped(); - if (mSystemPrincipal) { - return rawTime; - } - - return nsRFPService::ReduceTimePrecisionAsMSecs(rawTime, - GetRandomTimelineSeed()); + return nsRFPService::ReduceTimePrecisionAsMSecs( + rawTime, GetRandomTimelineSeed(), mSystemPrincipal, + CrossOriginIsolated()); } DOMHighResTimeStamp Performance::NowUnclamped() const { @@ -110,12 +108,9 @@ DOMHighResTimeStamp Performance::TimeOrigin() { MOZ_ASSERT(mPerformanceService); DOMHighResTimeStamp rawTimeOrigin = mPerformanceService->TimeOrigin(CreationTimeStamp()); - if (mSystemPrincipal) { - return rawTimeOrigin; - } - // Time Origin is an absolute timestamp, so we supply a 0 context mix-in - return nsRFPService::ReduceTimePrecisionAsMSecs(rawTimeOrigin, 0); + return nsRFPService::ReduceTimePrecisionAsMSecs( + rawTimeOrigin, 0, mSystemPrincipal, CrossOriginIsolated()); } JSObject* Performance::WrapObject(JSContext* aCx, diff --git a/dom/performance/Performance.h b/dom/performance/Performance.h index ae8f5987dce7..3f67b8b73cab 100644 --- a/dom/performance/Performance.h +++ b/dom/performance/Performance.h @@ -109,6 +109,8 @@ class Performance : public DOMEventTargetHelper { virtual void QueueNavigationTimingEntry() = 0; + virtual bool CrossOriginIsolated() const = 0; + protected: explicit Performance(bool aSystemPrincipal); Performance(nsPIDOMWindowInner* aWindow, bool aSystemPrincipal); diff --git a/dom/performance/PerformanceMainThread.cpp b/dom/performance/PerformanceMainThread.cpp index fe1cd685814f..588b487cacb2 100644 --- a/dom/performance/PerformanceMainThread.cpp +++ b/dom/performance/PerformanceMainThread.cpp @@ -72,7 +72,8 @@ PerformanceMainThread::PerformanceMainThread(nsPIDOMWindowInner* aWindow, bool aPrincipal) : Performance(aWindow, aPrincipal), mDOMTiming(aDOMTiming), - mChannel(aChannel) { + mChannel(aChannel), + mCrossOriginIsolated(aWindow->AsGlobal()->CrossOriginIsolated()) { MOZ_ASSERT(aWindow, "Parent window object should be provided"); CreateNavigationTimingEntry(); } @@ -256,8 +257,9 @@ DOMHighResTimeStamp PerformanceMainThread::GetPerformanceTimingFromString( "out " "of sync"); } - return nsRFPService::ReduceTimePrecisionAsMSecs(retValue, - GetRandomTimelineSeed()); + return nsRFPService::ReduceTimePrecisionAsMSecs( + retValue, GetRandomTimelineSeed(), /* aIsSystemPrinciapl */ false, + CrossOriginIsolated()); } void PerformanceMainThread::InsertUserEntry(PerformanceEntry* aEntry) { @@ -335,6 +337,10 @@ void PerformanceMainThread::QueueNavigationTimingEntry() { QueueEntry(mDocEntry); } +bool PerformanceMainThread::CrossOriginIsolated() const { + return mCrossOriginIsolated; +} + void PerformanceMainThread::GetEntries( nsTArray>& aRetval) { // We return an empty list when 'privacy.resistFingerprinting' is on. diff --git a/dom/performance/PerformanceMainThread.h b/dom/performance/PerformanceMainThread.h index 2de584760ebf..989bc3f01749 100644 --- a/dom/performance/PerformanceMainThread.h +++ b/dom/performance/PerformanceMainThread.h @@ -64,6 +64,8 @@ class PerformanceMainThread final : public Performance, void QueueNavigationTimingEntry() override; + bool CrossOriginIsolated() const override; + protected: ~PerformanceMainThread(); @@ -84,6 +86,8 @@ class PerformanceMainThread final : public Performance, RefPtr mTiming; RefPtr mNavigation; JS::Heap mMozMemory; + + const bool mCrossOriginIsolated; }; } // namespace dom diff --git a/dom/performance/PerformanceNavigationTiming.cpp b/dom/performance/PerformanceNavigationTiming.cpp index dbc6aa78c4d5..b159355f0828 100644 --- a/dom/performance/PerformanceNavigationTiming.cpp +++ b/dom/performance/PerformanceNavigationTiming.cpp @@ -21,12 +21,10 @@ JSObject* PerformanceNavigationTiming::WrapObject( return PerformanceNavigationTiming_Binding::Wrap(aCx, this, aGivenProto); } -#define REDUCE_TIME_PRECISION \ - if (mPerformance->IsSystemPrincipal()) { \ - return rawValue; \ - } \ - return nsRFPService::ReduceTimePrecisionAsMSecs( \ - rawValue, mPerformance->GetRandomTimelineSeed()) +#define REDUCE_TIME_PRECISION \ + return nsRFPService::ReduceTimePrecisionAsMSecs( \ + rawValue, mPerformance->GetRandomTimelineSeed(), \ + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()) DOMHighResTimeStamp PerformanceNavigationTiming::UnloadEventStart() const { DOMHighResTimeStamp rawValue = 0; diff --git a/dom/performance/PerformanceTiming.cpp b/dom/performance/PerformanceTiming.cpp index 374be9c6761c..08426e2bb354 100644 --- a/dom/performance/PerformanceTiming.cpp +++ b/dom/performance/PerformanceTiming.cpp @@ -82,10 +82,10 @@ PerformanceTiming::PerformanceTiming(Performance* aPerformance, mTimingData.reset(new PerformanceTimingData( aChannel, aHttpChannel, - aPerformance->IsSystemPrincipal() - ? aZeroTime - : nsRFPService::ReduceTimePrecisionAsMSecs( - aZeroTime, aPerformance->GetRandomTimelineSeed()))); + nsRFPService::ReduceTimePrecisionAsMSecs( + aZeroTime, aPerformance->GetRandomTimelineSeed(), + aPerformance->IsSystemPrincipal(), + aPerformance->CrossOriginIsolated()))); // Non-null aHttpChannel implies that this PerformanceTiming object is being // used for subresources, which is irrelevant to this probe. @@ -250,11 +250,9 @@ DOMHighResTimeStamp PerformanceTimingData::FetchStartHighRes( } } } - if (aPerformance->IsSystemPrincipal()) { - return mFetchStart; - } return nsRFPService::ReduceTimePrecisionAsMSecs( - mFetchStart, aPerformance->GetRandomTimelineSeed()); + mFetchStart, aPerformance->GetRandomTimelineSeed(), + aPerformance->IsSystemPrincipal(), aPerformance->CrossOriginIsolated()); } DOMTimeMilliSec PerformanceTiming::FetchStart() { @@ -317,11 +315,9 @@ DOMHighResTimeStamp PerformanceTimingData::AsyncOpenHighRes( } DOMHighResTimeStamp rawValue = TimeStampToDOMHighRes(aPerformance, mAsyncOpen); - if (aPerformance->IsSystemPrincipal()) { - return rawValue; - } return nsRFPService::ReduceTimePrecisionAsMSecs( - rawValue, aPerformance->GetRandomTimelineSeed()); + rawValue, aPerformance->GetRandomTimelineSeed(), + aPerformance->IsSystemPrincipal(), aPerformance->CrossOriginIsolated()); } DOMHighResTimeStamp PerformanceTimingData::WorkerStartHighRes( @@ -334,11 +330,9 @@ DOMHighResTimeStamp PerformanceTimingData::WorkerStartHighRes( } DOMHighResTimeStamp rawValue = TimeStampToDOMHighRes(aPerformance, mWorkerStart); - if (aPerformance->IsSystemPrincipal()) { - return rawValue; - } return nsRFPService::ReduceTimePrecisionAsMSecs( - rawValue, aPerformance->GetRandomTimelineSeed()); + rawValue, aPerformance->GetRandomTimelineSeed(), + aPerformance->IsSystemPrincipal(), aPerformance->CrossOriginIsolated()); } /** @@ -441,11 +435,9 @@ DOMHighResTimeStamp PerformanceTimingData::DomainLookupEndHighRes( } DOMHighResTimeStamp rawValue = TimeStampToDOMHighRes(aPerformance, mDomainLookupEnd); - if (aPerformance->IsSystemPrincipal()) { - return rawValue; - } return nsRFPService::ReduceTimePrecisionAsMSecs( - rawValue, aPerformance->GetRandomTimelineSeed()); + rawValue, aPerformance->GetRandomTimelineSeed(), + aPerformance->IsSystemPrincipal(), aPerformance->CrossOriginIsolated()); } DOMTimeMilliSec PerformanceTiming::DomainLookupEnd() { @@ -466,11 +458,9 @@ DOMHighResTimeStamp PerformanceTimingData::ConnectStartHighRes( } DOMHighResTimeStamp rawValue = TimeStampToDOMHighRes(aPerformance, mConnectStart); - if (aPerformance->IsSystemPrincipal()) { - return rawValue; - } return nsRFPService::ReduceTimePrecisionAsMSecs( - rawValue, aPerformance->GetRandomTimelineSeed()); + rawValue, aPerformance->GetRandomTimelineSeed(), + aPerformance->IsSystemPrincipal(), aPerformance->CrossOriginIsolated()); } DOMTimeMilliSec PerformanceTiming::ConnectStart() { @@ -494,11 +484,9 @@ DOMHighResTimeStamp PerformanceTimingData::SecureConnectionStartHighRes( } DOMHighResTimeStamp rawValue = TimeStampToDOMHighRes(aPerformance, mSecureConnectionStart); - if (aPerformance->IsSystemPrincipal()) { - return rawValue; - } return nsRFPService::ReduceTimePrecisionAsMSecs( - rawValue, aPerformance->GetRandomTimelineSeed()); + rawValue, aPerformance->GetRandomTimelineSeed(), + aPerformance->IsSystemPrincipal(), aPerformance->CrossOriginIsolated()); } DOMTimeMilliSec PerformanceTiming::SecureConnectionStart() { @@ -520,11 +508,9 @@ DOMHighResTimeStamp PerformanceTimingData::ConnectEndHighRes( } DOMHighResTimeStamp rawValue = TimeStampToDOMHighRes(aPerformance, mConnectEnd); - if (aPerformance->IsSystemPrincipal()) { - return rawValue; - } return nsRFPService::ReduceTimePrecisionAsMSecs( - rawValue, aPerformance->GetRandomTimelineSeed()); + rawValue, aPerformance->GetRandomTimelineSeed(), + aPerformance->IsSystemPrincipal(), aPerformance->CrossOriginIsolated()); } DOMTimeMilliSec PerformanceTiming::ConnectEnd() { @@ -596,11 +582,9 @@ DOMHighResTimeStamp PerformanceTimingData::ResponseEndHighRes( } DOMHighResTimeStamp rawValue = TimeStampToDOMHighRes(aPerformance, mResponseEnd); - if (aPerformance->IsSystemPrincipal()) { - return rawValue; - } return nsRFPService::ReduceTimePrecisionAsMSecs( - rawValue, aPerformance->GetRandomTimelineSeed()); + rawValue, aPerformance->GetRandomTimelineSeed(), + aPerformance->IsSystemPrincipal(), aPerformance->CrossOriginIsolated()); } DOMTimeMilliSec PerformanceTiming::ResponseEnd() { diff --git a/dom/performance/PerformanceTiming.h b/dom/performance/PerformanceTiming.h index 64a8dc7614c3..63b116c77207 100644 --- a/dom/performance/PerformanceTiming.h +++ b/dom/performance/PerformanceTiming.h @@ -70,12 +70,10 @@ class PerformanceTimingData final { DOMHighResTimeStamp rawTimestamp = TimeStampToDOMHighRes(aPerformance, aStamp); - if (aPerformance->IsSystemPrincipal()) { - return rawTimestamp; - } return nsRFPService::ReduceTimePrecisionAsMSecs( - rawTimestamp, aPerformance->GetRandomTimelineSeed()); + rawTimestamp, aPerformance->GetRandomTimelineSeed(), + aPerformance->IsSystemPrincipal(), aPerformance->CrossOriginIsolated()); } /** @@ -250,12 +248,10 @@ class PerformanceTiming final : public nsWrapperCache { nsContentUtils::ShouldResistFingerprinting()) { return 0; } - if (mPerformance->IsSystemPrincipal()) { - return GetDOMTiming()->GetNavigationStart(); - } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetNavigationStart(), - mPerformance->GetRandomTimelineSeed()); + mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec UnloadEventStart() { @@ -263,12 +259,10 @@ class PerformanceTiming final : public nsWrapperCache { nsContentUtils::ShouldResistFingerprinting()) { return 0; } - if (mPerformance->IsSystemPrincipal()) { - return GetDOMTiming()->GetUnloadEventStart(); - } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetUnloadEventStart(), - mPerformance->GetRandomTimelineSeed()); + mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec UnloadEventEnd() { @@ -276,12 +270,10 @@ class PerformanceTiming final : public nsWrapperCache { nsContentUtils::ShouldResistFingerprinting()) { return 0; } - if (mPerformance->IsSystemPrincipal()) { - return GetDOMTiming()->GetUnloadEventEnd(); - } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetUnloadEventEnd(), - mPerformance->GetRandomTimelineSeed()); + mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } // Low resolution (used by navigation timing) @@ -302,11 +294,9 @@ class PerformanceTiming final : public nsWrapperCache { nsContentUtils::ShouldResistFingerprinting()) { return 0; } - if (mPerformance->IsSystemPrincipal()) { - return GetDOMTiming()->GetDomLoading(); - } return nsRFPService::ReduceTimePrecisionAsMSecs( - GetDOMTiming()->GetDomLoading(), mPerformance->GetRandomTimelineSeed()); + GetDOMTiming()->GetDomLoading(), mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec DomInteractive() const { @@ -314,12 +304,10 @@ class PerformanceTiming final : public nsWrapperCache { nsContentUtils::ShouldResistFingerprinting()) { return 0; } - if (mPerformance->IsSystemPrincipal()) { - return GetDOMTiming()->GetDomInteractive(); - } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetDomInteractive(), - mPerformance->GetRandomTimelineSeed()); + mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec DomContentLoadedEventStart() const { @@ -327,12 +315,10 @@ class PerformanceTiming final : public nsWrapperCache { nsContentUtils::ShouldResistFingerprinting()) { return 0; } - if (mPerformance->IsSystemPrincipal()) { - return GetDOMTiming()->GetDomContentLoadedEventStart(); - } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetDomContentLoadedEventStart(), - mPerformance->GetRandomTimelineSeed()); + mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec DomContentLoadedEventEnd() const { @@ -340,12 +326,10 @@ class PerformanceTiming final : public nsWrapperCache { nsContentUtils::ShouldResistFingerprinting()) { return 0; } - if (mPerformance->IsSystemPrincipal()) { - return GetDOMTiming()->GetDomContentLoadedEventEnd(); - } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetDomContentLoadedEventEnd(), - mPerformance->GetRandomTimelineSeed()); + mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec DomComplete() const { @@ -353,12 +337,9 @@ class PerformanceTiming final : public nsWrapperCache { nsContentUtils::ShouldResistFingerprinting()) { return 0; } - if (mPerformance->IsSystemPrincipal()) { - return GetDOMTiming()->GetDomComplete(); - } return nsRFPService::ReduceTimePrecisionAsMSecs( - GetDOMTiming()->GetDomComplete(), - mPerformance->GetRandomTimelineSeed()); + GetDOMTiming()->GetDomComplete(), mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec LoadEventStart() const { @@ -366,12 +347,10 @@ class PerformanceTiming final : public nsWrapperCache { nsContentUtils::ShouldResistFingerprinting()) { return 0; } - if (mPerformance->IsSystemPrincipal()) { - return GetDOMTiming()->GetLoadEventStart(); - } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetLoadEventStart(), - mPerformance->GetRandomTimelineSeed()); + mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec LoadEventEnd() const { @@ -379,12 +358,10 @@ class PerformanceTiming final : public nsWrapperCache { nsContentUtils::ShouldResistFingerprinting()) { return 0; } - if (mPerformance->IsSystemPrincipal()) { - return GetDOMTiming()->GetLoadEventEnd(); - } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetLoadEventEnd(), - mPerformance->GetRandomTimelineSeed()); + mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec TimeToNonBlankPaint() const { @@ -392,12 +369,10 @@ class PerformanceTiming final : public nsWrapperCache { nsContentUtils::ShouldResistFingerprinting()) { return 0; } - if (mPerformance->IsSystemPrincipal()) { - return GetDOMTiming()->GetTimeToNonBlankPaint(); - } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetTimeToNonBlankPaint(), - mPerformance->GetRandomTimelineSeed()); + mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec TimeToContentfulPaint() const { @@ -405,12 +380,10 @@ class PerformanceTiming final : public nsWrapperCache { nsContentUtils::ShouldResistFingerprinting()) { return 0; } - if (mPerformance->IsSystemPrincipal()) { - return GetDOMTiming()->GetTimeToContentfulPaint(); - } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetTimeToContentfulPaint(), - mPerformance->GetRandomTimelineSeed()); + mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec TimeToDOMContentFlushed() const { @@ -418,12 +391,10 @@ class PerformanceTiming final : public nsWrapperCache { nsContentUtils::ShouldResistFingerprinting()) { return 0; } - if (mPerformance->IsSystemPrincipal()) { - return GetDOMTiming()->GetTimeToDOMContentFlushed(); - } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetTimeToDOMContentFlushed(), - mPerformance->GetRandomTimelineSeed()); + mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec TimeToFirstInteractive() const { @@ -431,11 +402,9 @@ class PerformanceTiming final : public nsWrapperCache { nsContentUtils::ShouldResistFingerprinting()) { return 0; } - if (mPerformance->IsSystemPrincipal()) { - return GetDOMTiming()->GetTimeToTTFI(); - } return nsRFPService::ReduceTimePrecisionAsMSecs( - GetDOMTiming()->GetTimeToTTFI(), mPerformance->GetRandomTimelineSeed()); + GetDOMTiming()->GetTimeToTTFI(), mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } PerformanceTimingData* Data() const { return mTimingData.get(); } diff --git a/dom/performance/PerformanceWorker.cpp b/dom/performance/PerformanceWorker.cpp index be9667602dd6..926222b461e1 100644 --- a/dom/performance/PerformanceWorker.cpp +++ b/dom/performance/PerformanceWorker.cpp @@ -46,5 +46,9 @@ uint64_t PerformanceWorker::GetRandomTimelineSeed() { return mWorkerPrivate->GetRandomTimelineSeed(); } +bool PerformanceWorker::CrossOriginIsolated() const { + return mWorkerPrivate->CrossOriginIsolated(); +} + } // namespace dom } // namespace mozilla diff --git a/dom/performance/PerformanceWorker.h b/dom/performance/PerformanceWorker.h index 4f9a1b83840a..be546d120bb7 100644 --- a/dom/performance/PerformanceWorker.h +++ b/dom/performance/PerformanceWorker.h @@ -58,6 +58,8 @@ class PerformanceWorker final : public Performance { MOZ_CRASH("This should not be called on workers."); } + bool CrossOriginIsolated() const override; + protected: ~PerformanceWorker();