AppProcessChecker.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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_AppProcessChecker_h
  6. #define mozilla_AppProcessChecker_h
  7. #include <stdint.h>
  8. class nsIPrincipal;
  9. namespace mozilla {
  10. namespace dom {
  11. class TabContext;
  12. class PBrowserParent;
  13. class PContentParent;
  14. } // namespace dom
  15. namespace hal_sandbox {
  16. class PHalParent;
  17. } // namespace hal_sandbox
  18. enum AssertAppProcessType {
  19. ASSERT_APP_PROCESS_PERMISSION,
  20. ASSERT_APP_PROCESS_MANIFEST_URL,
  21. ASSERT_APP_HAS_PERMISSION
  22. };
  23. /**
  24. * Return true if the specified browser has the specified capability.
  25. * If this returns false, the browser didn't have the capability and
  26. * will be killed.
  27. */
  28. bool
  29. AssertAppProcess(mozilla::dom::PBrowserParent* aActor,
  30. AssertAppProcessType aType,
  31. const char* aCapability);
  32. /**
  33. * Return true if the specified app has the specified status.
  34. * If this returns false, the browser will be killed.
  35. */
  36. bool
  37. AssertAppStatus(mozilla::dom::PBrowserParent* aActor,
  38. unsigned short aStatus);
  39. /**
  40. * Return true if the specified browser has the specified capability.
  41. * If this returns false, the browser didn't have the capability and
  42. * will be killed.
  43. */
  44. bool
  45. AssertAppProcess(const mozilla::dom::TabContext& aContext,
  46. AssertAppProcessType aType,
  47. const char* aCapability);
  48. /**
  49. * Return true if the specified app has the specified status.
  50. * If this returns false, the browser will be killed.
  51. */
  52. bool
  53. AssertAppStatus(const mozilla::dom::TabContext& aContext,
  54. unsigned short aStatus);
  55. /**
  56. * Return true if any of the PBrowsers loaded in this content process
  57. * has the specified capability. If this returns false, the process
  58. * didn't have the capability and will be killed.
  59. */
  60. bool
  61. AssertAppProcess(mozilla::dom::PContentParent* aActor,
  62. AssertAppProcessType aType,
  63. const char* aCapability);
  64. /**
  65. * Return true if any of the PBrowsers loaded in this content process
  66. * has an app with the specified status. If this returns false, the process
  67. * didn't have the status and will be killed.
  68. */
  69. bool
  70. AssertAppStatus(mozilla::dom::PContentParent* aActor,
  71. unsigned short aStatus);
  72. bool
  73. AssertAppProcess(mozilla::hal_sandbox::PHalParent* aActor,
  74. AssertAppProcessType aType,
  75. const char* aCapability);
  76. // NB: when adding capability checks for other IPDL actors, please add
  77. // them to this file and have them delegate to the two functions above
  78. // as appropriate. For example,
  79. //
  80. // bool AppProcessHasCapability(PNeckoParent* aActor, AssertAppProcessType aType) {
  81. // return AssertAppProcess(aActor->Manager(), aType);
  82. // }
  83. bool
  84. AssertAppPrincipal(mozilla::dom::PContentParent* aParent,
  85. nsIPrincipal* aPrincipal);
  86. /**
  87. * Check if the specified principal is valid, and return the saved permission
  88. * value for permission `aPermission' on that principal.
  89. * See nsIPermissionManager.idl for possible return values.
  90. *
  91. * nsIPermissionManager::UNKNOWN_ACTION is retuned if the principal is invalid.
  92. */
  93. uint32_t
  94. CheckPermission(mozilla::dom::PContentParent* aParent,
  95. nsIPrincipal* aPrincipal, const char* aPermission);
  96. /**
  97. * Inline function for asserting the process's permission.
  98. */
  99. template<typename T>
  100. inline bool
  101. AssertAppProcessPermission(T* aActor,
  102. const char* aPermission) {
  103. return AssertAppProcess(aActor,
  104. ASSERT_APP_PROCESS_PERMISSION,
  105. aPermission);
  106. }
  107. /**
  108. * Inline function for asserting the process's manifest URL.
  109. */
  110. template<typename T>
  111. inline bool
  112. AssertAppProcessManifestURL(T* aActor,
  113. const char* aManifestURL) {
  114. return AssertAppProcess(aActor,
  115. ASSERT_APP_PROCESS_MANIFEST_URL,
  116. aManifestURL);
  117. }
  118. /**
  119. * Inline function for asserting the process's manifest URL.
  120. */
  121. template<typename T>
  122. inline bool
  123. AssertAppHasPermission(T* aActor,
  124. const char* aPermission) {
  125. return AssertAppProcess(aActor,
  126. ASSERT_APP_HAS_PERMISSION,
  127. aPermission);
  128. }
  129. template<typename T>
  130. inline bool
  131. AssertAppHasStatus(T* aActor,
  132. unsigned short aStatus) {
  133. return AssertAppStatus(aActor, aStatus);
  134. }
  135. } // namespace mozilla
  136. #endif // mozilla_AppProcessChecker_h