Bug 1586761 - P3 - Use new methods in dom/performance; r=tjr,baku

Note that this patch implements a member function CrossOriginIsIsolated in
PerformanceWorker and PerformanceMainThread. In PerformanceMainThread, we need
to cache boolean for CrossOriginIsIsolated() so that we don't need to find the
owning global on every callsites.

Differential Revision: https://phabricator.services.mozilla.com/D63904

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Tom Tung 2020-03-25 14:09:42 +00:00
Родитель 94183661ac
Коммит b05759de17
9 изменённых файлов: 81 добавлений и 117 удалений

Просмотреть файл

@ -53,6 +53,7 @@ already_AddRefed<Performance> Performance::CreateForMainThread(
nsDOMNavigationTiming* aDOMTiming, nsITimedChannel* aChannel) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aWindow->AsGlobal());
RefPtr<Performance> 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,

Просмотреть файл

@ -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);

Просмотреть файл

@ -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<RefPtr<PerformanceEntry>>& aRetval) {
// We return an empty list when 'privacy.resistFingerprinting' is on.

Просмотреть файл

@ -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<PerformanceTiming> mTiming;
RefPtr<PerformanceNavigation> mNavigation;
JS::Heap<JSObject*> mMozMemory;
const bool mCrossOriginIsolated;
};
} // namespace dom

Просмотреть файл

@ -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;

Просмотреть файл

@ -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() {

Просмотреть файл

@ -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(); }

Просмотреть файл

@ -46,5 +46,9 @@ uint64_t PerformanceWorker::GetRandomTimelineSeed() {
return mWorkerPrivate->GetRandomTimelineSeed();
}
bool PerformanceWorker::CrossOriginIsolated() const {
return mWorkerPrivate->CrossOriginIsolated();
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -58,6 +58,8 @@ class PerformanceWorker final : public Performance {
MOZ_CRASH("This should not be called on workers.");
}
bool CrossOriginIsolated() const override;
protected:
~PerformanceWorker();