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