Interface nsIContentPrefService2Type

Content Preferences

Content preferences allow the application to associate arbitrary data, or "preferences", with specific domains, or web "content". Specifically, a content preference is a structure with three values: a domain with which the preference is associated, a name that identifies the preference within its domain, and a value. (See nsIContentPref below.)

For example, if you want to remember the user's preference for a certain zoom level on www.mozilla.org pages, you might store a preference whose domain is "www.mozilla.org", whose name is "zoomLevel", and whose value is the numeric zoom level.

A preference need not have a domain, and in that case the preference is called a "global" preference. This interface doesn't impart any special significance to global preferences; they're simply name-value pairs that aren't associated with any particular domain. As a consumer of this interface, you might choose to let a global preference override all non- global preferences of the same name, for example, for whatever definition of "override" is appropriate for your use case.

Domain Parameters

Many methods of this interface accept a "domain" parameter. Domains may be specified either exactly, like "example.com", or as full URLs, like "http://example.com/foo/bar". In the latter case the API extracts the full domain from the URL, so if you specify "http://foo.bar.example.com/baz", the domain is taken to be "foo.bar.example.com", not "example.com".

Private-Browsing Context Parameters

Many methods also accept a "context" parameter. This parameter relates to private browsing and determines the kind of storage that a method uses, either the usual permanent storage or temporary storage set aside for private browsing sessions.

Pass null to unconditionally use permanent storage. Pass an nsILoadContext to use storage appropriate to the context's usePrivateBrowsing attribute: if usePrivateBrowsing is true, temporary private-browsing storage is used, and otherwise permanent storage is used. A context can be obtained from the window or channel whose content pertains to the preferences being modified or retrieved.

Callbacks

The methods of callback objects are always called asynchronously.

Observers are called after callbacks are called, but they are called in the same turn of the event loop as callbacks.

See nsIContentPrefCallback2 below for more information about callbacks.

Hierarchy

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

  • Registers an observer that will be notified whenever a preference with the given name is set or removed.

    When a set or remove method is called, observers are called after the set or removal completes and after the method's callback is called, and they are called in the same turn of the event loop as the callback.

    The service holds a strong reference to the observer, so the observer must be removed later to avoid leaking it.

    Parameters

    • name: string

      The name of the preferences to observe. Pass null to observe all preference changes regardless of name.

    • observer: nsIContentPrefObserver

      The observer.

    Returns void

  • Extracts and returns the domain from the given string representation of a URI. This is how the API extracts domains from URIs passed to it.

    Returns

    If the given string is a valid URI, the domain of that URI is returned. Otherwise, the string itself is returned.

    Parameters

    Returns string

  • Gets the preference with the given domain and name.

    Parameters

    • domain: string

      The preference's domain.

    • name: string

      The preference's name.

    • context: nsILoadContext

      The private-browsing context, if any.

    • callback: nsIContentPrefCallback2

      handleResult is called once unless no such preference exists, in which case handleResult is not called at all.

    Returns void

  • Gets all the preferences with the given name.

    Parameters

    • name: string

      The preferences' name.

    • context: nsILoadContext

      The private-browsing context, if any.

    • callback: nsIContentPrefCallback2

      handleResult is called once for each preference unless no such preferences exist, in which case handleResult is not called at all.

    Returns void

  • Gets all preferences with the given name whose domains are either the same as or subdomains of the given domain.

    Parameters

    • domain: string

      The preferences' domain.

    • name: string

      The preferences' name.

    • context: nsILoadContext

      The private-browsing context, if any.

    • callback: nsIContentPrefCallback2

      handleResult is called once for each preference. If no such preferences exist, handleResult is not called at all.

    Returns void

  • Synchronously retrieves from the in-memory cache the preference with the given domain and name.

    In addition to caching preference values, the cache also keeps track of preferences that are known not to exist. If the preference is known not to exist, the value attribute of the returned object will be undefined (nsIDataType::VTYPE_VOID).

    If the preference is neither cached nor known not to exist, then null is returned, and get() must be called to determine whether the preference exists.

    Returns

    The preference, or null if no such preference is known to exist.

    Parameters

    • domain: string

      The preference's domain.

    • name: string

      The preference's name.

    • context: nsILoadContext

      The private-browsing context, if any.

    Returns nsIContentPref

  • Synchronously retrieves from the in-memory cache the preference with no domain and the given name.

    As with getCachedByDomainAndName, if the preference is cached then it is returned; if the preference is known not to exist, then the value attribute of the returned object will be undefined; if the preference is neither cached nor known not to exist, then null is returned.

    Returns

    The preference, or null if no such preference is known to exist.

    Parameters

    • name: string

      The preference's name.

    • context: nsILoadContext

      The private-browsing context, if any.

    Returns nsIContentPref

  • Gets the preference with no domain and the given name.

    Parameters

    • name: string

      The preference's name.

    • context: nsILoadContext

      The private-browsing context, if any.

    • callback: nsIContentPrefCallback2

      handleResult is called once unless no such preference exists, in which case handleResult is not called at all.

    Returns void

  • Removes all non-global preferences -- in other words, all preferences that have a domain.

    Parameters

    • context: nsILoadContext

      The private-browsing context, if any.

    • callback: nsIContentPrefCallback2

      handleCompletion is called when the operation completes.

    Returns void

  • Removes all non-global preferences created after and including |since|.

    Parameters

    • since: number

      Timestamp in milliseconds.

    • context: nsILoadContext

      The private-browsing context, if any.

    • callback: nsIContentPrefCallback2

      handleCompletion is called when the operation completes.

    Returns void

  • Removes all global preferences -- in other words, all preferences that have no domain.

    Parameters

    • context: nsILoadContext

      The private-browsing context, if any.

    • callback: nsIContentPrefCallback2

      handleCompletion is called when the operation completes.

    Returns void

  • Removes all preferences with the given domain.

    Parameters

    • domain: string

      The preferences' domain.

    • context: nsILoadContext

      The private-browsing context, if any.

    • callback: nsIContentPrefCallback2

      handleCompletion is called when the operation completes.

    Returns void

  • Removes the preference with the given domain and name.

    Parameters

    • domain: string

      The preference's domain.

    • name: string

      The preference's name.

    • context: nsILoadContext

      The private-browsing context, if any.

    • callback: nsIContentPrefCallback2

      handleCompletion is called when the operation completes.

    Returns void

  • Removes all preferences with the given name regardless of domain, including global preferences with the given name.

    Parameters

    • name: string

      The preferences' name.

    • context: nsILoadContext

      The private-browsing context, if any.

    • callback: nsIContentPrefCallback2

      handleCompletion is called when the operation completes.

    Returns void

  • Removes all preferences whose domains are either the same as or subdomains of the given domain.

    Parameters

    • domain: string

      The preferences' domain.

    • context: nsILoadContext

      The private-browsing context, if any.

    • callback: nsIContentPrefCallback2

      handleCompletion is called when the operation completes.

    Returns void

  • Removes all the preferences with the given name whose domains are either the same as or subdomains of the given domain.

    Parameters

    • domain: string

      The preferences' domain.

    • name: string

      The preferences' name.

    • context: nsILoadContext

      The private-browsing context, if any.

    • callback: nsIContentPrefCallback2

      handleCompletion is called when the operation completes.

    Returns void

  • Removes the preference with no domain and the given name.

    Parameters

    • name: string

      The preference's name.

    • context: nsILoadContext

      The private-browsing context, if any.

    • callback: nsIContentPrefCallback2

      handleCompletion is called when the operation completes.

    Returns void

  • Unregisters an observer for the given name.

    Parameters

    • name: string

      The name for which the observer was registered. Pass null if the observer was added with a null name.

    • observer: nsIContentPrefObserver

      The observer.

    Returns void

  • Sets a preference.

    Parameters

    • domain: string

      The preference's domain.

    • name: string

      The preference's name.

    • value: nsIVariant

      The preference's value.

    • context: nsILoadContext

      The private-browsing context, if any.

    • callback: nsIContentPrefCallback2

      handleCompletion is called when the preference has been stored.

    Returns void

  • Sets a preference with no domain.

    Parameters

    • name: string

      The preference's name.

    • value: nsIVariant

      The preference's value.

    • context: nsILoadContext

      The private-browsing context, if any.

    • callback: nsIContentPrefCallback2

      handleCompletion is called when the preference has been stored.

    Returns void

Generated using TypeDoc