nsIPermissionManager 编辑

The nsIPermissionManager interface is used to persistently store permissions for different object types (cookies, images, and so on) on a site-by-site basis.

netwerk/base/nsIPermissionManager.idlScriptable Please add a summary to this article.   Last changed in Gecko 16 (Firefox 16 / Thunderbird 16 / SeaMonkey 2.13)

Inherits from: nsISupports

Method overview

void add(in nsIURI uri, in string type, in PRUint32 permission, [optional] in PRUint32 expireType, [optional] in PRInt64 expireTime);
void addFromPrincipal(in nsIPrincipal principal, in string type, in PRUint32 permission, [optional] in PRUint32 expireType, [optional] in PRInt64 expireTime);
void remove(in AUTF8String host, in string type);

void removeFromPrincipal(in nsIPrincipal principal, in string type);

void removePermission(in nsIPermission perm);

void removeAllSince(in int64_t since);

void removeAll();
PRUint32 testExactPermission(in nsIURI uri, in string type);
PRUint32 testExactPermissionFromPrincipal(in nsIPrincipal principal, in string type);
PRUint32 testPermission(in nsIURI uri, in string type);
PRUint32 testPermissionFromPrincipal(in nsIPrincipal principal, in string type);

Attributes

AttributeTypeDescription
enumeratornsISimpleEnumeratorEnumerates all stored permissions. Allows access to nsIPermission objects. Read only.

Constants

Permission type constants

ConstantValueDescription
UNKNOWN_ACTION0Default permission when no entry is found for a host. It should not be used by consumers.
ALLOW_ACTION1Permission is allowed.
DENY_ACTION2Permission is denied.
PROMPT_ACTION3Prompt user if the permission is allowed.

Permission expiration constants

ConstantValueDescription
EXPIRE_NEVER0Permission never expires.
EXPIRE_SESSION1Permission expires at end of session.
EXPIRE_TIME2Permission expires at a specified time.

Methods

add()

Add permission information and permission type for a given URI. If the permission already exists for a given type, it will be modified.

void add(
  in nsIURI uri,
  in string type,
  in PRUint32 permission,
  [optional] in PRUint32 expireType,
  [optional] in PRInt64 expireTime
);
Parameters
uri
The URI to add the permission for.
type
A unique, case-sensitive ASCII string identifying the consumer. Consumers should choose this string to be unique, with respect to other consumers.
permission
An integer specifying the permission. See nsIPermissionManager.Permission_type_constants.
expireType
Expiration type of the permission. See nsIPermissionManager.Permission_expiration_constants.
expireTime
Time (in milliseconds since Jan 1 1970 0:00:00) representing expiration of this permission.

addFromPrincipal()

Add permission information and permission type for a given principal. If the permission already exists for a given type, it will be modified. It is internally calling add() method using the nsIURI from the principal.

void addFromPrincipal(
  in nsIPrincipal principal,
  in string type,
  in PRUint32 permission,
  [optional] in PRUint32 expireType,
  [optional] in PRInt64 expireTime
);
Parameters
principal
The principal to add the permission for.
type
A unique, case-sensitive ASCII string identifying the consumer. Consumers should choose this string to be unique, with respect to other consumers.
permission
An integer specifying the permission. See nsIPermissionManager.Permission_type_constants.
expireType
Expiration type of the permission. See nsIPermissionManager.Permission_expiration_constants.
expireTime
Time (in milliseconds since Jan 1 1970 0:00:00) representing expiration of this permission.

remove()

Remove permission information for a given host string and permission type.

void remove(
  in nsIURI uri,
  in string type
);
Parameters
nsIURI
The uri whose permission will be removed.
type
A case-sensitive ASCII string, identifying the type of the permission to be removed. This must have been previously registered using the add() method.

removeFromPrincipal()

Remove permission information for a given principal and permission type.

void removeFromPrincipal(
  in nsIPrincipal principal,
  in string type
);
Parameters
principal
The principal whose permission will be removed.
type
A case-sensitive ASCII string, identifying the type of the permission to be removed. This must have been previously registered using the add() method.

removePermission()

Remove a given permission from the stored permissions.

void removePermission(
  in nsIPermission perm
);
Parameters
nsIPermission
The permission which will be removed.

removeAllSince()

Remove permission information for a given host string and permission type.

void remove(
  in int64_t since
);
Parameters
since
Epoch timestamp. Permission information stored after this timestamp will be removed.

removeAll()

Remove permission information for all URIs.

void removeAll();
Parameters

None.

testExactPermission()

Checks if a URI is permitted to perform an action. This requires an exact hostname match, subdomains are not a match.

PRUint32 testExactPermission(
  in nsIURI uri,
  in string type
);
Parameters
uri
The URI to be tested.
type
A case-sensitive ASCII string, identifying the consumer.
Return value

A PRUint32 representing the permission, or UNKNOWN_ACTION if no permission exists.

testExactPermissionFromPrincipal()

Checks if a principal is permitted to perform an action. See testExactPermission().

PRUint32 testExactPermissionFromPrincipal(
  in nsIPrincipal principal,
  in string type
);
Parameters
principal
The principal to be tested.
type
A case-sensitive ASCII string, identifying the consumer.
Return value

A PRUint32 representing the permission, or UNKNOWN_ACTION if no permission exists.

testPermission()

Checks if a URI is permitted to perform an action.

PRUint32 testPermission(
  in nsIURI uri,
  in string type
);
Parameters
uri
The URI to be tested.
type
A case-sensitive ASCII string, identifying the consumer.
Return value

A PRUint32 representing the permission, or UNKNOWN_ACTION if no permission exists.

testPermissionFromPrincipal()

Checks if a principal is permitted to perform an action.

PRUint32 testPermissionFromPrincipal(
  in nsIPrincipal principal,
  in string type
);
Parameters
principal
The principal to be tested.
type
A case-sensitive ASCII string, identifying the consumer.
Return value

A PRUint32 representing the permission, or UNKNOWN_ACTION if no permission exists.

Remarks

This service broadcasts the following notification when the permission list is changed:

topic : "perm-changed" (PERM_CHANGE_NOTIFICATION) broadcast whenever the permission list changes in some way.

There are four possible data strings for this notification; one notification will be broadcast for each change, and will involve a single permission.

data : "deleted" a permission was deleted. The subject is the deleted nsIPermission.

data : "added" a permission was added. The subject is the added nsIPermission.

data : "changed" a permission was changed. The subject is the new nsIPermission.

data : "cleared" the entire permission list was cleared. The subject is null.

See also

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

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

发布评论

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

词条统计

浏览:41 次

字数:15284

最后编辑:7年前

编辑次数:0 次

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