PermissionRequestBase.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_indexeddb_permissionrequestbase_h__
  6. #define mozilla_dom_indexeddb_permissionrequestbase_h__
  7. #include "mozilla/Attributes.h"
  8. #include "nsCOMPtr.h"
  9. #include "nsIInterfaceRequestor.h"
  10. #include "nsIObserver.h"
  11. #include "nsIPermissionManager.h"
  12. #include "nsISupportsImpl.h"
  13. #include "nsString.h"
  14. class nsIPrincipal;
  15. namespace mozilla {
  16. namespace dom {
  17. class Element;
  18. namespace indexedDB {
  19. class PermissionRequestBase
  20. : public nsIObserver
  21. , public nsIInterfaceRequestor
  22. {
  23. nsCOMPtr<Element> mOwnerElement;
  24. nsCOMPtr<nsIPrincipal> mPrincipal;
  25. public:
  26. enum PermissionValue {
  27. kPermissionAllowed = nsIPermissionManager::ALLOW_ACTION,
  28. kPermissionDenied = nsIPermissionManager::DENY_ACTION,
  29. kPermissionPrompt = nsIPermissionManager::PROMPT_ACTION
  30. };
  31. NS_DECL_ISUPPORTS
  32. // This function will not actually prompt. It will never return
  33. // kPermissionDefault but will instead translate the permission manager value
  34. // into the correct value for the given type.
  35. static nsresult
  36. GetCurrentPermission(nsIPrincipal* aPrincipal,
  37. PermissionValue* aCurrentValue);
  38. static PermissionValue
  39. PermissionValueForIntPermission(uint32_t aIntPermission);
  40. // This function will prompt if needed. It may only be called once.
  41. nsresult
  42. PromptIfNeeded(PermissionValue* aCurrentValue);
  43. protected:
  44. PermissionRequestBase(Element* aOwnerElement,
  45. nsIPrincipal* aPrincipal);
  46. // Reference counted.
  47. virtual
  48. ~PermissionRequestBase();
  49. virtual void
  50. OnPromptComplete(PermissionValue aPermissionValue) = 0;
  51. private:
  52. void
  53. SetExplicitPermission(nsIPrincipal* aPrincipal,
  54. uint32_t aIntPermission);
  55. NS_DECL_NSIOBSERVER
  56. NS_DECL_NSIINTERFACEREQUESTOR
  57. };
  58. } // namespace indexedDB
  59. } // namespace dom
  60. } // namespace mozilla
  61. #endif // mozilla_dom_indexeddb_permissionrequestbase_h__