Interface nsIPrefBranchType

The nsIPrefBranch interface is used to manipulate the preferences data. This object may be obtained from the preferences service (nsIPrefService) and used to get and set default and/or user preferences across the application.

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.

See

nsIPrefService

Hierarchy

Properties

root: string

Called to get the root on which this branch is based, such as "browser.startup."

Methods

  • Increases the reference count for this interface. The associated instance will not be deleted unless the reference count is returned to zero.

    Returns

    The resulting reference count.

    Returns number

  • Parameters

    • aIID: object
    • Optional aInstancePtr: object

    Returns any

  • A run time mechanism for interface discovery.

    Returns

    NS_OK if the interface is supported by the associated instance, NS_NOINTERFACE if it is not.

    aInstancePtr must not be null.

    Parameters

    • aIID: object

      [in] A requested interface IID

    • aInstancePtr: object

      [out] A pointer to an interface pointer to receive the result.

    Returns void

  • Decreases the reference count for this interface. Generally, if the reference count returns to zero, the associated instance is deleted.

    Returns

    The resulting reference count.

    Returns number

  • Add a preference change observer. On preference changes, the following arguments will be passed to the nsIObserver.observe() method: 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".

    Note

    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.

    1. The nsPrefBranch object supports nsISupportsWeakReference. Any consumer may hold a weak reference to it instead of a strong one.
    2. The nsPrefBranch object listens for xpcom-shutdown and frees all of the objects currently in its observer list. This ensures that long lived objects (services for example) will be freed correctly.
    3. The observer can request to be held as a weak reference when it is registered. This insures that shorter lived objects (say one tied to an open window) will not fall into the cyclical reference trap.

    Note

    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.

    Note

    It is possible to change preferences during the notification.

    Note

    It is not safe to change observers during this callback in Gecko releases before 1.9. If you want a safe way to remove a pref observer, please use an nsITimer.

    See

    • nsIObserver
    • removeObserver

    Parameters

    • aDomain: string

      The preference on which to listen for changes. This can be the name of an entire branch to observe. e.g. Holding the "root" prefbranch and calling addObserver("foo.bar.", ...) will observe changes to foo.bar.baz and foo.bar.bzip

    • aObserver: nsIObserver

      The object to be notified if the preference changes.

    • aHoldWeak: boolean

      true Hold a weak reference to |aObserver|. The object must implement the nsISupportsWeakReference interface or this will fail. false Hold a strong reference to |aObserver|.

    Returns void

  • 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.

    Note

    This method does nothing if this object is a default branch.

    Parameters

    • aPrefName: string

      The preference to be cleared.

    Returns void

  • Called to remove all of the preferences referenced by this branch.

    Note

    This method can be called on either a default or user branch but, in effect, always operates on both.

    Throws

    Error The preference(s) do not exist or an error occurred.

    Parameters

    • aStartingAt: string

      The point on the branch at which to start the deleting preferences. Pass in "" to remove all preferences referenced by this branch.

    Returns void

  • Called to get the state of an individual boolean preference.

    Returns

    boolean The value of the requested boolean preference.

    See

    setBoolPref

    Parameters

    • aPrefName: string

      The boolean preference to get the state of.

    • aDefaultValue: boolean

      The value to return if the preference is not set.

    Returns boolean

  • Parameters

    • aPrefName: string

    Returns boolean

  • Called to get the state of an individual ascii string preference.

    Returns

    ACString The value of the requested string preference.

    See

    setCharPref

    Parameters

    • aPrefName: string

      The string preference to retrieve.

    • aDefaultValue: string

      The string to return if the preference is not set.

    Returns string

  • Parameters

    • aPrefName: string

    Returns string

  • 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.

    Throws

    Error The value does not exist or is the wrong type.

    See

    setComplexValue

    Parameters

    • aPrefName: string

      The complex preference to get the value of.

    • aType: object

      The XPCOM interface that this complex preference represents. Interfaces currently supported are:

      • nsIFile
      • nsIPrefLocalizedString (Localized UniChar)
    • aValue: object

      The XPCOM object into which to the complex preference value should be retrieved.

    Returns void

  • Called to get the state of an individual floating-point preference. "Floating point" preferences are really string preferences that are converted to floating point numbers.

    Returns

    float The value of the requested floating point preference.

    See

    setCharPref

    Parameters

    • aPrefName: string

      The floating point preference to get the state of.

    • aDefaultValue: number

      The value to return if the preference is not set.

    Returns number

  • Parameters

    • aPrefName: string

    Returns number

  • Called to get the state of an individual integer preference.

    Returns

    long The value of the requested integer preference.

    See

    setIntPref

    Parameters

    • aPrefName: string

      The integer preference to get the value of.

    • aDefaultValue: number

      The value to return if the preference is not set.

    Returns number

  • Parameters

    • aPrefName: string

    Returns number

  • Called to determine the type of a specific preference.

    Returns

    long A value representing the type of the preference. This value will be PREF_STRING, PREF_INT, or PREF_BOOL.

    Parameters

    • aPrefName: string

      The preference to get the type of.

    Returns number

  • Called to get the state of an individual unicode string preference.

    Returns

    AUTF8String The value of the requested string preference.

    See

    setStringPref

    Parameters

    • aPrefName: string

      The string preference to retrieve.

    • aDefaultValue: string

      The string to return if the preference is not set.

    Returns string

  • 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.

    Note

    This method can be called on either a default or user branch but, in effect, always operates on the default branch.

    Throws

    Error The preference does not exist or an error occurred.

    See

    unlockPref

    Parameters

    • aPrefName: string

      The preference to be locked.

    Returns void

  • Called to check if a specific preference has a default value associated to it.

    Note

    This method can be called on either a default or user branch but, in effect, always operates on the user branch.

    Note

    This method can be used to distinguish between a built-in preference and a user-added preference.

    Returns

    boolean true The preference has a default value. false The preference only has a user value.

    Parameters

    • aPrefName: string

      The preference to be tested.

    Returns boolean

  • Called to check if a specific preference has a user value associated to it.

    Note

    This method can be called on either a default or user branch but, in effect, always operates on the user branch.

    Note

    If a preference was manually set to a value that equals the default value, then the preference no longer has a user set value, i.e. it is considered reset to its default value. In particular, this method will return false for such a preference and the preference will not be saved to a file by nsIPrefService.savePrefFile.

    Returns

    boolean true The preference has a user set value. false The preference only has a default value.

    Parameters

    • aPrefName: string

      The preference to be tested.

    Returns boolean

  • Called to check if a specific preference is locked. If a preference is locked calling its Get method will always return the default value.

    Note

    This method can be called on either a default or user branch but, in effect, always operates on the default branch.

    Returns

    boolean true The preference is locked. false The preference is not locked.

    See

    • lockPref
    • unlockPref

    Parameters

    • aPrefName: string

      The preference to be tested.

    Returns boolean

  • Called to check if a specific preference has been sanitized. If a preference is sanitized, any user value the preference may have will not be present in a sub-process. A preference is never sanitized in the parent process; it is only marked as sanitized when it is converted to a dom::Pref for serialization to a child process.

    Note

    This method can be called on either a default or user branch but it makes no difference.

    Returns

    boolean true The preference is sanitized. false The preference is not sanitized.

    Parameters

    • aPrefName: string

      The preference to be tested.

    Returns boolean

  • Remove a preference change observer.

    Note

    Note that you must call removeObserver() on the same nsIPrefBranch instance on which you called addObserver() in order to remove aObserver; otherwise, the observer will not be removed.

    See

    • nsIObserver
    • addObserver

    Parameters

    • aDomain: string

      The preference which is being observed for changes.

    • aObserver: nsIObserver

      An observer previously registered with addObserver().

    Returns void

  • Called to reset all of the preferences referenced by this branch to their default values.

    Note

    This method can be called on either a default or user branch but, in effect, always operates on the user branch.

    Throws

    Error The preference(s) do not exist or an error occurred.

    Parameters

    • aStartingAt: string

      The point on the branch at which to start the resetting preferences to their default values. Pass in "" to reset all preferences referenced by this branch.

    Returns void

  • Called to set the state of an individual boolean preference.

    Throws

    Error if setting failed or the preference has a default value of a type other than boolean.

    See

    getBoolPref

    Parameters

    • aPrefName: string

      The boolean preference to set the state of.

    • aValue: boolean

      The boolean value to set the preference to.

    Returns void

  • Called to set the state of an individual ascii string preference.

    Throws

    Error if setting failed or the preference has a default value of a type other than string.

    See

    getCharPref

    Parameters

    • aPrefName: string

      The string preference to set.

    • aValue: string

      The string value to set the preference to.

    Returns void

  • 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.

    Throws

    Error if setting failed or the value is the wrong type.

    See

    getComplexValue

    Parameters

    • aPrefName: string

      The complex preference to set the value of.

    • aType: object

      The XPCOM interface that this complex preference represents. Interfaces currently supported are:

      • nsIFile
      • nsISupportsString (UniChar) (deprecated; see setStringPref)
      • nsIPrefLocalizedString (Localized UniChar)
    • aValue: nsISupports

      The XPCOM object from which to set the complex preference value.

    Returns void

  • Called to set the state of an individual integer preference.

    Throws

    Error if setting failed or the preference has a default value of a type other than integer.

    See

    getIntPref

    Parameters

    • aPrefName: string

      The integer preference to set the value of.

    • aValue: number

      The integer value to set the preference to.

    Returns void

  • Called to set the state of an individual unicode string preference.

    Throws

    Error if setting failed or the preference has a default value of a type other than string.

    See

    getStringPref

    Parameters

    • aPrefName: string

      The string preference to set.

    • aValue: string

      The string value to set the preference to.

    Returns void

  • 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.

    Note

    This method can be called on either a default or user branch but, in effect, always operates on the default branch.

    Throws

    Error The preference does not exist or an error occurred.

    See

    lockPref

    Parameters

    • aPrefName: string

      The preference to be unlocked.

    Returns void

Generated using TypeDoc