Interface nsICookieServiceType

nsICookieService

Provides methods for setting and getting cookies in the context of a page load. See nsICookieManager for methods to manipulate the cookie database directly. This separation of interface is mainly historical.

This service broadcasts the notifications detailed below when the cookie list is changed, or a cookie is rejected.

NOTE: observers of these notifications must not attempt to change profile or switch into or out of private browsing mode from within the observer. Doing so will cause undefined behavior. Mutating the cookie list (e.g. by calling methods on nsICookieService and friends) is allowed, but beware that there may be pending notifications you haven't seen yet -- for instance, a "batch-deleted" notification will likely be immediately followed by "added". You may check the state of the cookie list to determine if this is the case.

topic : "cookie-changed" broadcast whenever the cookie list changes in some way. see explanation of data strings below. subject: see below. data : "deleted" a cookie was deleted. the subject is an nsICookie representing the deleted cookie. "added" a cookie was added. the subject is an nsICookie representing the added cookie. "changed" a cookie was changed. the subject is an nsICookie representing the new cookie. (note that host, path, and name are invariant for a given cookie; other parameters may change.) "batch-deleted" a set of cookies was purged (typically, because they have either expired or because the cookie list has grown too large). The subject is an nsIArray of nsICookie's representing the deleted cookies. Note that the array could contain a single cookie. "cleared" the entire cookie list was cleared. the subject is null.

topic : "cookie-rejected" broadcast whenever a cookie was rejected from being set as a result of user prefs. subject: an nsIURI interface pointer representing the URI that attempted to set the cookie. data : none.

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

  • Get the complete cookie string associated with the document's principal. This method is meant to be used for document.cookie only. Any security check about storage-access permission and cookie behavior must be done by the caller.

    Returns

    the resulting cookie string

    Parameters

    • aDocument: Document

      The document.

    Returns string

  • Get the complete cookie string associated with the URI.

    This function is NOT redundant with getCookieString, as the result will be different based on httponly (see bug 178993)

    Returns

    the resulting cookie string

    Parameters

    • aURI: nsIURI

      The URI of the document for which cookies are being queried. file:// URIs (i.e. with an empty host) are allowed, but any other scheme must have a non-empty host. A trailing dot in the host is acceptable, and will be stripped. This argument must not be null.

    • aChannel: nsIChannel

      the channel used to load the document.

    Returns string

  • Batch SQLite operations into one transaction. By default each call to CookieService that affects the underlying SQLite database (add, remove, setCookieString etc.) runs in a separate transaction. If you do this many times in a row, it's faster and suggested to wrap them all in a single transaction by setting all the operations into the callback parameter. Example: test scripts that need to construct a large cookie database.

    Throws

    NS_ERROR_FAILURE if aCallback() fails.

    Throws

    NS_ERROR_NOT_AVAILABLE if the connection is not established.

    Parameters

    • aCallback: nsICookieTransactionCallback

      nsICookieTransactionCallback interface to call

    Returns void

  • Set the cookie string associated with a Document. This method is meant to be used for document.cookie only. Any security check about storage-access permission and cookie behavior must be done by the caller.

    Parameters

    • aDocument: Document

      The document.

    • aCookie: string

      the cookie string to set.

    Returns void

  • Set the cookie string and expires associated with the URI.

    This function is NOT redundant with setCookieString, as the result will be different based on httponly (see bug 178993)

    Parameters

    • aURI: nsIURI

      The URI of the document for which cookies are being queried. file:// URIs (i.e. with an empty host) are allowed, but any other scheme must have a non-empty host. A trailing dot in the host is acceptable, and will be stripped. This argument must not be null.

    • aCookie: string

      the cookie string to set.

    • aChannel: nsIChannel

      the channel used to load the document.

    Returns void

Generated using TypeDoc