PermissionObserver.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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_PermissionObserver_h_
  6. #define mozilla_dom_PermissionObserver_h_
  7. #include "mozilla/dom/PermissionsBinding.h"
  8. #include "nsIObserver.h"
  9. #include "nsIPrincipal.h"
  10. #include "nsTArray.h"
  11. #include "nsWeakReference.h"
  12. namespace mozilla {
  13. namespace dom {
  14. class PermissionStatus;
  15. // Singleton that watches for perm-changed notifications in order to notify
  16. // PermissionStatus objects.
  17. class PermissionObserver final
  18. : public nsIObserver
  19. , public nsSupportsWeakReference
  20. {
  21. public:
  22. NS_DECL_ISUPPORTS
  23. NS_DECL_NSIOBSERVER
  24. static already_AddRefed<PermissionObserver> GetInstance();
  25. void AddSink(PermissionStatus* aObs);
  26. void RemoveSink(PermissionStatus* aObs);
  27. private:
  28. PermissionObserver();
  29. virtual ~PermissionObserver();
  30. void Notify(PermissionName aName, nsIPrincipal& aPrincipal);
  31. nsTArray<PermissionStatus*> mSinks;
  32. };
  33. } // namespace dom
  34. } // namespace mozilla
  35. #endif