Bug 1708193 - Remove mozapps/extensions/internal/Content.js r=rpl
[gecko.git] / dom / performance / PerformanceObserver.h
blob664ae6c121814801b692a4d2832a819c2c2b9298
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__
10 #include "nsCOMPtr.h"
11 #include "nsISupports.h"
12 #include "mozilla/dom/PerformanceObserverBinding.h"
13 #include "mozilla/RefPtr.h"
14 #include "nsString.h"
15 #include "nsTArray.h"
16 #include "nsWrapperCache.h"
18 class nsPIDOMWindowInner;
20 namespace mozilla {
22 class ErrorResult;
24 namespace dom {
26 class GlobalObject;
27 class Performance;
28 class PerformanceEntry;
29 class PerformanceObserverCallback;
30 class WorkerPrivate;
32 class PerformanceObserver final : public nsISupports, public nsWrapperCache {
33 public:
34 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
35 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(PerformanceObserver)
37 static already_AddRefed<PerformanceObserver> Constructor(
38 const GlobalObject& aGlobal, PerformanceObserverCallback& aCb,
39 ErrorResult& aRv);
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);
56 void Disconnect();
58 void TakeRecords(nsTArray<RefPtr<PerformanceEntry>>& aRetval);
60 MOZ_CAN_RUN_SCRIPT void Notify();
61 void QueueEntry(PerformanceEntry* aEntry);
63 bool ObservesTypeOfEntry(PerformanceEntry* aEntry);
65 private:
66 void ReportUnsupportedTypesErrorToConsole(bool aIsMainThread,
67 const char* msgId,
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;
76 enum {
77 ObserverTypeUndefined,
78 ObserverTypeSingle,
79 ObserverTypeMultiple,
80 } mObserverType;
82 * This is also known as registered, in the spec.
84 bool mConnected;
85 nsTArray<RefPtr<PerformanceEntry>> mQueuedEntries;
88 } // namespace dom
89 } // namespace mozilla
91 #endif