1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_PerformanceObserver_h__
8 #define mozilla_dom_PerformanceObserver_h__
11 #include "nsISupports.h"
12 #include "mozilla/dom/PerformanceObserverBinding.h"
13 #include "mozilla/RefPtr.h"
16 #include "nsWrapperCache.h"
18 class nsPIDOMWindowInner
;
28 class PerformanceEntry
;
29 class PerformanceObserverCallback
;
32 class PerformanceObserver final
: public nsISupports
, public nsWrapperCache
{
34 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
35 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(PerformanceObserver
)
37 static already_AddRefed
<PerformanceObserver
> Constructor(
38 const GlobalObject
& aGlobal
, PerformanceObserverCallback
& aCb
,
41 PerformanceObserver(nsPIDOMWindowInner
* aOwner
,
42 PerformanceObserverCallback
& aCb
);
44 PerformanceObserver(WorkerPrivate
* aWorkerPrivate
,
45 PerformanceObserverCallback
& aCb
);
47 virtual JSObject
* WrapObject(JSContext
* aCx
,
48 JS::Handle
<JSObject
*> aGivenProto
) override
;
50 nsISupports
* GetParentObject() const { return mOwner
; }
52 void Observe(const PerformanceObserverInit
& aOptions
, ErrorResult
& aRv
);
53 static void GetSupportedEntryTypes(const GlobalObject
& aGlobal
,
54 JS::MutableHandle
<JSObject
*> aObject
);
58 void TakeRecords(nsTArray
<RefPtr
<PerformanceEntry
>>& aRetval
);
60 MOZ_CAN_RUN_SCRIPT
void Notify();
61 void QueueEntry(PerformanceEntry
* aEntry
);
63 bool ObservesTypeOfEntry(PerformanceEntry
* aEntry
);
66 void ReportUnsupportedTypesErrorToConsole(bool aIsMainThread
,
68 const nsString
& aInvalidTypes
);
69 ~PerformanceObserver();
71 nsCOMPtr
<nsISupports
> mOwner
;
72 RefPtr
<PerformanceObserverCallback
> mCallback
;
73 RefPtr
<Performance
> mPerformance
;
74 nsTArray
<nsString
> mEntryTypes
;
75 nsTArray
<PerformanceObserverInit
> mOptions
;
77 ObserverTypeUndefined
,
82 * This is also known as registered, in the spec.
85 nsTArray
<RefPtr
<PerformanceEntry
>> mQueuedEntries
;
89 } // namespace mozilla