2016-06-09 20:04:42 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_Performance_h
|
|
|
|
#define mozilla_dom_Performance_h
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2018-02-12 23:02:22 +03:00
|
|
|
#include "mozilla/dom/DOMPrefs.h"
|
2016-06-09 20:04:42 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDOMNavigationTiming.h"
|
|
|
|
|
|
|
|
class nsITimedChannel;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class ErrorResult;
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class PerformanceEntry;
|
|
|
|
class PerformanceNavigation;
|
|
|
|
class PerformanceObserver;
|
2016-11-17 12:00:05 +03:00
|
|
|
class PerformanceService;
|
2018-01-24 19:17:31 +03:00
|
|
|
class PerformanceStorage;
|
2016-06-09 20:04:42 +03:00
|
|
|
class PerformanceTiming;
|
|
|
|
class WorkerPrivate;
|
|
|
|
|
|
|
|
// Base class for main-thread and worker Performance API
|
|
|
|
class Performance : public DOMEventTargetHelper {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Performance, DOMEventTargetHelper)
|
|
|
|
|
|
|
|
static bool IsObserverEnabled(JSContext* aCx, JSObject* aGlobal);
|
|
|
|
|
|
|
|
static already_AddRefed<Performance> CreateForMainThread(
|
|
|
|
nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal,
|
|
|
|
nsDOMNavigationTiming* aDOMTiming, nsITimedChannel* aChannel);
|
|
|
|
|
|
|
|
static already_AddRefed<Performance> CreateForWorker(
|
2018-01-31 10:24:08 +03:00
|
|
|
WorkerPrivate* aWorkerPrivate);
|
2016-06-09 20:04:42 +03:00
|
|
|
|
|
|
|
JSObject* WrapObject(JSContext* cx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
2016-04-17 23:03:28 +03:00
|
|
|
virtual void GetEntries(nsTArray<RefPtr<PerformanceEntry>>& aRetval);
|
2016-06-09 20:04:42 +03:00
|
|
|
|
2016-04-17 23:03:28 +03:00
|
|
|
virtual void GetEntriesByType(const nsAString& aEntryType,
|
|
|
|
nsTArray<RefPtr<PerformanceEntry>>& aRetval);
|
2016-06-09 20:04:42 +03:00
|
|
|
|
2016-04-17 23:03:28 +03:00
|
|
|
virtual void GetEntriesByName(const nsAString& aName,
|
|
|
|
const Optional<nsAString>& aEntryType,
|
|
|
|
nsTArray<RefPtr<PerformanceEntry>>& aRetval);
|
2016-06-09 20:04:42 +03:00
|
|
|
|
2018-01-24 19:17:31 +03:00
|
|
|
virtual PerformanceStorage* AsPerformanceStorage() = 0;
|
2016-06-09 20:04:42 +03:00
|
|
|
|
|
|
|
void ClearResourceTimings();
|
|
|
|
|
2018-03-10 05:12:53 +03:00
|
|
|
DOMHighResTimeStamp Now();
|
|
|
|
|
|
|
|
DOMHighResTimeStamp NowUnclamped() const;
|
2016-06-09 20:04:42 +03:00
|
|
|
|
2016-11-17 12:00:05 +03:00
|
|
|
DOMHighResTimeStamp TimeOrigin();
|
|
|
|
|
2016-06-09 20:04:42 +03:00
|
|
|
void Mark(const nsAString& aName, ErrorResult& aRv);
|
|
|
|
|
|
|
|
void ClearMarks(const Optional<nsAString>& aName);
|
|
|
|
|
|
|
|
void Measure(const nsAString& aName, const Optional<nsAString>& aStartMark,
|
|
|
|
const Optional<nsAString>& aEndMark, ErrorResult& aRv);
|
|
|
|
|
|
|
|
void ClearMeasures(const Optional<nsAString>& aName);
|
|
|
|
|
|
|
|
void SetResourceTimingBufferSize(uint64_t aMaxSize);
|
|
|
|
|
|
|
|
void AddObserver(PerformanceObserver* aObserver);
|
|
|
|
void RemoveObserver(PerformanceObserver* aObserver);
|
|
|
|
void NotifyObservers();
|
|
|
|
void CancelNotificationObservers();
|
|
|
|
|
|
|
|
virtual PerformanceTiming* Timing() = 0;
|
|
|
|
|
|
|
|
virtual PerformanceNavigation* Navigation() = 0;
|
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(resourcetimingbufferfull)
|
|
|
|
|
|
|
|
virtual void GetMozMemory(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JSObject*> aObj) = 0;
|
|
|
|
|
|
|
|
virtual nsDOMNavigationTiming* GetDOMTiming() const = 0;
|
|
|
|
|
|
|
|
virtual nsITimedChannel* GetChannel() const = 0;
|
|
|
|
|
2018-01-24 19:17:32 +03:00
|
|
|
virtual TimeStamp CreationTimeStamp() const = 0;
|
|
|
|
|
2018-03-09 18:29:33 +03:00
|
|
|
uint64_t IsSystemPrincipal() { return mSystemPrincipal; }
|
|
|
|
|
2018-03-13 20:36:34 +03:00
|
|
|
virtual uint64_t GetRandomTimelineSeed() = 0;
|
|
|
|
|
2017-07-20 13:57:08 +03:00
|
|
|
void MemoryPressure();
|
|
|
|
|
2017-07-27 10:05:51 +03:00
|
|
|
size_t SizeOfUserEntries(mozilla::MallocSizeOf aMallocSizeOf) const;
|
|
|
|
size_t SizeOfResourceEntries(mozilla::MallocSizeOf aMallocSizeOf) const;
|
|
|
|
|
2018-01-24 19:17:32 +03:00
|
|
|
void InsertResourceEntry(PerformanceEntry* aEntry);
|
|
|
|
|
2018-08-04 09:54:58 +03:00
|
|
|
virtual void QueueNavigationTimingEntry() = 0;
|
|
|
|
|
2016-06-09 20:04:42 +03:00
|
|
|
protected:
|
2018-06-16 17:21:46 +03:00
|
|
|
explicit Performance(bool aSystemPrincipal);
|
|
|
|
Performance(nsPIDOMWindowInner* aWindow, bool aSystemPrincipal);
|
2016-06-09 20:04:42 +03:00
|
|
|
|
|
|
|
virtual ~Performance();
|
|
|
|
|
|
|
|
virtual void InsertUserEntry(PerformanceEntry* aEntry);
|
|
|
|
|
|
|
|
void ClearUserEntries(const Optional<nsAString>& aEntryName,
|
|
|
|
const nsAString& aEntryType);
|
|
|
|
|
|
|
|
DOMHighResTimeStamp ResolveTimestampFromName(const nsAString& aName,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
virtual void DispatchBufferFullEvent() = 0;
|
|
|
|
|
|
|
|
virtual DOMHighResTimeStamp CreationTime() const = 0;
|
|
|
|
|
2016-12-17 09:51:22 +03:00
|
|
|
virtual bool IsPerformanceTimingAttribute(const nsAString& aName) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-09 20:04:42 +03:00
|
|
|
|
2016-12-17 09:51:22 +03:00
|
|
|
virtual DOMHighResTimeStamp GetPerformanceTimingFromString(
|
|
|
|
const nsAString& aTimingName) {
|
|
|
|
return 0;
|
|
|
|
}
|
2016-06-09 20:04:42 +03:00
|
|
|
|
|
|
|
void LogEntry(PerformanceEntry* aEntry, const nsACString& aOwner) const;
|
|
|
|
void TimingNotification(PerformanceEntry* aEntry, const nsACString& aOwner,
|
|
|
|
uint64_t epoch);
|
|
|
|
|
|
|
|
void RunNotificationObserversTask();
|
|
|
|
void QueueEntry(PerformanceEntry* aEntry);
|
|
|
|
|
|
|
|
nsTObserverArray<PerformanceObserver*> mObservers;
|
|
|
|
|
2016-04-17 23:03:28 +03:00
|
|
|
protected:
|
2018-05-19 09:49:20 +03:00
|
|
|
static const uint64_t kDefaultResourceTimingBufferSize = 250;
|
2017-07-06 01:15:08 +03:00
|
|
|
|
|
|
|
// When kDefaultResourceTimingBufferSize is increased or removed, these should
|
|
|
|
// be changed to use SegmentedVector
|
|
|
|
AutoTArray<RefPtr<PerformanceEntry>, kDefaultResourceTimingBufferSize>
|
|
|
|
mUserEntries;
|
|
|
|
AutoTArray<RefPtr<PerformanceEntry>, kDefaultResourceTimingBufferSize>
|
|
|
|
mResourceEntries;
|
2016-06-09 20:04:42 +03:00
|
|
|
|
|
|
|
uint64_t mResourceTimingBufferSize;
|
|
|
|
bool mPendingNotificationObserversTask;
|
2016-11-17 12:00:05 +03:00
|
|
|
|
|
|
|
RefPtr<PerformanceService> mPerformanceService;
|
2018-03-09 18:29:33 +03:00
|
|
|
|
|
|
|
bool mSystemPrincipal;
|
2016-06-09 20:04:42 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_Performance_h
|