nsISupports
Last changed in Gecko 58 (Firefox 58 / Thunderbird 58 / SeaMonkey 2.55)This object is created with a "root" value which describes the base point in the preferences "tree" from which this "branch" stems. Preferences are accessed off of this root by using just the final portion of the preference. For example, if this object is created with the root "browser.startup.", the preferences "browser.startup.page", "browser.startup.homepage", and "browser.startup.homepage_override" can be accessed by simply passing "page", "homepage", or "homepage_override" to the various Get/Set methods.
void addObserver(in string aDomain, in nsIObserver aObserver, in boolean aHoldWeak); |
void clearUserPref(in string aPrefName); |
void deleteBranch(in string aStartingAt); |
boolean getBoolPref(in string aPrefName, Requires Gecko 54 [optional] in boolean aDefaultValue); |
string getCharPref(in string aPrefName, Requires Gecko 54 [optional] in string aDefaultValue); |
Requires Gecko 58 utf8tring getStringPref(in string aPrefName, [optional] in utf8string aDefaultValue); |
void getChildList(in string aStartingAt, [optional] out unsigned long aCount, [array, size_is(aCount), retval] out string aChildArray); |
void getComplexValue(in string aPrefName, in nsIIDRef aType, [iid_is(aType), retval] out nsQIResult aValue); |
long getIntPref(in string aPrefName, Requires Gecko 54 [optional] in long aDefaultValue); |
long getPrefType(in string aPrefName); |
void lockPref(in string aPrefName); |
boolean prefHasUserValue(in string aPrefName); |
boolean prefIsLocked(in string aPrefName); |
void removeObserver(in string aDomain, in nsIObserver aObserver); |
void resetBranch(in string aStartingAt); |
void setBoolPref(in string aPrefName, in long aValue); |
void setCharPref(in string aPrefName, in string aValue); |
Requires Gecko 58 void setStringPref(in string aPrefName, in utf8string aValue); |
void setComplexValue(in string aPrefName, in nsIIDRef aType, in nsISupports aValue); |
void setIntPref(in string aPrefName, in long aValue); |
void unlockPref(in string aPrefName); |
Attribute | Type | Description |
root |
string |
Called to get the root on which this branch is based, such as "browser.startup." Read only. |
Constant | Value | Description |
PREF_INVALID |
0 |
long |
PREF_STRING |
32 |
long data type. |
PREF_INT |
64 |
long data type. |
PREF_BOOL |
128 |
long data type. |
Adds a preference change observer. On preference changes, the following arguments will be passed to nsIObserver.observe()
:
aSubject
- The nsIPrefBranch
object (this).
aTopic
- The string defined by NS_PREFBRANCH_PREFCHANGE_TOPIC_ID
aData
- The name of the preference which has changed, relative to the "root" of the aSubject
branch.
aSubject.get*Pref(aData)
will get the new value of the modified preference. For example, if your observer is registered with addObserver("bar.", ...)
on a branch with root "foo."
, modifying the preference "foo.bar.baz"
will trigger the observer, and aData
parameter will be "bar.baz"
.
void addObserver( in string aDomain, in nsIObserver aObserver, in boolean aHoldWeak );
aDomain
prefbranch
and calling addObserver("foo.bar.", ...)
will observe changes to foo.bar.baz
and foo.bar.bzip
.aObserver
var myObserver = { observe: function(aSubject, aTopic, aData) { //do stuff here } }
aHoldWeak
true
holds a weak reference to aObserver
. The object must implement the nsISupportsWeakReference
interface or this will fail. false
holds a strong reference to aObserver
.Called to clear a user set value from a specific preference. This will, in effect, reset the value to the default value. If no default value exists the preference will cease to exist.
void clearUserPref( in string aPrefName );
aPrefName
Note: Prior to Gecko 6.0, this method would throw an exception if there was no user value set for the specified preference. Now, this method never throws. Instead, it simply does nothing.
Called to remove all of the preferences referenced by this branch.
void deleteBranch( in string aStartingAt );
aStartingAt
Called to get the state of an individual boolean preference.
boolean getBoolPref( in string aPrefName, [optional] in boolean aDefaultValue );
aPrefName
aDefaultValue
Requires Gecko 54The value of the requested boolean preference.
Called to get the state of an individual string preference.
string getCharPref( in string aPrefName, [optional] in string aDefaultValue );
aPrefName
aDefaultValue
Requires Gecko 54Returns string
- The value of the requested string preference.
Called to get the state of an individual UTF-8 string preference.
utf8string getStringPref( in string aPrefName, [optional] in utf8string aDefaultValue );
aPrefName
aDefaultValue
Returns utf8tring
- The value of the requested string preference.
Returns an array of strings representing the child preferences of the root
of this branch.
(To call from javascript use children = nsIPrefBranch.getChildList("",obj)
, which will fill in obj.value with the count and return an array of keys! (It is not void in javascript)
void getChildList( in string aStartingAt, out unsigned long aCount, [array, size_is(aCount), retval] out string aChildArray );
aStartingAt
aCount
Optional from Gecko 2.0aChildArray
Called to get the state of an individual complex preference. A complex preference is a preference which represents an XPCOM object that can not be easily represented using a standard boolean, integer or string value.
void getComplexValue( in string aPrefName, in nsIIDRef aType, [iid_is(aType), retval] out nsQIResult aValue );
aPrefName
aType
NsILocalFile
NsISupportsString
(UniChar) (removed as of Gecko 58 in favor of getStringPref)NsIPrefLocalizedString
(Localized UniChar)NsIFileSpec
(deprecated - to be removed eventually)aValue
Called to get the state of an individual integer preference.
long getIntPref( in string aPrefName, [optional] in long aDefaultValue );
aPrefName
aDefaultValue
Requires Gecko 54Returns long
- The value of the requested integer preference.
Called to determine the type of a specific preference.
long getPrefType( in string aPrefName );
aPrefName
Returns long
- A value representing the type of the preference. This value will be PREF_STRING
, PREF_INT, PREF_BOOL,
or PREF_INVALID
.
Called to lock a specific preference. Locking a preference will cause the preference service to always return the default value regardless of whether there is a user set value or not.
void lockPref( in string aPrefName );
aPrefName
Called to check if a specific preference has a user value associated to it.
false
for such a preference and the preference will not be saved to a file by nsIPrefService.savePrefFile()
.boolean prefHasUserValue( in string aPrefName );
aPrefName
Returns boolean
- true
The preference has a user set value. false
The preference only has a default value.
Called to check if a specific preference is locked. If a preference is locked calling its Get method will always return the default value.
boolean prefIsLocked( in string aPrefName );
aPrefName
Returns boolean
- true
The preference is locked. false
The preference is not locked.
Remove a preference change observer.
removeObserver
method on the same nsIPrefBranch instance on which you called addObserver method in order to remove aObserver
; otherwise, the observer will not be removed.void removeObserver( in string aDomain, in nsIObserver aObserver );
aDomain
aObserver
Called to reset all of the preferences referenced by this branch to their default values.
void resetBranch( in string aStartingAt );
aStartingAt
Called to set the state of an individual boolean preference.
void setBoolPref( in string aPrefName, in long aValue );
aPrefName
aValue
Called to set the state of an individual string preference.
void setCharPref( in string aPrefName, in string aValue );
aPrefName
aValue
Called to set the state of an individual UTF-8 string preference.
void setStringPref( in string aPrefName, in utf8string aValue );
aPrefName
aValue
Called to set the state of an individual complex preference. A complex preference is a preference which represents an XPCOM object that can not be easily represented using a standard boolean, integer or string value.
void setComplexValue( in string aPrefName, in nsIIDRef aType, in nsISupports aValue );
aPrefName
aType
NsILocalFile
NsISupportsString
(UniChar) (removed as of Gecko 58 in favor of setStringPref)NsIPrefLocalizedString
(Localized UniChar)NsIFileSpec
(deprecated - to be removed eventually)aValue
Called to set the state of an individual integer preference.
void setIntPref( in string aPrefName, in long aValue );
aPrefName
aValue
Called to unlock a specific preference. Unlocking a previously locked preference allows the preference service to once again return the user set value of the preference.
void unlockPref( in string aPrefName );
aPrefName
Registering as a preference observer can open an object to potential cyclical references which will cause memory leaks. These cycles generally occur because an object both registers itself as an observer (causing the branch to hold a reference to the observer) and holds a reference to the branch object for the purpose of getting/setting preference values. There are 3 approaches which have been implemented in an attempt to avoid these situations:
nsISupportsWeakReference
. Any consumer may hold a weak reference to it instead of a strong one.The list of registered observers may be changed during the dispatch of nsPref:changed notification. However, the observers are not guaranteed to be notified in any particular order, so you can't be sure whether the added/removed observer will be called during the notification when it is added/removed.
It is possible to change preferences during the notification.
It is not safe to change observers during this callback in releases before Gecko 1.9. If you want a safe way to remove a preference observer, please use an nsITimer
.