PerformanceObserver.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_dom_PerformanceObserver_h__
  6. #define mozilla_dom_PerformanceObserver_h__
  7. #include "nsCOMPtr.h"
  8. #include "nsISupports.h"
  9. #include "mozilla/RefPtr.h"
  10. #include "nsString.h"
  11. #include "nsTArray.h"
  12. #include "nsWrapperCache.h"
  13. class nsPIDOMWindowInner;
  14. namespace mozilla {
  15. class ErrorResult;
  16. namespace dom {
  17. class GlobalObject;
  18. class Performance;
  19. class PerformanceEntry;
  20. class PerformanceObserverCallback;
  21. struct PerformanceObserverInit;
  22. namespace workers {
  23. class WorkerPrivate;
  24. } // namespace workers
  25. class PerformanceObserver final : public nsISupports,
  26. public nsWrapperCache
  27. {
  28. public:
  29. NS_DECL_CYCLE_COLLECTING_ISUPPORTS
  30. NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(PerformanceObserver)
  31. static already_AddRefed<PerformanceObserver>
  32. Constructor(const GlobalObject& aGlobal,
  33. PerformanceObserverCallback& aCb,
  34. ErrorResult& aRv);
  35. PerformanceObserver(nsPIDOMWindowInner* aOwner,
  36. PerformanceObserverCallback& aCb);
  37. PerformanceObserver(workers::WorkerPrivate* aWorkerPrivate,
  38. PerformanceObserverCallback& aCb);
  39. virtual JSObject* WrapObject(JSContext* aCx,
  40. JS::Handle<JSObject*> aGivenProto) override;
  41. nsISupports* GetParentObject() const { return mOwner; }
  42. void Observe(const PerformanceObserverInit& aOptions,
  43. mozilla::ErrorResult& aRv);
  44. void Disconnect();
  45. void Notify();
  46. void QueueEntry(PerformanceEntry* aEntry);
  47. private:
  48. ~PerformanceObserver();
  49. nsCOMPtr<nsISupports> mOwner;
  50. RefPtr<PerformanceObserverCallback> mCallback;
  51. RefPtr<Performance> mPerformance;
  52. nsTArray<nsString> mEntryTypes;
  53. bool mConnected;
  54. nsTArray<RefPtr<PerformanceEntry>> mQueuedEntries;
  55. };
  56. } // namespace dom
  57. } // namespace mozilla
  58. #endif