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: IDL; 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 | #include "nsISupports.idl" |
michael@0 | 7 | |
michael@0 | 8 | interface nsIObserver; |
michael@0 | 9 | |
michael@0 | 10 | /** |
michael@0 | 11 | * The nsIPrefBranch interface is used to manipulate the preferences data. This |
michael@0 | 12 | * object may be obtained from the preferences service (nsIPrefService) and |
michael@0 | 13 | * used to get and set default and/or user preferences across the application. |
michael@0 | 14 | * |
michael@0 | 15 | * This object is created with a "root" value which describes the base point in |
michael@0 | 16 | * the preferences "tree" from which this "branch" stems. Preferences are |
michael@0 | 17 | * accessed off of this root by using just the final portion of the preference. |
michael@0 | 18 | * For example, if this object is created with the root "browser.startup.", |
michael@0 | 19 | * the preferences "browser.startup.page", "browser.startup.homepage", |
michael@0 | 20 | * and "browser.startup.homepage_override" can be accessed by simply passing |
michael@0 | 21 | * "page", "homepage", or "homepage_override" to the various Get/Set methods. |
michael@0 | 22 | * |
michael@0 | 23 | * @see nsIPrefService |
michael@0 | 24 | */ |
michael@0 | 25 | |
michael@0 | 26 | [scriptable, uuid(55d25e49-793f-4727-a69f-de8b15f4b985)] |
michael@0 | 27 | interface nsIPrefBranch : nsISupports |
michael@0 | 28 | { |
michael@0 | 29 | |
michael@0 | 30 | /** |
michael@0 | 31 | * Values describing the basic preference types. |
michael@0 | 32 | * |
michael@0 | 33 | * @see getPrefType |
michael@0 | 34 | */ |
michael@0 | 35 | const long PREF_INVALID = 0; |
michael@0 | 36 | const long PREF_STRING = 32; |
michael@0 | 37 | const long PREF_INT = 64; |
michael@0 | 38 | const long PREF_BOOL = 128; |
michael@0 | 39 | |
michael@0 | 40 | /** |
michael@0 | 41 | * Called to get the root on which this branch is based, such as |
michael@0 | 42 | * "browser.startup." |
michael@0 | 43 | */ |
michael@0 | 44 | readonly attribute string root; |
michael@0 | 45 | |
michael@0 | 46 | /** |
michael@0 | 47 | * Called to determine the type of a specific preference. |
michael@0 | 48 | * |
michael@0 | 49 | * @param aPrefName The preference to get the type of. |
michael@0 | 50 | * |
michael@0 | 51 | * @return long A value representing the type of the preference. This |
michael@0 | 52 | * value will be PREF_STRING, PREF_INT, or PREF_BOOL. |
michael@0 | 53 | */ |
michael@0 | 54 | long getPrefType(in string aPrefName); |
michael@0 | 55 | |
michael@0 | 56 | /** |
michael@0 | 57 | * Called to get the state of an individual boolean preference. |
michael@0 | 58 | * |
michael@0 | 59 | * @param aPrefName The boolean preference to get the state of. |
michael@0 | 60 | * |
michael@0 | 61 | * @return boolean The value of the requested boolean preference. |
michael@0 | 62 | * |
michael@0 | 63 | * @see setBoolPref |
michael@0 | 64 | */ |
michael@0 | 65 | boolean getBoolPref(in string aPrefName); |
michael@0 | 66 | |
michael@0 | 67 | /** |
michael@0 | 68 | * Called to set the state of an individual boolean preference. |
michael@0 | 69 | * |
michael@0 | 70 | * @param aPrefName The boolean preference to set the state of. |
michael@0 | 71 | * @param aValue The boolean value to set the preference to. |
michael@0 | 72 | * |
michael@0 | 73 | * @throws Error if setting failed or the preference has a default |
michael@0 | 74 | value of a type other than boolean. |
michael@0 | 75 | * |
michael@0 | 76 | * @see getBoolPref |
michael@0 | 77 | */ |
michael@0 | 78 | void setBoolPref(in string aPrefName, in boolean aValue); |
michael@0 | 79 | |
michael@0 | 80 | /** |
michael@0 | 81 | * Called to get the state of an individual floating-point preference. |
michael@0 | 82 | * "Floating point" preferences are really string preferences that |
michael@0 | 83 | * are converted to floating point numbers. |
michael@0 | 84 | * |
michael@0 | 85 | * @param aPrefName The floating point preference to get the state of. |
michael@0 | 86 | * |
michael@0 | 87 | * @return float The value of the requested floating point preference. |
michael@0 | 88 | * |
michael@0 | 89 | * @see setCharPref |
michael@0 | 90 | */ |
michael@0 | 91 | float getFloatPref(in string aPrefName); |
michael@0 | 92 | |
michael@0 | 93 | /** |
michael@0 | 94 | * Called to get the state of an individual string preference. |
michael@0 | 95 | * |
michael@0 | 96 | * @param aPrefName The string preference to retrieve. |
michael@0 | 97 | * |
michael@0 | 98 | * @return string The value of the requested string preference. |
michael@0 | 99 | * |
michael@0 | 100 | * @see setCharPref |
michael@0 | 101 | */ |
michael@0 | 102 | string getCharPref(in string aPrefName); |
michael@0 | 103 | |
michael@0 | 104 | /** |
michael@0 | 105 | * Called to set the state of an individual string preference. |
michael@0 | 106 | * |
michael@0 | 107 | * @param aPrefName The string preference to set. |
michael@0 | 108 | * @param aValue The string value to set the preference to. |
michael@0 | 109 | * |
michael@0 | 110 | * @throws Error if setting failed or the preference has a default |
michael@0 | 111 | value of a type other than string. |
michael@0 | 112 | * |
michael@0 | 113 | * @see getCharPref |
michael@0 | 114 | */ |
michael@0 | 115 | void setCharPref(in string aPrefName, in string aValue); |
michael@0 | 116 | |
michael@0 | 117 | /** |
michael@0 | 118 | * Called to get the state of an individual integer preference. |
michael@0 | 119 | * |
michael@0 | 120 | * @param aPrefName The integer preference to get the value of. |
michael@0 | 121 | * |
michael@0 | 122 | * @return long The value of the requested integer preference. |
michael@0 | 123 | * |
michael@0 | 124 | * @see setIntPref |
michael@0 | 125 | */ |
michael@0 | 126 | long getIntPref(in string aPrefName); |
michael@0 | 127 | |
michael@0 | 128 | /** |
michael@0 | 129 | * Called to set the state of an individual integer preference. |
michael@0 | 130 | * |
michael@0 | 131 | * @param aPrefName The integer preference to set the value of. |
michael@0 | 132 | * @param aValue The integer value to set the preference to. |
michael@0 | 133 | * |
michael@0 | 134 | * @throws Error if setting failed or the preference has a default |
michael@0 | 135 | value of a type other than integer. |
michael@0 | 136 | * |
michael@0 | 137 | * @see getIntPref |
michael@0 | 138 | */ |
michael@0 | 139 | void setIntPref(in string aPrefName, in long aValue); |
michael@0 | 140 | |
michael@0 | 141 | /** |
michael@0 | 142 | * Called to get the state of an individual complex preference. A complex |
michael@0 | 143 | * preference is a preference which represents an XPCOM object that can not |
michael@0 | 144 | * be easily represented using a standard boolean, integer or string value. |
michael@0 | 145 | * |
michael@0 | 146 | * @param aPrefName The complex preference to get the value of. |
michael@0 | 147 | * @param aType The XPCOM interface that this complex preference |
michael@0 | 148 | * represents. Interfaces currently supported are: |
michael@0 | 149 | * - nsIFile |
michael@0 | 150 | * - nsISupportsString (UniChar) |
michael@0 | 151 | * - nsIPrefLocalizedString (Localized UniChar) |
michael@0 | 152 | * @param aValue The XPCOM object into which to the complex preference |
michael@0 | 153 | * value should be retrieved. |
michael@0 | 154 | * |
michael@0 | 155 | * @throws Error The value does not exist or is the wrong type. |
michael@0 | 156 | * |
michael@0 | 157 | * @see setComplexValue |
michael@0 | 158 | */ |
michael@0 | 159 | void getComplexValue(in string aPrefName, in nsIIDRef aType, |
michael@0 | 160 | [iid_is(aType), retval] out nsQIResult aValue); |
michael@0 | 161 | |
michael@0 | 162 | /** |
michael@0 | 163 | * Called to set the state of an individual complex preference. A complex |
michael@0 | 164 | * preference is a preference which represents an XPCOM object that can not |
michael@0 | 165 | * be easily represented using a standard boolean, integer or string value. |
michael@0 | 166 | * |
michael@0 | 167 | * @param aPrefName The complex preference to set the value of. |
michael@0 | 168 | * @param aType The XPCOM interface that this complex preference |
michael@0 | 169 | * represents. Interfaces currently supported are: |
michael@0 | 170 | * - nsIFile |
michael@0 | 171 | * - nsISupportsString (UniChar) |
michael@0 | 172 | * - nsIPrefLocalizedString (Localized UniChar) |
michael@0 | 173 | * @param aValue The XPCOM object from which to set the complex preference |
michael@0 | 174 | * value. |
michael@0 | 175 | * |
michael@0 | 176 | * @throws Error if setting failed or the value is the wrong type. |
michael@0 | 177 | * |
michael@0 | 178 | * @see getComplexValue |
michael@0 | 179 | */ |
michael@0 | 180 | void setComplexValue(in string aPrefName, in nsIIDRef aType, in nsISupports aValue); |
michael@0 | 181 | |
michael@0 | 182 | /** |
michael@0 | 183 | * Called to clear a user set value from a specific preference. This will, in |
michael@0 | 184 | * effect, reset the value to the default value. If no default value exists |
michael@0 | 185 | * the preference will cease to exist. |
michael@0 | 186 | * |
michael@0 | 187 | * @param aPrefName The preference to be cleared. |
michael@0 | 188 | * |
michael@0 | 189 | * @note |
michael@0 | 190 | * This method does nothing if this object is a default branch. |
michael@0 | 191 | */ |
michael@0 | 192 | void clearUserPref(in string aPrefName); |
michael@0 | 193 | |
michael@0 | 194 | /** |
michael@0 | 195 | * Called to lock a specific preference. Locking a preference will cause the |
michael@0 | 196 | * preference service to always return the default value regardless of |
michael@0 | 197 | * whether there is a user set value or not. |
michael@0 | 198 | * |
michael@0 | 199 | * @param aPrefName The preference to be locked. |
michael@0 | 200 | * |
michael@0 | 201 | * @note |
michael@0 | 202 | * This method can be called on either a default or user branch but, in |
michael@0 | 203 | * effect, always operates on the default branch. |
michael@0 | 204 | * |
michael@0 | 205 | * @throws Error The preference does not exist or an error occurred. |
michael@0 | 206 | * |
michael@0 | 207 | * @see unlockPref |
michael@0 | 208 | */ |
michael@0 | 209 | void lockPref(in string aPrefName); |
michael@0 | 210 | |
michael@0 | 211 | /** |
michael@0 | 212 | * Called to check if a specific preference has a user value associated to |
michael@0 | 213 | * it. |
michael@0 | 214 | * |
michael@0 | 215 | * @param aPrefName The preference to be tested. |
michael@0 | 216 | * |
michael@0 | 217 | * @note |
michael@0 | 218 | * This method can be called on either a default or user branch but, in |
michael@0 | 219 | * effect, always operates on the user branch. |
michael@0 | 220 | * |
michael@0 | 221 | * @note |
michael@0 | 222 | * If a preference was manually set to a value that equals the default value, |
michael@0 | 223 | * then the preference no longer has a user set value, i.e. it is |
michael@0 | 224 | * considered reset to its default value. |
michael@0 | 225 | * In particular, this method will return false for such a preference and |
michael@0 | 226 | * the preference will not be saved to a file by nsIPrefService.savePrefFile. |
michael@0 | 227 | * |
michael@0 | 228 | * @return boolean true The preference has a user set value. |
michael@0 | 229 | * false The preference only has a default value. |
michael@0 | 230 | */ |
michael@0 | 231 | boolean prefHasUserValue(in string aPrefName); |
michael@0 | 232 | |
michael@0 | 233 | /** |
michael@0 | 234 | * Called to check if a specific preference is locked. If a preference is |
michael@0 | 235 | * locked calling its Get method will always return the default value. |
michael@0 | 236 | * |
michael@0 | 237 | * @param aPrefName The preference to be tested. |
michael@0 | 238 | * |
michael@0 | 239 | * @note |
michael@0 | 240 | * This method can be called on either a default or user branch but, in |
michael@0 | 241 | * effect, always operates on the default branch. |
michael@0 | 242 | * |
michael@0 | 243 | * @return boolean true The preference is locked. |
michael@0 | 244 | * false The preference is not locked. |
michael@0 | 245 | * |
michael@0 | 246 | * @see lockPref |
michael@0 | 247 | * @see unlockPref |
michael@0 | 248 | */ |
michael@0 | 249 | boolean prefIsLocked(in string aPrefName); |
michael@0 | 250 | |
michael@0 | 251 | /** |
michael@0 | 252 | * Called to unlock a specific preference. Unlocking a previously locked |
michael@0 | 253 | * preference allows the preference service to once again return the user set |
michael@0 | 254 | * value of the preference. |
michael@0 | 255 | * |
michael@0 | 256 | * @param aPrefName The preference to be unlocked. |
michael@0 | 257 | * |
michael@0 | 258 | * @note |
michael@0 | 259 | * This method can be called on either a default or user branch but, in |
michael@0 | 260 | * effect, always operates on the default branch. |
michael@0 | 261 | * |
michael@0 | 262 | * @throws Error The preference does not exist or an error occurred. |
michael@0 | 263 | * |
michael@0 | 264 | * @see lockPref |
michael@0 | 265 | */ |
michael@0 | 266 | void unlockPref(in string aPrefName); |
michael@0 | 267 | |
michael@0 | 268 | |
michael@0 | 269 | /** |
michael@0 | 270 | * Called to remove all of the preferences referenced by this branch. |
michael@0 | 271 | * |
michael@0 | 272 | * @param aStartingAt The point on the branch at which to start the deleting |
michael@0 | 273 | * preferences. Pass in "" to remove all preferences |
michael@0 | 274 | * referenced by this branch. |
michael@0 | 275 | * |
michael@0 | 276 | * @note |
michael@0 | 277 | * This method can be called on either a default or user branch but, in |
michael@0 | 278 | * effect, always operates on both. |
michael@0 | 279 | * |
michael@0 | 280 | * @throws Error The preference(s) do not exist or an error occurred. |
michael@0 | 281 | */ |
michael@0 | 282 | void deleteBranch(in string aStartingAt); |
michael@0 | 283 | |
michael@0 | 284 | /** |
michael@0 | 285 | * Returns an array of strings representing the child preferences of the |
michael@0 | 286 | * root of this branch. |
michael@0 | 287 | * |
michael@0 | 288 | * @param aStartingAt The point on the branch at which to start enumerating |
michael@0 | 289 | * the child preferences. Pass in "" to enumerate all |
michael@0 | 290 | * preferences referenced by this branch. |
michael@0 | 291 | * @param aCount Receives the number of elements in the array. |
michael@0 | 292 | * @param aChildArray Receives the array of child preferences. |
michael@0 | 293 | * |
michael@0 | 294 | * @note |
michael@0 | 295 | * This method can be called on either a default or user branch but, in |
michael@0 | 296 | * effect, always operates on both. |
michael@0 | 297 | * |
michael@0 | 298 | * @throws Error The preference(s) do not exist or an error occurred. |
michael@0 | 299 | */ |
michael@0 | 300 | void getChildList(in string aStartingAt, |
michael@0 | 301 | [optional] out unsigned long aCount, |
michael@0 | 302 | [array, size_is(aCount), retval] out string aChildArray); |
michael@0 | 303 | |
michael@0 | 304 | /** |
michael@0 | 305 | * Called to reset all of the preferences referenced by this branch to their |
michael@0 | 306 | * default values. |
michael@0 | 307 | * |
michael@0 | 308 | * @param aStartingAt The point on the branch at which to start the resetting |
michael@0 | 309 | * preferences to their default values. Pass in "" to |
michael@0 | 310 | * reset all preferences referenced by this branch. |
michael@0 | 311 | * |
michael@0 | 312 | * @note |
michael@0 | 313 | * This method can be called on either a default or user branch but, in |
michael@0 | 314 | * effect, always operates on the user branch. |
michael@0 | 315 | * |
michael@0 | 316 | * @throws Error The preference(s) do not exist or an error occurred. |
michael@0 | 317 | */ |
michael@0 | 318 | void resetBranch(in string aStartingAt); |
michael@0 | 319 | |
michael@0 | 320 | /** |
michael@0 | 321 | * Add a preference change observer. On preference changes, the following |
michael@0 | 322 | * arguments will be passed to the nsIObserver.observe() method: |
michael@0 | 323 | * aSubject - The nsIPrefBranch object (this) |
michael@0 | 324 | * aTopic - The string defined by NS_PREFBRANCH_PREFCHANGE_TOPIC_ID |
michael@0 | 325 | * aData - The name of the preference which has changed, relative to |
michael@0 | 326 | * the |root| of the aSubject branch. |
michael@0 | 327 | * |
michael@0 | 328 | * aSubject.get*Pref(aData) will get the new value of the modified |
michael@0 | 329 | * preference. For example, if your observer is registered with |
michael@0 | 330 | * addObserver("bar.", ...) on a branch with root "foo.", modifying |
michael@0 | 331 | * the preference "foo.bar.baz" will trigger the observer, and aData |
michael@0 | 332 | * parameter will be "bar.baz". |
michael@0 | 333 | * |
michael@0 | 334 | * @param aDomain The preference on which to listen for changes. This can |
michael@0 | 335 | * be the name of an entire branch to observe. |
michael@0 | 336 | * e.g. Holding the "root" prefbranch and calling |
michael@0 | 337 | * addObserver("foo.bar.", ...) will observe changes to |
michael@0 | 338 | * foo.bar.baz and foo.bar.bzip |
michael@0 | 339 | * @param aObserver The object to be notified if the preference changes. |
michael@0 | 340 | * @param aHoldWeak true Hold a weak reference to |aObserver|. The object |
michael@0 | 341 | * must implement the nsISupportsWeakReference |
michael@0 | 342 | * interface or this will fail. |
michael@0 | 343 | * false Hold a strong reference to |aObserver|. |
michael@0 | 344 | * |
michael@0 | 345 | * @note |
michael@0 | 346 | * Registering as a preference observer can open an object to potential |
michael@0 | 347 | * cyclical references which will cause memory leaks. These cycles generally |
michael@0 | 348 | * occur because an object both registers itself as an observer (causing the |
michael@0 | 349 | * branch to hold a reference to the observer) and holds a reference to the |
michael@0 | 350 | * branch object for the purpose of getting/setting preference values. There |
michael@0 | 351 | * are 3 approaches which have been implemented in an attempt to avoid these |
michael@0 | 352 | * situations. |
michael@0 | 353 | * 1) The nsPrefBranch object supports nsISupportsWeakReference. Any consumer |
michael@0 | 354 | * may hold a weak reference to it instead of a strong one. |
michael@0 | 355 | * 2) The nsPrefBranch object listens for xpcom-shutdown and frees all of the |
michael@0 | 356 | * objects currently in its observer list. This ensures that long lived |
michael@0 | 357 | * objects (services for example) will be freed correctly. |
michael@0 | 358 | * 3) The observer can request to be held as a weak reference when it is |
michael@0 | 359 | * registered. This insures that shorter lived objects (say one tied to an |
michael@0 | 360 | * open window) will not fall into the cyclical reference trap. |
michael@0 | 361 | * |
michael@0 | 362 | * @note |
michael@0 | 363 | * The list of registered observers may be changed during the dispatch of |
michael@0 | 364 | * nsPref:changed notification. However, the observers are not guaranteed |
michael@0 | 365 | * to be notified in any particular order, so you can't be sure whether the |
michael@0 | 366 | * added/removed observer will be called during the notification when it |
michael@0 | 367 | * is added/removed. |
michael@0 | 368 | * |
michael@0 | 369 | * @note |
michael@0 | 370 | * It is possible to change preferences during the notification. |
michael@0 | 371 | * |
michael@0 | 372 | * @note |
michael@0 | 373 | * It is not safe to change observers during this callback in Gecko |
michael@0 | 374 | * releases before 1.9. If you want a safe way to remove a pref observer, |
michael@0 | 375 | * please use an nsITimer. |
michael@0 | 376 | * |
michael@0 | 377 | * @see nsIObserver |
michael@0 | 378 | * @see removeObserver |
michael@0 | 379 | */ |
michael@0 | 380 | void addObserver(in string aDomain, in nsIObserver aObserver, |
michael@0 | 381 | in boolean aHoldWeak); |
michael@0 | 382 | |
michael@0 | 383 | /** |
michael@0 | 384 | * Remove a preference change observer. |
michael@0 | 385 | * |
michael@0 | 386 | * @param aDomain The preference which is being observed for changes. |
michael@0 | 387 | * @param aObserver An observer previously registered with addObserver(). |
michael@0 | 388 | * |
michael@0 | 389 | * @note |
michael@0 | 390 | * Note that you must call removeObserver() on the same nsIPrefBranch |
michael@0 | 391 | * instance on which you called addObserver() in order to remove aObserver; |
michael@0 | 392 | * otherwise, the observer will not be removed. |
michael@0 | 393 | * |
michael@0 | 394 | * @see nsIObserver |
michael@0 | 395 | * @see addObserver |
michael@0 | 396 | */ |
michael@0 | 397 | void removeObserver(in string aDomain, in nsIObserver aObserver); |
michael@0 | 398 | }; |
michael@0 | 399 | |
michael@0 | 400 | |
michael@0 | 401 | %{C++ |
michael@0 | 402 | |
michael@0 | 403 | #define NS_PREFBRANCH_CONTRACTID "@mozilla.org/preferencesbranch;1" |
michael@0 | 404 | /** |
michael@0 | 405 | * Notification sent when a preference changes. |
michael@0 | 406 | */ |
michael@0 | 407 | #define NS_PREFBRANCH_PREFCHANGE_TOPIC_ID "nsPref:changed" |
michael@0 | 408 | |
michael@0 | 409 | %} |