nsICookieService 编辑

netwerk/cookie/public/nsICookieService.idlScriptable Provides methods for setting and getting cookies in the context of a page load. Inherits from: nsISupports Last changed in Gecko 1.9 (Firefox 3)

See nsICookieManager and nsICookieManager2 for methods to manipulate the cookie database directly. This separation of interface is mainly historical.

var cookieSvc = Components.classes["@mozilla.org/cookieService;1"]
                  .getService(Components.interfaces.nsICookieService);

Notifications

This service broadcasts the following notifications when the cookie list is changed, or a cookie is rejected:

TopicSubjectData

cookie-changed
Broadcast whenever the cookie list changes in some way. There are four possible data strings for this notification; one notification will be broadcast for each change.

Depending on the Data value, either an nsICookie2 interface pointer representing the cookie object that changed, or an nsIArray of nsICookie2 objects.A keyword indicating what was done to the affected cookie.
deleted
A cookie was deleted. The subject is the deleted cookie.
added
A cookie was added. The subject is the added cookie.
changed
A cookie was changed. The subject is the changed cookie.
batch-deleted
A set of cookies were deleted as part of a purge operation. This typically happens because they have either expired or because the cookie list has grown too large. The subject is an nsIArray of deleted cookies.
cleared
The entire cookie list was cleared. The subject is null.
reload
The entire cookie list was changed, and the observer should reload the list of cookies. The subject is null.
private-cookie-changed
Since Firefox 20 (see bugzilla #837091)
Same as cookie-changed, except used in lieu of cookie-changed for private windows.See cookie-changed.
cookie-rejected

Broadcast whenever the user's preferences cause a cookie to be rejected from being set.

An nsIURI interface pointer representing the URI that attempted to set the cookie.None.

Method overview

string getCookieString(in nsIURI aURI, in nsIChannel aChannel);
string getCookieStringFromHttp(in nsIURI aURI, in nsIURI aFirstURI, in nsIChannel aChannel);
void setCookieString(in nsIURI aURI, in nsIPrompt aPrompt, in string aCookie, in nsIChannel aChannel);
void setCookieStringFromHttp(in nsIURI aURI, in nsIURI aFirstURI, in nsIPrompt aPrompt, in string aCookie, in string aServerTime, in nsIChannel aChannel);

Attributes

AttributeTypeDescription
cookieIconIsVisiblebooleanThis attribute really doesn't belong on this interface. CVS blame will tell you why it is here. It remains until we can find a better home for it.

Methods

getCookieString()

Get the complete cookie string associated with the URI.

 string getCookieString(
   in nsIURI aURI,
   in nsIChannel aChannel
 );
Parameters
aURI
The URI of the document for which cookies are being queried.
aChannel
The channel used to load the document. this parameter may be null, but it is strongly recommended that a non-null value be provided to ensure that the cookie privacy preferences are honored.
Return value

Returns the resulting cookie string.

getCookieStringFromHttp()

Get the complete cookie string associated with the URI.

Note: This function is redundant and will most likely be removed in a future revision of this interface. getCookieString() will query the documentURI property off of nsIHttpChannelInternal if supported, so getCookieString() can be used in place of this method.
 string getCookieStringFromHttp(
   in nsIURI aURI,
   in nsIURI aFirstURI,
   in nsIChannel aChannel
 );
Parameters
aURI
The URI of the document for which cookies are being queried.
aFirstURI
The URI that the user originally typed in or clicked on to initiate the load of the document referenced by aURI.
aChannel
The channel used to load the document. this parameter may be null, but it is strongly recommended that a non-null value be provided to ensure that the cookie privacy preferences are honored.
Return value

Returns the resulting cookie string.

setCookieString()

Set the cookie string associated with the URI.

Note: Should be able to allow null aPrompt, since nsIPrompt can be queried from aChannel.
 void setCookieString(
   in nsIURI aURI,
   in nsIPrompt aPrompt,
   in string aCookie,
   in nsIChannel aChannel
 );
Parameters
aURI
The URI of the document for which cookies are being queried.
aPrompt
The prompt to use for all user-level cookie notifications.
aCookie
The cookie string to set.
aChannel
The channel used to load the document. this parameter may be null, but it is strongly recommended that a non-null value be provided to ensure that the cookie privacy preferences are honored.

setCookieStringFromHttp()

Set the cookie string and expires associated with the URI.

Note: This function is redundant and will most likely be removed in a future revision of this interface. setCookieString() will query the documentURI property off of nsIHttpChannelInternal if supported, and setCookieString() could also query the Date header from the channel if aChannel supports nsIHttpChannel.
 void setCookieStringFromHttp(
   in nsIURI aURI,
   in nsIURI aFirstURI,
   in nsIPrompt aPrompt,
   in string aCookie,
   in string aServerTime,
   in nsIChannel aChannel
 );
Parameters
aURI
The URI of the document for which cookies are being queried.
aFirstURI
The URI that the user originally typed in or clicked on to initiate the load of the document referenced by aURI.
aPrompt
The prompt to use for all user-level cookie notifications.
aCookie
The cookie string to set.
aServerTime
The expiry information of the cookie (the Date header from the HTTP response).
aChannel
The channel used to load the document. this parameter may be null, but it is strongly recommended that a non-null value be provided to ensure that the cookie privacy preferences are honored.

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:52 次

字数:11868

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文