PerformanceObserver.h (2547B)
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/. */ 6 7 #ifndef mozilla_dom_PerformanceObserver_h__ 8 #define mozilla_dom_PerformanceObserver_h__ 9 10 #include "mozilla/RefPtr.h" 11 #include "mozilla/dom/PerformanceObserverBinding.h" 12 #include "nsCOMPtr.h" 13 #include "nsISupports.h" 14 #include "nsString.h" 15 #include "nsTArray.h" 16 #include "nsWrapperCache.h" 17 18 class nsPIDOMWindowInner; 19 20 namespace mozilla { 21 22 class ErrorResult; 23 24 namespace dom { 25 26 class GlobalObject; 27 class Performance; 28 class PerformanceEntry; 29 class PerformanceObserverCallback; 30 class WorkerPrivate; 31 32 class PerformanceObserver final : public nsISupports, public nsWrapperCache { 33 public: 34 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 35 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(PerformanceObserver) 36 37 static already_AddRefed<PerformanceObserver> Constructor( 38 const GlobalObject& aGlobal, PerformanceObserverCallback& aCb, 39 ErrorResult& aRv); 40 41 PerformanceObserver(nsPIDOMWindowInner* aOwner, 42 PerformanceObserverCallback& aCb); 43 44 PerformanceObserver(WorkerPrivate* aWorkerPrivate, 45 PerformanceObserverCallback& aCb); 46 47 virtual JSObject* WrapObject(JSContext* aCx, 48 JS::Handle<JSObject*> aGivenProto) override; 49 50 nsISupports* GetParentObject() const { return mOwner; } 51 52 void Observe(const PerformanceObserverInit& aOptions, ErrorResult& aRv); 53 static void GetSupportedEntryTypes(const GlobalObject& aGlobal, 54 JS::MutableHandle<JSObject*> aObject); 55 56 void Disconnect(); 57 58 void TakeRecords(nsTArray<RefPtr<PerformanceEntry>>& aRetval); 59 60 MOZ_CAN_RUN_SCRIPT void Notify(); 61 void QueueEntry(PerformanceEntry* aEntry); 62 63 bool ObservesTypeOfEntry(PerformanceEntry* aEntry); 64 65 private: 66 ~PerformanceObserver(); 67 68 nsCOMPtr<nsIGlobalObject> mOwner; 69 RefPtr<PerformanceObserverCallback> mCallback; 70 RefPtr<Performance> mPerformance; 71 nsTArray<nsString> mEntryTypes; 72 nsTArray<PerformanceObserverInit> mOptions; 73 enum { 74 ObserverTypeUndefined, 75 ObserverTypeSingle, 76 ObserverTypeMultiple, 77 } mObserverType; 78 /* 79 * This is also known as registered, in the spec. 80 */ 81 bool mConnected; 82 nsTArray<RefPtr<PerformanceEntry>> mQueuedEntries; 83 }; 84 85 } // namespace dom 86 } // namespace mozilla 87 88 #endif