nsIPermissionManager.idl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /* -*- Mode: C++; tab-width: 2; 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
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /**
  6. * This file contains an interface to the Permission Manager,
  7. * used to persistenly store permissions for different object types (cookies,
  8. * images etc) on a site-by-site basis.
  9. *
  10. * This service broadcasts the following notification when the permission list
  11. * is changed:
  12. *
  13. * topic : "perm-changed" (PERM_CHANGE_NOTIFICATION)
  14. * broadcast whenever the permission list changes in some way. there
  15. * are four possible data strings for this notification; one
  16. * notification will be broadcast for each change, and will involve
  17. * a single permission.
  18. * subject: an nsIPermission interface pointer representing the permission object
  19. * that changed.
  20. * data : "deleted"
  21. * a permission was deleted. the subject is the deleted permission.
  22. * "added"
  23. * a permission was added. the subject is the added permission.
  24. * "changed"
  25. * a permission was changed. the subject is the new permission.
  26. * "cleared"
  27. * the entire permission list was cleared. the subject is null.
  28. */
  29. #include "nsISupports.idl"
  30. interface nsIURI;
  31. interface nsIObserver;
  32. interface nsIPrincipal;
  33. interface mozIDOMWindow;
  34. interface nsIPermission;
  35. interface nsISimpleEnumerator;
  36. [scriptable, uuid(4dcb3851-eba2-4e42-b236-82d2596fca22)]
  37. interface nsIPermissionManager : nsISupports
  38. {
  39. /**
  40. * Predefined return values for the testPermission method and for
  41. * the permission param of the add method
  42. * NOTE: UNKNOWN_ACTION (0) is reserved to represent the
  43. * default permission when no entry is found for a host, and
  44. * should not be used by consumers to indicate otherwise.
  45. */
  46. const uint32_t UNKNOWN_ACTION = 0;
  47. const uint32_t ALLOW_ACTION = 1;
  48. const uint32_t DENY_ACTION = 2;
  49. const uint32_t PROMPT_ACTION = 3;
  50. /**
  51. * Predefined expiration types for permissions. Permissions can be permanent
  52. * (never expire), expire at the end of the session, or expire at a specified
  53. * time. Permissions that expire at the end of a session may also have a
  54. * specified expiration time.
  55. */
  56. const uint32_t EXPIRE_NEVER = 0;
  57. const uint32_t EXPIRE_SESSION = 1;
  58. const uint32_t EXPIRE_TIME = 2;
  59. /**
  60. * Add permission information for a given URI and permission type. This
  61. * operation will cause the type string to be registered if it does not
  62. * currently exist. If a permission already exists for a given type, it
  63. * will be modified.
  64. *
  65. * @param uri the uri to add the permission for
  66. * @param type a case-sensitive ASCII string, identifying the consumer.
  67. * Consumers should choose this string to be unique, with
  68. * respect to other consumers.
  69. * @param permission an integer representing the desired action (e.g. allow
  70. * or deny). The interpretation of this number is up to the
  71. * consumer, and may represent different actions for different
  72. * types. Consumers may use one of the enumerated permission
  73. * actions defined above, for convenience.
  74. * NOTE: UNKNOWN_ACTION (0) is reserved to represent the
  75. * default permission when no entry is found for a host, and
  76. * should not be used by consumers to indicate otherwise.
  77. * @param expiretype a constant defining whether this permission should
  78. * never expire (EXPIRE_NEVER), expire at the end of the
  79. * session (EXPIRE_SESSION), or expire at a specified time
  80. * (EXPIRE_TIME).
  81. * @param expiretime an integer representation of when this permission
  82. * should be forgotten (milliseconds since Jan 1 1970 0:00:00).
  83. */
  84. void add(in nsIURI uri,
  85. in string type,
  86. in uint32_t permission,
  87. [optional] in uint32_t expireType,
  88. [optional] in int64_t expireTime);
  89. /**
  90. * Get all custom permissions for a given URI. This will return
  91. * an enumerator of all permissions which are not set to default
  92. * and which belong to the matching prinicpal of the given URI.
  93. *
  94. * @param uri the URI to get all permissions for
  95. */
  96. nsISimpleEnumerator getAllForURI(in nsIURI uri);
  97. /**
  98. * Add permission information for a given principal.
  99. * It is internally calling the other add() method using the nsIURI from the
  100. * principal.
  101. * Passing a system principal will be a no-op because they will always be
  102. * granted permissions.
  103. */
  104. void addFromPrincipal(in nsIPrincipal principal, in string typed,
  105. in uint32_t permission,
  106. [optional] in uint32_t expireType,
  107. [optional] in int64_t expireTime);
  108. /**
  109. * Remove permission information for a given URI and permission type. This will
  110. * remove the permission for the entire host described by the uri, acting as the
  111. * opposite operation to the add() method.
  112. *
  113. * @param uri the uri to remove the permission for
  114. * @param type a case-sensitive ASCII string, identifying the consumer.
  115. * The type must have been previously registered using the
  116. * add() method.
  117. */
  118. void remove(in nsIURI uri,
  119. in string type);
  120. /**
  121. * Remove permission information for a given principal.
  122. * This is internally calling remove() with the host from the principal's URI.
  123. * Passing system principal will be a no-op because we never add them to the
  124. * database.
  125. */
  126. void removeFromPrincipal(in nsIPrincipal principal, in string type);
  127. /**
  128. * Remove the given permission from the permission manager.
  129. *
  130. * @param perm a permission obtained from the permission manager.
  131. */
  132. void removePermission(in nsIPermission perm);
  133. /**
  134. * Clear permission information for all websites.
  135. */
  136. void removeAll();
  137. /**
  138. * Clear all permission information added since the specified time.
  139. */
  140. void removeAllSince(in int64_t since);
  141. /**
  142. * Test whether a website has permission to perform the given action.
  143. * @param uri the uri to be tested
  144. * @param type a case-sensitive ASCII string, identifying the consumer
  145. * @param return see add(), param permission. returns UNKNOWN_ACTION when
  146. * there is no stored permission for this uri and / or type.
  147. */
  148. uint32_t testPermission(in nsIURI uri,
  149. in string type);
  150. /**
  151. * Test whether the principal has the permission to perform a given action.
  152. * System principals will always have permissions granted.
  153. */
  154. uint32_t testPermissionFromPrincipal(in nsIPrincipal principal,
  155. in string type);
  156. /**
  157. * Test whether the principal associated with the window's document has the
  158. * permission to perform a given action. System principals will always
  159. * have permissions granted.
  160. */
  161. uint32_t testPermissionFromWindow(in mozIDOMWindow window,
  162. in string type);
  163. /**
  164. * Test whether a website has permission to perform the given action.
  165. * This requires an exact hostname match, subdomains are not a match.
  166. * @param uri the uri to be tested
  167. * @param type a case-sensitive ASCII string, identifying the consumer
  168. * @param return see add(), param permission. returns UNKNOWN_ACTION when
  169. * there is no stored permission for this uri and / or type.
  170. */
  171. uint32_t testExactPermission(in nsIURI uri,
  172. in string type);
  173. /**
  174. * See testExactPermission() above.
  175. * System principals will always have permissions granted.
  176. */
  177. uint32_t testExactPermissionFromPrincipal(in nsIPrincipal principal,
  178. in string type);
  179. /**
  180. * Test whether a website has permission to perform the given action
  181. * ignoring active sessions.
  182. * System principals will always have permissions granted.
  183. *
  184. * @param principal the principal
  185. * @param type a case-sensitive ASCII string, identifying the consumer
  186. * @param return see add(), param permission. returns UNKNOWN_ACTION when
  187. * there is no stored permission for this uri and / or type.
  188. */
  189. uint32_t testExactPermanentPermission(in nsIPrincipal principal,
  190. in string type);
  191. /**
  192. * Get the permission object associated with the given principal and action.
  193. * @param principal The principal
  194. * @param type A case-sensitive ASCII string identifying the consumer
  195. * @param exactHost If true, only the specific host will be matched,
  196. * @see testExactPermission. If false, subdomains will
  197. * also be searched, @see testPermission.
  198. * @returns The matching permission object, or null if no matching object
  199. * was found. No matching object is equivalent to UNKNOWN_ACTION.
  200. * @note Clients in general should prefer the test* methods unless they
  201. * need to know the specific stored details.
  202. * @note This method will always return null for the system principal.
  203. */
  204. nsIPermission getPermissionObject(in nsIPrincipal principal,
  205. in string type,
  206. in boolean exactHost);
  207. /**
  208. * Allows enumeration of all stored permissions
  209. * @return an nsISimpleEnumerator interface that allows access to
  210. * nsIPermission objects
  211. */
  212. readonly attribute nsISimpleEnumerator enumerator;
  213. /**
  214. * Remove all permissions that will match the origin pattern.
  215. */
  216. void removePermissionsWithAttributes(in DOMString patternAsJSON);
  217. /**
  218. * If the current permission is set to expire, reset the expiration time. If
  219. * there is no permission or the current permission does not expire, this
  220. * method will silently return.
  221. *
  222. * @param sessionExpiretime an integer representation of when this permission
  223. * should be forgotten (milliseconds since
  224. * Jan 1 1970 0:00:00), if it is currently
  225. * EXPIRE_SESSION.
  226. * @param sessionExpiretime an integer representation of when this permission
  227. * should be forgotten (milliseconds since
  228. * Jan 1 1970 0:00:00), if it is currently
  229. * EXPIRE_TIME.
  230. */
  231. void updateExpireTime(in nsIPrincipal principal,
  232. in string type,
  233. in boolean exactHost,
  234. in uint64_t sessionExpireTime,
  235. in uint64_t persistentExpireTime);
  236. /**
  237. * Remove all current permission settings and get permission settings from
  238. * chrome process.
  239. */
  240. void refreshPermission();
  241. };
  242. %{ C++
  243. #define NS_PERMISSIONMANAGER_CONTRACTID "@mozilla.org/permissionmanager;1"
  244. #define PERM_CHANGE_NOTIFICATION "perm-changed"
  245. %}