nsIContentPrefService
From MDC
This article covers features introduced in Firefox 3
nsIContentPrefService offers a way for extensions and browser code to save preferences for specific URIs. Preferences are saved as key/value pairs on a per-URI basis. See Using content preferences for examples.
Contents |
nsIContentPrefService is defined in toolkit/components/contentprefs/public/nsIContentPrefService.idl. It is scriptable and
unfrozen (hasn't changed since Mozilla 1.9).
Inherits from: nsISupports
Implemented by: @mozilla.org/content-pref/service;1. To create an instance, use:
var prefService = Components.classes["@mozilla.org/content-pref/service;1"]
.getService(Components.interfaces.nsIContentPrefService);
[edit] Method overview
void addObserver(in AString aName, in nsIContentPrefObserver aObserver);
|
nsIVariant getPref(in nsIURI aURI, in AString aName);
|
nsIPropertyBag2 getPrefs(in nsIURI aURI);
|
boolean hasPref(in nsIURI aURI, in AString aName);
|
void removeObserver(in AString aName, in nsIContentPrefObserver aObserver);
|
void removePref(in nsIURI aURI, in AString aName);
|
void setPref(in nsIURI aURI, in AString aName, in nsIVariant aValue);
|
[edit] Attributes
| Attribute | Type | Description |
grouper
| nsIContentURIGrouper
| The component that the service uses to determine the groups to which URIs belong. By default, this is the "hostname grouper," which groups URIs by full hostname (in otherwords, by site). |
[edit] Methods
[edit] getPref()
Returns the value of a preference saved for a particular URI.
nsIVariant getPref( in nsIURI aURI, in AString aName );
[edit] Parameters
- aURI
- The URI for which to retrieve a preference. Specify
nullto get the preference from the global preference space; those preferences apply to all URIs. - aName
- The name of the preference whose value is to be retrieved.
[edit] Return value
The preference's value is returned; this value may be a string, integer, boolean, or any other value. The result may be null (nsIDataType:VTYPE_EMPTY) if the preference's value is either null, or undefined (nsIDataType:VTYPE_VOID) if there is no saved preference by the specified name.
[edit] setPref()
Sets the value of a preference for a particular URI.
nsIVariant setPref( in nsIURI aURI, in AString aName, in nsIVariant aValue );
[edit] Parameters
- aURI
- The URI for which to set a preference. Specify
nullto set the preference in the global preference space; those preferences apply to all URIs. - aName
- The name of the preference whose value is to be set.
- aValue
- The value to assign to the preference.
[edit] hasPref()
Determines whether or not a preference exists.
boolean hasPref( in nsIURI aURI, in AString aName );
[edit] Parameters
- aURI
- The URI for which to check for the existence of a preference, or
nullto check the global preference space. - aName
- The name of the preference whose existence is to be determined.
[edit] Return value
true if the preference exists; otherwise false.
[edit] removePref()
Removes the specified preference.
void removePref( in nsIURI aURI, in AString aName );
[edit] Parameters
- aURI
- The URI for which the preference is to be removed, or
nullto remove the preference from the global preference space. - aName
- The name of the preference to delete.
[edit] getPrefs()
Returns an nsIPropertyBag2 containing all preferences and their values for the specified URI.
nsIPropertyBag2 getPrefs( in nsIURI aURI, );
[edit] Parameters
- aURI
- The URI whose preferences you wish to retrieve, or
nullto retrieve the global preferences.
[edit] Return value
The result is an nsIPropertyBag2 containing the preferences and their values.
[edit] addObserver()
Adds an observer that monitors a preference for changes.
void addObserver( in AString aName, in nsIContentPrefObserver aObserver );
[edit] Parameters
- aName
- The name of the preference to observe. You may specify
nullto add a generic observer that is notified of all preference changes. - aObserver
- The name of an object implementing
nsIContentPrefObserverthat will receive notifications of changes to the preference's value.
[edit] removeObserver()
Removes an observer that's presently monitoring a preference for changes.
void addObserver( in AString aName, in nsIContentPrefObserver aObserver );
[edit] Parameters
- aName
- The name of the preference to stop observing. You may specify
nullto remove a generic observer that is monitoring all preference changes. - aObserver
- The name of the observer that will cease receive notifications of changes to the preference's value.