dom/interfaces/base/nsIContentPrefService2.idl

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include "nsISupports.idl"
michael@0 6
michael@0 7 interface nsIVariant;
michael@0 8 interface nsIContentPrefObserver;
michael@0 9 interface nsIContentPrefCallback2;
michael@0 10 interface nsILoadContext;
michael@0 11 interface nsIContentPref;
michael@0 12
michael@0 13 /**
michael@0 14 * Content Preferences
michael@0 15 *
michael@0 16 * Content preferences allow the application to associate arbitrary data, or
michael@0 17 * "preferences", with specific domains, or web "content". Specifically, a
michael@0 18 * content preference is a structure with three values: a domain with which the
michael@0 19 * preference is associated, a name that identifies the preference within its
michael@0 20 * domain, and a value. (See nsIContentPref below.)
michael@0 21 *
michael@0 22 * For example, if you want to remember the user's preference for a certain zoom
michael@0 23 * level on www.mozilla.org pages, you might store a preference whose domain is
michael@0 24 * "www.mozilla.org", whose name is "zoomLevel", and whose value is the numeric
michael@0 25 * zoom level.
michael@0 26 *
michael@0 27 * A preference need not have a domain, and in that case the preference is
michael@0 28 * called a "global" preference. This interface doesn't impart any special
michael@0 29 * significance to global preferences; they're simply name-value pairs that
michael@0 30 * aren't associated with any particular domain. As a consumer of this
michael@0 31 * interface, you might choose to let a global preference override all non-
michael@0 32 * global preferences of the same name, for example, for whatever definition of
michael@0 33 * "override" is appropriate for your use case.
michael@0 34 *
michael@0 35 *
michael@0 36 * Domain Parameters
michael@0 37 *
michael@0 38 * Many methods of this interface accept a "domain" parameter. Domains may be
michael@0 39 * specified either exactly, like "example.com", or as full URLs, like
michael@0 40 * "http://example.com/foo/bar". In the latter case the API extracts the full
michael@0 41 * domain from the URL, so if you specify "http://foo.bar.example.com/baz", the
michael@0 42 * domain is taken to be "foo.bar.example.com", not "example.com".
michael@0 43 *
michael@0 44 *
michael@0 45 * Private-Browsing Context Parameters
michael@0 46 *
michael@0 47 * Many methods also accept a "context" parameter. This parameter relates to
michael@0 48 * private browsing and determines the kind of storage that a method uses,
michael@0 49 * either the usual permanent storage or temporary storage set aside for private
michael@0 50 * browsing sessions.
michael@0 51 *
michael@0 52 * Pass null to unconditionally use permanent storage. Pass an nsILoadContext
michael@0 53 * to use storage appropriate to the context's usePrivateBrowsing attribute: if
michael@0 54 * usePrivateBrowsing is true, temporary private-browsing storage is used, and
michael@0 55 * otherwise permanent storage is used. A context can be obtained from the
michael@0 56 * window or channel whose content pertains to the preferences being modified or
michael@0 57 * retrieved.
michael@0 58 *
michael@0 59 *
michael@0 60 * Callbacks
michael@0 61 *
michael@0 62 * The methods of callback objects are always called asynchronously.
michael@0 63 *
michael@0 64 * Observers are called after callbacks are called, but they are called in the
michael@0 65 * same turn of the event loop as callbacks.
michael@0 66 *
michael@0 67 * See nsIContentPrefCallback2 below for more information about callbacks.
michael@0 68 */
michael@0 69
michael@0 70 [scriptable, uuid(f2507add-dc39-48e0-9147-e0270376148b)]
michael@0 71 interface nsIContentPrefService2 : nsISupports
michael@0 72 {
michael@0 73 /**
michael@0 74 * Gets all the preferences with the given name.
michael@0 75 *
michael@0 76 * @param name The preferences' name.
michael@0 77 * @param context The private-browsing context, if any.
michael@0 78 * @param callback handleResult is called once for each preference unless
michael@0 79 * no such preferences exist, in which case handleResult
michael@0 80 * is not called at all.
michael@0 81 */
michael@0 82 void getByName(in AString name,
michael@0 83 in nsILoadContext context,
michael@0 84 in nsIContentPrefCallback2 callback);
michael@0 85
michael@0 86 /**
michael@0 87 * Gets the preference with the given domain and name.
michael@0 88 *
michael@0 89 * @param domain The preference's domain.
michael@0 90 * @param name The preference's name.
michael@0 91 * @param context The private-browsing context, if any.
michael@0 92 * @param callback handleResult is called once unless no such preference
michael@0 93 * exists, in which case handleResult is not called at all.
michael@0 94 */
michael@0 95 void getByDomainAndName(in AString domain,
michael@0 96 in AString name,
michael@0 97 in nsILoadContext context,
michael@0 98 in nsIContentPrefCallback2 callback);
michael@0 99
michael@0 100 /**
michael@0 101 * Gets all preferences with the given name whose domains are either the same
michael@0 102 * as or subdomains of the given domain.
michael@0 103 *
michael@0 104 * @param domain The preferences' domain.
michael@0 105 * @param name The preferences' name.
michael@0 106 * @param context The private-browsing context, if any.
michael@0 107 * @param callback handleResult is called once for each preference. If no
michael@0 108 * such preferences exist, handleResult is not called at all.
michael@0 109 */
michael@0 110 void getBySubdomainAndName(in AString domain,
michael@0 111 in AString name,
michael@0 112 in nsILoadContext context,
michael@0 113 in nsIContentPrefCallback2 callback);
michael@0 114
michael@0 115 /**
michael@0 116 * Gets the preference with no domain and the given name.
michael@0 117 *
michael@0 118 * @param name The preference's name.
michael@0 119 * @param context The private-browsing context, if any.
michael@0 120 * @param callback handleResult is called once unless no such preference
michael@0 121 * exists, in which case handleResult is not called at all.
michael@0 122 */
michael@0 123 void getGlobal(in AString name,
michael@0 124 in nsILoadContext context,
michael@0 125 in nsIContentPrefCallback2 callback);
michael@0 126
michael@0 127 /**
michael@0 128 * Synchronously retrieves from the in-memory cache the preference with the
michael@0 129 * given domain and name.
michael@0 130 *
michael@0 131 * In addition to caching preference values, the cache also keeps track of
michael@0 132 * preferences that are known not to exist. If the preference is known not to
michael@0 133 * exist, the value attribute of the returned object will be undefined
michael@0 134 * (nsIDataType::VTYPE_VOID).
michael@0 135 *
michael@0 136 * If the preference is neither cached nor known not to exist, then null is
michael@0 137 * returned, and get() must be called to determine whether the preference
michael@0 138 * exists.
michael@0 139 *
michael@0 140 * @param domain The preference's domain.
michael@0 141 * @param name The preference's name.
michael@0 142 * @param context The private-browsing context, if any.
michael@0 143 * @return The preference, or null if no such preference is known to
michael@0 144 * exist.
michael@0 145 */
michael@0 146 nsIContentPref getCachedByDomainAndName(in AString domain,
michael@0 147 in AString name,
michael@0 148 in nsILoadContext context);
michael@0 149
michael@0 150 /**
michael@0 151 * Synchronously retrieves from the in-memory cache all preferences with the
michael@0 152 * given name whose domains are either the same as or subdomains of the given
michael@0 153 * domain.
michael@0 154 *
michael@0 155 * The preferences are returned in an array through the out-parameter. If a
michael@0 156 * preference for a particular subdomain is known not to exist, then an object
michael@0 157 * corresponding to that preference will be present in the array, and, as with
michael@0 158 * getCachedByDomainAndName, its value attribute will be undefined.
michael@0 159 *
michael@0 160 * @param domain The preferences' domain.
michael@0 161 * @param name The preferences' name.
michael@0 162 * @param context The private-browsing context, if any.
michael@0 163 * @param len The length of the returned array.
michael@0 164 * @param prefs The array of preferences.
michael@0 165 */
michael@0 166 void getCachedBySubdomainAndName(in AString domain,
michael@0 167 in AString name,
michael@0 168 in nsILoadContext context,
michael@0 169 [optional] out unsigned long len,
michael@0 170 [retval,array,size_is(len)] out nsIContentPref prefs);
michael@0 171
michael@0 172 /**
michael@0 173 * Synchronously retrieves from the in-memory cache the preference with no
michael@0 174 * domain and the given name.
michael@0 175 *
michael@0 176 * As with getCachedByDomainAndName, if the preference is cached then it is
michael@0 177 * returned; if the preference is known not to exist, then the value attribute
michael@0 178 * of the returned object will be undefined; if the preference is neither
michael@0 179 * cached nor known not to exist, then null is returned.
michael@0 180 *
michael@0 181 * @param name The preference's name.
michael@0 182 * @param context The private-browsing context, if any.
michael@0 183 * @return The preference, or null if no such preference is known to
michael@0 184 * exist.
michael@0 185 */
michael@0 186 nsIContentPref getCachedGlobal(in AString name,
michael@0 187 in nsILoadContext context);
michael@0 188
michael@0 189 /**
michael@0 190 * Sets a preference.
michael@0 191 *
michael@0 192 * @param domain The preference's domain.
michael@0 193 * @param name The preference's name.
michael@0 194 * @param value The preference's value.
michael@0 195 * @param context The private-browsing context, if any.
michael@0 196 * @param callback handleCompletion is called when the preference has been
michael@0 197 * stored.
michael@0 198 */
michael@0 199 void set(in AString domain,
michael@0 200 in AString name,
michael@0 201 in nsIVariant value,
michael@0 202 in nsILoadContext context,
michael@0 203 [optional] in nsIContentPrefCallback2 callback);
michael@0 204
michael@0 205 /**
michael@0 206 * Sets a preference with no domain.
michael@0 207 *
michael@0 208 * @param name The preference's name.
michael@0 209 * @param value The preference's value.
michael@0 210 * @param context The private-browsing context, if any.
michael@0 211 * @param callback handleCompletion is called when the preference has been
michael@0 212 * stored.
michael@0 213 */
michael@0 214 void setGlobal(in AString name,
michael@0 215 in nsIVariant value,
michael@0 216 in nsILoadContext context,
michael@0 217 [optional] in nsIContentPrefCallback2 callback);
michael@0 218
michael@0 219 /**
michael@0 220 * Removes the preference with the given domain and name.
michael@0 221 *
michael@0 222 * @param domain The preference's domain.
michael@0 223 * @param name The preference's name.
michael@0 224 * @param context The private-browsing context, if any.
michael@0 225 * @param callback handleCompletion is called when the operation completes.
michael@0 226 */
michael@0 227 void removeByDomainAndName(in AString domain,
michael@0 228 in AString name,
michael@0 229 in nsILoadContext context,
michael@0 230 [optional] in nsIContentPrefCallback2 callback);
michael@0 231
michael@0 232 /**
michael@0 233 * Removes all the preferences with the given name whose domains are either
michael@0 234 * the same as or subdomains of the given domain.
michael@0 235 *
michael@0 236 * @param domain The preferences' domain.
michael@0 237 * @param name The preferences' name.
michael@0 238 * @param context The private-browsing context, if any.
michael@0 239 * @param callback handleCompletion is called when the operation completes.
michael@0 240 */
michael@0 241 void removeBySubdomainAndName(in AString domain,
michael@0 242 in AString name,
michael@0 243 in nsILoadContext context,
michael@0 244 [optional] in nsIContentPrefCallback2 callback);
michael@0 245
michael@0 246 /**
michael@0 247 * Removes the preference with no domain and the given name.
michael@0 248 *
michael@0 249 * @param name The preference's name.
michael@0 250 * @param context The private-browsing context, if any.
michael@0 251 * @param callback handleCompletion is called when the operation completes.
michael@0 252 */
michael@0 253 void removeGlobal(in AString name,
michael@0 254 in nsILoadContext context,
michael@0 255 [optional] in nsIContentPrefCallback2 callback);
michael@0 256
michael@0 257 /**
michael@0 258 * Removes all preferences with the given domain.
michael@0 259 *
michael@0 260 * @param domain The preferences' domain.
michael@0 261 * @param context The private-browsing context, if any.
michael@0 262 * @param callback handleCompletion is called when the operation completes.
michael@0 263 */
michael@0 264 void removeByDomain(in AString domain,
michael@0 265 in nsILoadContext context,
michael@0 266 [optional] in nsIContentPrefCallback2 callback);
michael@0 267
michael@0 268 /**
michael@0 269 * Removes all preferences whose domains are either the same as or subdomains
michael@0 270 * of the given domain.
michael@0 271 *
michael@0 272 * @param domain The preferences' domain.
michael@0 273 * @param context The private-browsing context, if any.
michael@0 274 * @param callback handleCompletion is called when the operation completes.
michael@0 275 */
michael@0 276 void removeBySubdomain(in AString domain,
michael@0 277 in nsILoadContext context,
michael@0 278 [optional] in nsIContentPrefCallback2 callback);
michael@0 279
michael@0 280 /**
michael@0 281 * Removes all preferences with the given name regardless of domain, including
michael@0 282 * global preferences with the given name.
michael@0 283 *
michael@0 284 * @param name The preferences' name.
michael@0 285 * @param context The private-browsing context, if any.
michael@0 286 * @param callback handleCompletion is called when the operation completes.
michael@0 287 */
michael@0 288 void removeByName(in AString name,
michael@0 289 in nsILoadContext context,
michael@0 290 [optional] in nsIContentPrefCallback2 callback);
michael@0 291
michael@0 292 /**
michael@0 293 * Removes all non-global preferences -- in other words, all preferences that
michael@0 294 * have a domain.
michael@0 295 *
michael@0 296 * @param context The private-browsing context, if any.
michael@0 297 * @param callback handleCompletion is called when the operation completes.
michael@0 298 */
michael@0 299 void removeAllDomains(in nsILoadContext context,
michael@0 300 [optional] in nsIContentPrefCallback2 callback);
michael@0 301
michael@0 302 /**
michael@0 303 * Removes all global preferences -- in other words, all preferences that have
michael@0 304 * no domain.
michael@0 305 *
michael@0 306 * @param context The private-browsing context, if any.
michael@0 307 * @param callback handleCompletion is called when the operation completes.
michael@0 308 */
michael@0 309 void removeAllGlobals(in nsILoadContext context,
michael@0 310 [optional] in nsIContentPrefCallback2 callback);
michael@0 311
michael@0 312 /**
michael@0 313 * Registers an observer that will be notified whenever a preference with the
michael@0 314 * given name is set or removed.
michael@0 315 *
michael@0 316 * When a set or remove method is called, observers are called after the set
michael@0 317 * or removal completes and after the method's callback is called, and they
michael@0 318 * are called in the same turn of the event loop as the callback.
michael@0 319 *
michael@0 320 * The service holds a strong reference to the observer, so the observer must
michael@0 321 * be removed later to avoid leaking it.
michael@0 322 *
michael@0 323 * @param name The name of the preferences to observe. Pass null to
michael@0 324 * observe all preference changes regardless of name.
michael@0 325 * @param observer The observer.
michael@0 326 */
michael@0 327 void addObserverForName(in AString name,
michael@0 328 in nsIContentPrefObserver observer);
michael@0 329
michael@0 330 /**
michael@0 331 * Unregisters an observer for the given name.
michael@0 332 *
michael@0 333 * @param name The name for which the observer was registered. Pass null
michael@0 334 * if the observer was added with a null name.
michael@0 335 * @param observer The observer.
michael@0 336 */
michael@0 337 void removeObserverForName(in AString name,
michael@0 338 in nsIContentPrefObserver observer);
michael@0 339
michael@0 340 /**
michael@0 341 * Extracts and returns the domain from the given string representation of a
michael@0 342 * URI. This is how the API extracts domains from URIs passed to it.
michael@0 343 *
michael@0 344 * @param str The string representation of a URI, like
michael@0 345 * "http://example.com/foo/bar".
michael@0 346 * @return If the given string is a valid URI, the domain of that URI is
michael@0 347 * returned. Otherwise, the string itself is returned.
michael@0 348 */
michael@0 349 AString extractDomain(in AString str);
michael@0 350 };
michael@0 351
michael@0 352 /**
michael@0 353 * The callback used by the above methods.
michael@0 354 */
michael@0 355 [scriptable, uuid(1a12cf41-79e8-4d0f-9899-2f7b27c5d9a1)]
michael@0 356 interface nsIContentPrefCallback2 : nsISupports
michael@0 357 {
michael@0 358 /**
michael@0 359 * For the retrieval methods, this is called once for each retrieved
michael@0 360 * preference. It is not called for other methods.
michael@0 361 *
michael@0 362 * @param pref The retrieved preference.
michael@0 363 */
michael@0 364 void handleResult(in nsIContentPref pref);
michael@0 365
michael@0 366 /**
michael@0 367 * Called when an error occurs. This may be called multiple times before
michael@0 368 * handleCompletion is called.
michael@0 369 *
michael@0 370 * @param error A number in Components.results describing the error.
michael@0 371 */
michael@0 372 void handleError(in nsresult error);
michael@0 373
michael@0 374 /**
michael@0 375 * Called when the method finishes. This will be called exactly once for
michael@0 376 * each method invocation, and afterward no other callback methods will be
michael@0 377 * called.
michael@0 378 *
michael@0 379 * @param reason One of the COMPLETE_* values indicating the manner in which
michael@0 380 * the method completed.
michael@0 381 */
michael@0 382 void handleCompletion(in unsigned short reason);
michael@0 383
michael@0 384 const unsigned short COMPLETE_OK = 0;
michael@0 385 const unsigned short COMPLETE_ERROR = 1;
michael@0 386 };
michael@0 387
michael@0 388 [scriptable, function, uuid(9f24948d-24b5-4b1b-b554-7dbd58c1d792)]
michael@0 389 interface nsIContentPref : nsISupports
michael@0 390 {
michael@0 391 readonly attribute AString domain;
michael@0 392 readonly attribute AString name;
michael@0 393 readonly attribute nsIVariant value;
michael@0 394 };

mercurial