The nsICookiePermission interface is used to test for cookie permissions

netwerk/cookie/nsICookiePermission.idlScriptable
Please add a summary to this article.
  Last changed in Gecko 1.9 (Firefox 3)

Inherits from: nsISupports

Method overview

nsCookieAccess canAccess(in nsIURI aURI, in nsIChannel aChannel);
boolean canSetCookie(in nsIURI aURI, in nsIChannel aChannel, in nsICookie2 aCookie, inout boolean aIsSession, inout PRInt64 aExpiry);
nsIURI getOriginatingURI(in nsIChannel aChannel);
void setAccess(in nsIURI aURI, in nsCookieAccess aAccess);

Constants

Constant Value Description
ACCESS_DEFAULT 0 nsCookieAccess's access default value
ACCESS_ALLOW 1 nsCookieAccess's access allow value
ACCESS_DENY 2 nsCookieAccess's access deny value
ACCESS_SESSION 8 Additional values for nsCookieAccess, which are not directly used by any methods on this interface, but are nevertheless convenient to define here. These may be relocated somewhere else if we ever consider freezing this interface.

Methods

canAccess()

Tests whether or not the given URI/channel may access the cookie database, either to set or get cookies.

nsCookieAccess canAccess(
  in nsIURI aURI,
  in nsIURI aFirstURI, Obsolete since Gecko 1.9
  in nsIChannel aChannel
);
Parameters
aURI
The URI trying to access cookies.
aFirstURI
The URI initiated by the user that resulted in aURI being loaded.
aChannel
The channel corresponding to aURI.
Return value

One of the nsCookieAccess values: ACCESS_DEFAULT, ACCESS_ALLOW, or ACCESS_DENY.

canSetCookie()

Tests whether or not the given URI/channel may set a specific cookie. This method is always preceded by a call to canAccess(). It may modify the isSession and expiry attributes of the cookie via the aIsSession and aExpiry parameters, in order to limit or extend the lifetime of the cookie. This is useful, for instance, to downgrade a cookie to session-only if it fails to meet certain criteria.

boolean canSetCookie(
  in nsIURI aURI,
  in nsIChannel aChannel,
  in nsICookie2 aCookie,
  inout boolean aIsSession,
  inout PRInt64 aExpiry
);
Parameters
aURI
The URI trying to set the cookie.
aChannel
The channel corresponding to aURI.
aCookie
The cookie being added to the cookie database.
aIsSession
When canSetCookie is invoked, this is the current isSession attribute of the cookie. canSetCookie may leave this value unchanged to preserve this attribute of the cookie.
aExpiry
When canSetCookie is invoked, this is the current expiry time of the cookie. canSetCookie may leave this value unchanged to preserve this attribute of the cookie.
Return value

true if the cookie can be set.

getOriginatingURI()

Determines the originating URI for a load given a channel, for third-party cookie blocking. This is done by leveraging the loadgroup of the channel to find the root content docshell, and the URI associated with its principal. If the root content docshell or its principal's URI cannot be obtained, this method will throw.

nsIURI getOriginatingURI(
  in nsIChannel aChannel
);
Parameters
aChannel
The channel for the load trying to get or set cookies.
Return value

The originating URI.

setAccess()

Sets cookie access permissions for the given URI. This may result in other URIs being blocked as well, such as URIs that share the same host name.

void setAccess(
  in nsIURI aURI,
  in nsCookieAccess aAccess
);
Parameters
aURI
The URI to block.
aAccess
The new cookie access permissions for the URI.

See also