Bug 1043136 - Only prompt for certain permissions when action is unknown. r=mfinkle

This commit is contained in:
Jim Chen 2014-07-29 07:39:00 -04:00
Родитель 4d1e4fdf93
Коммит 644fa28b7a
1 изменённых файлов: 11 добавлений и 3 удалений

Просмотреть файл

@ -14,6 +14,12 @@ const kEntities = { "geolocation": "geolocation",
"desktop-notification": "desktopNotification",
"contacts": "contacts" };
// For these types, prompt for permission if action is unknown.
const PROMPT_FOR_UNKNOWN = [
"desktop-notification",
"geolocation",
];
function ContentPermissionPrompt() {}
ContentPermissionPrompt.prototype = {
@ -21,18 +27,19 @@ ContentPermissionPrompt.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPermissionPrompt]),
handleExistingPermission: function handleExistingPermission(request, type, isApp) {
handleExistingPermission: function handleExistingPermission(request, type, denyUnknown) {
let result = Services.perms.testExactPermissionFromPrincipal(request.principal, type);
if (result == Ci.nsIPermissionManager.ALLOW_ACTION) {
request.allow();
return true;
}
if (result == Ci.nsIPermissionManager.DENY_ACTION) {
request.cancel();
return true;
}
if (isApp && (result == Ci.nsIPermissionManager.UNKNOWN_ACTION && !!kEntities[type])) {
if (denyUnknown && result == Ci.nsIPermissionManager.UNKNOWN_ACTION) {
request.cancel();
return true;
}
@ -73,7 +80,8 @@ ContentPermissionPrompt.prototype = {
// Returns true if the request was handled
let access = (perm.access && perm.access !== "unused") ?
(perm.type + "-" + perm.access) : perm.type;
if (this.handleExistingPermission(request, access, isApp))
if (this.handleExistingPermission(request, access,
/* denyUnknown */ isApp || PROMPT_FOR_UNKNOWN.indexOf(perm.type) < 0))
return;
let chromeWin = this.getChromeForRequest(request);