# Backport of https://phabricator.services.mozilla.com/D167444 # and https://phabricator.services.mozilla.com/D167563 # Should land in 111.0 --- a/dom/performance/Performance.cpp +++ b/dom/performance/Performance.cpp @@ -163,29 +163,17 @@ JS::Handle aGivenProto) { return Performance_Binding::Wrap(aCx, this, aGivenProto); } void Performance::GetEntries(nsTArray>& aRetval) { - // We return an empty list when 'privacy.resistFingerprinting' is on. - if (nsContentUtils::ShouldResistFingerprinting()) { - aRetval.Clear(); - return; - } - aRetval = mResourceEntries.Clone(); aRetval.AppendElements(mUserEntries); aRetval.Sort(PerformanceEntryComparator()); } void Performance::GetEntriesByType( const nsAString& aEntryType, nsTArray>& aRetval) { - // We return an empty list when 'privacy.resistFingerprinting' is on. - if (nsContentUtils::ShouldResistFingerprinting()) { - aRetval.Clear(); - return; - } - if (aEntryType.EqualsLiteral("resource")) { aRetval = mResourceEntries.Clone(); return; } @@ -204,15 +192,10 @@ void Performance::GetEntriesByName( const nsAString& aName, const Optional& aEntryType, nsTArray>& aRetval) { aRetval.Clear(); - // We return an empty list when 'privacy.resistFingerprinting' is on. - if (nsContentUtils::ShouldResistFingerprinting()) { - return; - } - RefPtr name = NS_Atomize(aName); RefPtr entryType = aEntryType.WasPassed() ? NS_Atomize(aEntryType.Value()) : nullptr; if (entryType) { @@ -365,21 +348,11 @@ PerformanceMark::Constructor(global, aName, aMarkOptions, aRv); if (aRv.Failed()) { return nullptr; } - // To avoid fingerprinting in User Timing L2, we didn't add marks to the - // buffer so the user could not get timing data (which can be used to - // fingerprint) from the API. This may no longer be necessary (since - // performance.now() has reduced precision to protect against fingerprinting - // and performance.mark's primary fingerprinting issue is probably this timing - // data) but we need to do a more thorough reanalysis before we remove the - // fingerprinting protection. For now, we preserve the User Timing L2 behavior - // while supporting User Timing L3. - if (!nsContentUtils::ShouldResistFingerprinting()) { - InsertUserEntry(performanceMark); - } + InsertUserEntry(performanceMark); if (profiler_thread_is_being_profiled_for_markers()) { Maybe innerWindowId; if (GetOwner()) { innerWindowId = Some(GetOwner()->WindowID()); @@ -595,23 +568,10 @@ if (!GetParentObject()) { aRv.ThrowInvalidStateError("Global object is unavailable"); return nullptr; } - // When resisting fingerprinting, we don't add marks to the buffer. Since - // measure relies on relationships between marks in the buffer, this method - // will throw if we look for user-entered marks so we return a dummy measure - // instead of continuing. We could instead return real values for performance - // timing attributes and dummy values for user-entered marks but this adds - // complexity that doesn't seem worth the effort because these fingerprinting - // protections may not longer be necessary (since performance.now() already - // has reduced precision). - if (nsContentUtils::ShouldResistFingerprinting()) { - return do_AddRef(new PerformanceMeasure(GetParentObject(), aName, 0, 0, - JS::NullHandleValue)); - } - // Maybe is more readable than using the union type directly. Maybe options; if (aStartOrMeasureOptions.IsPerformanceMeasureOptions()) { options.emplace(aStartOrMeasureOptions.GetAsPerformanceMeasureOptions()); } @@ -811,10 +811,6 @@ MOZ_ALWAYS_INLINE bool Performance::CanAddResourceTimingEntry() { void Performance::InsertResourceEntry(PerformanceEntry* aEntry) { MOZ_ASSERT(aEntry); - if (nsContentUtils::ShouldResistFingerprinting()) { - return; - } - /* * Let new entry be the input PerformanceEntry to be added. * --- a/dom/performance/PerformanceMainThread.cpp +++ b/dom/performance/PerformanceMainThread.cpp @@ -409,12 +409,11 @@ } void PerformanceMainThread::CreateNavigationTimingEntry() { MOZ_ASSERT(!mDocEntry, "mDocEntry should be null."); - if (!StaticPrefs::dom_enable_performance_navigation_timing() || - StaticPrefs::privacy_resistFingerprinting()) { + if (!StaticPrefs::dom_enable_performance_navigation_timing()) { return; } nsAutoString name; GetURLSpecFromChannel(mChannel, name); @@ -461,16 +460,10 @@ return mEventCounts; } void PerformanceMainThread::GetEntries( nsTArray>& aRetval) { - // We return an empty list when 'privacy.resistFingerprinting' is on. - if (nsContentUtils::ShouldResistFingerprinting()) { - aRetval.Clear(); - return; - } - aRetval = mResourceEntries.Clone(); aRetval.AppendElements(mUserEntries); if (mDocEntry) { aRetval.AppendElement(mDocEntry); @@ -482,16 +475,10 @@ aRetval.Sort(PerformanceEntryComparator()); } void PerformanceMainThread::GetEntriesByType( const nsAString& aEntryType, nsTArray>& aRetval) { - // We return an empty list when 'privacy.resistFingerprinting' is on. - if (nsContentUtils::ShouldResistFingerprinting()) { - aRetval.Clear(); - return; - } - RefPtr type = NS_Atomize(aEntryType); if (type == nsGkAtoms::navigation) { aRetval.Clear(); if (mDocEntry) { @@ -524,16 +511,10 @@ } void PerformanceMainThread::GetEntriesByName( const nsAString& aName, const Optional& aEntryType, nsTArray>& aRetval) { - // We return an empty list when 'privacy.resistFingerprinting' is on. - if (nsContentUtils::ShouldResistFingerprinting()) { - aRetval.Clear(); - return; - } - Performance::GetEntriesByName(aName, aEntryType, aRetval); if (mFCPTiming && mFCPTiming->GetName()->Equals(aName) && (!aEntryType.WasPassed() || mFCPTiming->GetEntryType()->Equals(aEntryType.Value()))) { --- a/dom/performance/PerformanceNavigationTiming.cpp +++ b/dom/performance/PerformanceNavigationTiming.cpp @@ -150,8 +150,7 @@ nsIHttpChannel* aHttpChannel, nsITimedChannel* aChannel) { mTimingData->SetPropertiesFromHttpChannel(aHttpChannel, aChannel); } bool PerformanceNavigationTiming::Enabled(JSContext* aCx, JSObject* aGlobal) { - return (StaticPrefs::dom_enable_performance_navigation_timing() && - !StaticPrefs::privacy_resistFingerprinting()); + return StaticPrefs::dom_enable_performance_navigation_timing(); } --- a/dom/performance/PerformanceTiming.cpp +++ b/dom/performance/PerformanceTiming.cpp @@ -110,12 +110,11 @@ mTimingAllowed(true), mInitialized(false) { mInitialized = !!aChannel; mZeroTime = aZeroTime; - if (!StaticPrefs::dom_enable_performance() || - nsContentUtils::ShouldResistFingerprinting()) { + if (!StaticPrefs::dom_enable_performance()) { mZeroTime = 0; } nsCOMPtr uri; if (aHttpChannel) { @@ -336,24 +335,22 @@ // header with the domain of the page that started the load. return aChannel->TimingAllowCheck(principal); } uint8_t PerformanceTimingData::GetRedirectCount() const { - if (!StaticPrefs::dom_enable_performance() || !IsInitialized() || - nsContentUtils::ShouldResistFingerprinting()) { + if (!StaticPrefs::dom_enable_performance() || !IsInitialized()) { return 0; } if (!mAllRedirectsSameOrigin) { return 0; } return mRedirectCount; } bool PerformanceTimingData::ShouldReportCrossOriginRedirect( bool aEnsureSameOriginAndIgnoreTAO) const { - if (!StaticPrefs::dom_enable_performance() || !IsInitialized() || - nsContentUtils::ShouldResistFingerprinting()) { + if (!StaticPrefs::dom_enable_performance() || !IsInitialized()) { return false; } if (!mTimingAllowed || mRedirectCount == 0) { return false; --- a/dom/performance/Performance.h +++ b/dom/performance/Performance.h @@ -120,10 +120,15 @@ virtual TimeStamp CreationTimeStamp() const = 0; RTPCallerType GetRTPCallerType() const { return mRTPCallerType; } + bool CrossOriginIsolated() const { return mCrossOriginIsolated; } + bool ShouldResistFingerprinting() const { + return mShouldResistFingerprinting; + } + DOMHighResTimeStamp TimeStampToDOMHighResForRendering(TimeStamp) const; virtual uint64_t GetRandomTimelineSeed() = 0; void MemoryPressure(); @@ -145,12 +150,10 @@ virtual void QueueNavigationTimingEntry() = 0; virtual void UpdateNavigationTimingEntry() = 0; - virtual bool CrossOriginIsolated() const = 0; - virtual void DispatchPendingEventTimingEntries() = 0; void QueueNotificationObserversTask(); bool IsPerformanceTimingAttribute(const nsAString& aName) const; @@ -203,11 +206,13 @@ bool mPendingResourceTimingBufferFullEvent; RefPtr mPerformanceService; - enum RTPCallerType mRTPCallerType; + const RTPCallerType mRTPCallerType; + const bool mCrossOriginIsolated; + const bool mShouldResistFingerprinting; private: MOZ_ALWAYS_INLINE bool CanAddResourceTimingEntry(); void BufferEvent(); --- a/dom/performance/Performance.cpp +++ b/dom/performance/Performance.cpp @@ -96,24 +96,13 @@ Performance::Performance(nsIGlobalObject* aGlobal) : DOMEventTargetHelper(aGlobal), mResourceTimingBufferSize(kDefaultResourceTimingBufferSize), mPendingNotificationObserversTask(false), mPendingResourceTimingBufferFullEvent(false), - mRTPCallerType( - RTPCallerType::Normal /* to be updated in CreateForFoo */) { - MOZ_ASSERT(!NS_IsMainThread()); -} - -Performance::Performance(nsPIDOMWindowInner* aWindow) - : DOMEventTargetHelper(aWindow), - mResourceTimingBufferSize(kDefaultResourceTimingBufferSize), - mPendingNotificationObserversTask(false), - mPendingResourceTimingBufferFullEvent(false), - mRTPCallerType( - RTPCallerType::Normal /* to be updated in CreateForFoo */) { - MOZ_ASSERT(NS_IsMainThread()); -} + mRTPCallerType(aGlobal->GetRTPCallerType()), + mCrossOriginIsolated(aGlobal->CrossOriginIsolated()), + mShouldResistFingerprinting(aGlobal->ShouldResistFingerprinting()) {} Performance::~Performance() = default; DOMHighResTimeStamp Performance::TimeStampToDOMHighResForRendering( TimeStamp aTimeStamp) const { --- a/dom/performance/PerformanceMainThread.h +++ b/dom/performance/PerformanceMainThread.h @@ -86,12 +86,10 @@ nsTArray>& aRetval) override; void UpdateNavigationTimingEntry() override; void QueueNavigationTimingEntry() override; - bool CrossOriginIsolated() const override; - size_t SizeOfEventEntries(mozilla::MallocSizeOf aMallocSizeOf) const override; static constexpr uint32_t kDefaultEventTimingBufferSize = 150; static constexpr uint32_t kDefaultEventTimingDurationThreshold = 104; static constexpr double kDefaultEventTimingMinDuration = 16.0; @@ -118,12 +116,10 @@ RefPtr mTiming; RefPtr mNavigation; RefPtr mFCPTiming; JS::Heap mMozMemory; - const bool mCrossOriginIsolated; - nsTArray> mEventTimingEntries; AutoCleanLinkedList> mPendingEventTimingEntries; bool mHasDispatchedInputEvent = false; --- a/dom/performance/PerformanceMainThread.cpp +++ b/dom/performance/PerformanceMainThread.cpp @@ -89,16 +89,14 @@ NS_INTERFACE_MAP_END_INHERITING(Performance) PerformanceMainThread::PerformanceMainThread(nsPIDOMWindowInner* aWindow, nsDOMNavigationTiming* aDOMTiming, nsITimedChannel* aChannel) - : Performance(aWindow), + : Performance(aWindow->AsGlobal()), mDOMTiming(aDOMTiming), - mChannel(aChannel), - mCrossOriginIsolated(aWindow->AsGlobal()->CrossOriginIsolated()) { + mChannel(aChannel) { MOZ_ASSERT(aWindow, "Parent window object should be provided"); - mRTPCallerType = aWindow->AsGlobal()->GetRTPCallerType(); if (StaticPrefs::dom_enable_event_timing()) { mEventCounts = new class EventCounts(GetParentObject()); } CreateNavigationTimingEntry(); } @@ -449,14 +447,10 @@ UpdateNavigationTimingEntry(); QueueEntry(mDocEntry); } -bool PerformanceMainThread::CrossOriginIsolated() const { - return mCrossOriginIsolated; -} - EventCounts* PerformanceMainThread::EventCounts() { MOZ_ASSERT(StaticPrefs::dom_enable_event_timing()); return mEventCounts; } --- a/dom/performance/PerformanceTiming.cpp +++ b/dom/performance/PerformanceTiming.cpp @@ -466,11 +466,11 @@ if (!StaticPrefs::dom_enable_performance() || !IsInitialized()) { return mZeroTime; } // Bug 1637985 - DomainLookup information may be useful for fingerprinting. - if (nsContentUtils::ShouldResistFingerprinting()) { + if (aPerformance->ShouldResistFingerprinting()) { return FetchStartHighRes(aPerformance); } return TimeStampToReducedDOMHighResOrFetchStart(aPerformance, mDomainLookupStart); } @@ -486,11 +486,11 @@ if (!StaticPrefs::dom_enable_performance() || !IsInitialized()) { return mZeroTime; } // Bug 1637985 - DomainLookup information may be useful for fingerprinting. - if (nsContentUtils::ShouldResistFingerprinting()) { + if (aPerformance->ShouldResistFingerprinting()) { return FetchStartHighRes(aPerformance); } // Bug 1155008 - nsHttpTransaction is racy. Return DomainLookupStart when null if (mDomainLookupEnd.IsNull()) { return DomainLookupStartHighRes(aPerformance); --- a/dom/performance/PerformanceWorker.h +++ b/dom/performance/PerformanceWorker.h @@ -78,12 +78,10 @@ class EventCounts* EventCounts() override { MOZ_CRASH("This should not be called on workers"); } - bool CrossOriginIsolated() const override; - void NoteShuttingDown(); protected: ~PerformanceWorker(); --- a/dom/performance/PerformanceWorker.cpp +++ b/dom/performance/PerformanceWorker.cpp @@ -12,11 +12,10 @@ PerformanceWorker::PerformanceWorker(WorkerPrivate* aWorkerPrivate) : Performance(aWorkerPrivate->GlobalScope()), mWorkerPrivate(aWorkerPrivate) { mWorkerPrivate->AssertIsOnWorkerThread(); - mRTPCallerType = aWorkerPrivate->GlobalScope()->GetRTPCallerType(); } PerformanceWorker::~PerformanceWorker() { if (mWorkerPrivate) { mWorkerPrivate->AssertIsOnWorkerThread(); @@ -58,16 +57,8 @@ return mWorkerPrivate->GetRandomTimelineSeed(); } return 0; } -bool PerformanceWorker::CrossOriginIsolated() const { - MOZ_DIAGNOSTIC_ASSERT(mWorkerPrivate); - if (mWorkerPrivate) { - return mWorkerPrivate->CrossOriginIsolated(); - } - return false; -} - void PerformanceWorker::NoteShuttingDown() { mWorkerPrivate = nullptr; } } // namespace mozilla::dom