2018-01-19 03:59:58 +08:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
|
|
#include "PerformanceResourceTiming.h"
|
|
|
|
|
#include "mozilla/dom/PerformanceResourceTimingBinding.h"
|
2018-05-26 15:00:01 -04:00
|
|
|
#include "mozilla/Unused.h"
|
2018-01-19 03:59:58 +08:00
|
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(PerformanceResourceTiming,
|
|
|
|
|
PerformanceEntry,
|
2023-10-20 04:21:49 -05:00
|
|
|
mPerformance)
|
2018-01-19 03:59:58 +08:00
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(PerformanceResourceTiming,
|
|
|
|
|
PerformanceEntry)
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
|
2025-01-18 16:15:51 +01:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PerformanceResourceTiming)
|
2018-01-19 03:59:58 +08:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(PerformanceEntry)
|
|
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(PerformanceResourceTiming, PerformanceEntry)
|
|
|
|
|
NS_IMPL_RELEASE_INHERITED(PerformanceResourceTiming, PerformanceEntry)
|
|
|
|
|
|
2023-10-20 04:21:49 -05:00
|
|
|
PerformanceResourceTiming::PerformanceResourceTiming(UniquePtr<PerformanceTimingData>&& aPerformanceTiming,
|
2018-01-19 03:59:58 +08:00
|
|
|
Performance* aPerformance,
|
2023-10-20 04:21:49 -05:00
|
|
|
const nsAString& aName)
|
|
|
|
|
: PerformanceEntry(aPerformance->GetParentObject(), aName, NS_LITERAL_STRING("resource"))
|
|
|
|
|
, mTimingData(Move(aPerformanceTiming))
|
|
|
|
|
, mPerformance(aPerformance)
|
2018-01-19 03:59:58 +08:00
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(aPerformance, "Parent performance object should be provided");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PerformanceResourceTiming::~PerformanceResourceTiming()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DOMHighResTimeStamp
|
|
|
|
|
PerformanceResourceTiming::StartTime() const
|
|
|
|
|
{
|
2018-04-29 11:49:50 +02:00
|
|
|
// Force the start time to be the earliest of:
|
|
|
|
|
// - RedirectStart
|
|
|
|
|
// - WorkerStart
|
|
|
|
|
// - AsyncOpen
|
|
|
|
|
// Ignore zero values. The RedirectStart and WorkerStart values
|
|
|
|
|
// can come from earlier redirected channels prior to the AsyncOpen
|
|
|
|
|
// time being recorded.
|
2023-10-20 04:21:49 -05:00
|
|
|
DOMHighResTimeStamp redirect = mTimingData->RedirectStartHighRes(mPerformance);
|
2018-04-29 11:49:50 +02:00
|
|
|
redirect = redirect ? redirect : DBL_MAX;
|
|
|
|
|
|
2023-10-20 04:21:49 -05:00
|
|
|
DOMHighResTimeStamp worker = mTimingData->WorkerStartHighRes(mPerformance);
|
2018-04-29 11:49:50 +02:00
|
|
|
worker = worker ? worker : DBL_MAX;
|
|
|
|
|
|
2023-10-20 04:21:49 -05:00
|
|
|
DOMHighResTimeStamp asyncOpen = mTimingData->AsyncOpenHighRes(mPerformance);
|
2018-04-29 11:49:50 +02:00
|
|
|
|
|
|
|
|
return std::min(asyncOpen, std::min(redirect, worker));
|
2018-01-19 03:59:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JSObject*
|
|
|
|
|
PerformanceResourceTiming::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
|
|
|
|
{
|
|
|
|
|
return PerformanceResourceTimingBinding::Wrap(aCx, this, aGivenProto);
|
|
|
|
|
}
|