2012-03-17 02:23:28 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2012-11-30 21:32:05 +04:00
|
|
|
"use strict"
|
|
|
|
|
2013-05-23 19:52:04 +04:00
|
|
|
function debug(str) {
|
2014-02-10 00:34:40 +04:00
|
|
|
//dump("-*- ContentPermissionPrompt: " + str + "\n");
|
2012-10-25 00:19:01 +04:00
|
|
|
}
|
|
|
|
|
2012-03-17 02:23:28 +04:00
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cr = Components.results;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
const Cc = Components.classes;
|
|
|
|
|
2014-02-10 00:34:40 +04:00
|
|
|
const PROMPT_FOR_UNKNOWN = ["audio-capture",
|
|
|
|
"desktop-notification",
|
|
|
|
"geolocation",
|
|
|
|
"video-capture"];
|
2013-09-27 15:59:31 +04:00
|
|
|
// Due to privary issue, permission requests like GetUserMedia should prompt
|
|
|
|
// every time instead of providing session persistence.
|
2014-02-10 00:34:40 +04:00
|
|
|
const PERMISSION_NO_SESSION = ["audio-capture", "video-capture"];
|
|
|
|
const ALLOW_MULTIPLE_REQUESTS = ["audio-capture", "video-capture"];
|
2012-11-30 21:32:05 +04:00
|
|
|
|
2012-03-17 02:23:28 +04:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2012-09-12 22:00:55 +04:00
|
|
|
Cu.import("resource://gre/modules/Webapps.jsm");
|
2012-10-03 09:38:03 +04:00
|
|
|
Cu.import("resource://gre/modules/AppsUtils.jsm");
|
2012-10-25 00:19:01 +04:00
|
|
|
Cu.import("resource://gre/modules/PermissionsInstaller.jsm");
|
2012-12-15 05:32:30 +04:00
|
|
|
Cu.import("resource://gre/modules/PermissionsTable.jsm");
|
2012-10-25 00:19:01 +04:00
|
|
|
|
|
|
|
var permissionManager = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager);
|
|
|
|
var secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager);
|
|
|
|
|
2013-10-04 20:41:57 +04:00
|
|
|
let permissionSpecificChecker = {};
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this,
|
|
|
|
"AudioManager",
|
|
|
|
"@mozilla.org/telephony/audiomanager;1",
|
|
|
|
"nsIAudioManager");
|
|
|
|
|
2014-04-07 17:59:48 +04:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "SystemAppProxy",
|
|
|
|
"resource://gre/modules/SystemAppProxy.jsm");
|
|
|
|
|
2014-05-13 09:58:04 +04:00
|
|
|
/**
|
|
|
|
* Determine if a permission should be prompt to user or not.
|
|
|
|
*
|
|
|
|
* @param aPerm requested permission
|
|
|
|
* @param aAction the action according to principal
|
|
|
|
* @return true if prompt is required
|
|
|
|
*/
|
|
|
|
function shouldPrompt(aPerm, aAction) {
|
|
|
|
return ((aAction == Ci.nsIPermissionManager.PROMPT_ACTION) ||
|
|
|
|
(aAction == Ci.nsIPermissionManager.UNKNOWN_ACTION &&
|
|
|
|
PROMPT_FOR_UNKNOWN.indexOf(aPerm) >= 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the default choices for the requested permissions
|
|
|
|
*
|
|
|
|
* @param aTypesInfo requested permissions
|
|
|
|
* @return the default choices for permissions with options, return
|
|
|
|
* undefined if no option in all requested permissions.
|
|
|
|
*/
|
|
|
|
function buildDefaultChoices(aTypesInfo) {
|
|
|
|
let choices;
|
|
|
|
for (let type of aTypesInfo) {
|
|
|
|
if (type.options.length > 0) {
|
|
|
|
if (!choices) {
|
|
|
|
choices = {};
|
|
|
|
}
|
|
|
|
choices[type.access] = type.options[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return choices;
|
|
|
|
}
|
|
|
|
|
2014-02-10 00:34:40 +04:00
|
|
|
/**
|
|
|
|
* aTypesInfo is an array of {permission, access, action, deny} which keeps
|
|
|
|
* the information of each permission. This arrary is initialized in
|
|
|
|
* ContentPermissionPrompt.prompt and used among functions.
|
|
|
|
*
|
|
|
|
* aTypesInfo[].permission : permission name
|
|
|
|
* aTypesInfo[].access : permission name + request.access
|
|
|
|
* aTypesInfo[].action : the default action of this permission
|
|
|
|
* aTypesInfo[].deny : true if security manager denied this app's origin
|
|
|
|
* principal.
|
|
|
|
* Note:
|
|
|
|
* aTypesInfo[].permission will be sent to prompt only when
|
|
|
|
* aTypesInfo[].action is PROMPT_ACTION and aTypesInfo[].deny is false.
|
|
|
|
*/
|
|
|
|
function rememberPermission(aTypesInfo, aPrincipal, aSession)
|
2012-10-25 00:19:01 +04:00
|
|
|
{
|
|
|
|
function convertPermToAllow(aPerm, aPrincipal)
|
|
|
|
{
|
|
|
|
let type =
|
|
|
|
permissionManager.testExactPermissionFromPrincipal(aPrincipal, aPerm);
|
2014-05-13 09:58:04 +04:00
|
|
|
if (shouldPrompt(aPerm, type)) {
|
2014-02-10 00:34:40 +04:00
|
|
|
debug("add " + aPerm + " to permission manager with ALLOW_ACTION");
|
2013-01-06 02:02:29 +04:00
|
|
|
if (!aSession) {
|
|
|
|
permissionManager.addFromPrincipal(aPrincipal,
|
|
|
|
aPerm,
|
|
|
|
Ci.nsIPermissionManager.ALLOW_ACTION);
|
2014-02-10 00:34:40 +04:00
|
|
|
} else if (PERMISSION_NO_SESSION.indexOf(aPerm) < 0) {
|
2013-01-06 02:02:29 +04:00
|
|
|
permissionManager.addFromPrincipal(aPrincipal,
|
|
|
|
aPerm,
|
|
|
|
Ci.nsIPermissionManager.ALLOW_ACTION,
|
|
|
|
Ci.nsIPermissionManager.EXPIRE_SESSION, 0);
|
|
|
|
}
|
2012-10-25 00:19:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 00:34:40 +04:00
|
|
|
for (let i in aTypesInfo) {
|
|
|
|
// Expand the permission to see if we have multiple access properties
|
|
|
|
// to convert
|
|
|
|
let perm = aTypesInfo[i].permission;
|
|
|
|
let access = PermissionsTable[perm].access;
|
|
|
|
if (access) {
|
|
|
|
for (let idx in access) {
|
|
|
|
convertPermToAllow(perm + "-" + access[idx], aPrincipal);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
convertPermToAllow(perm, aPrincipal);
|
2012-10-25 00:19:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 02:23:28 +04:00
|
|
|
|
|
|
|
function ContentPermissionPrompt() {}
|
|
|
|
|
|
|
|
ContentPermissionPrompt.prototype = {
|
|
|
|
|
2014-02-10 00:34:40 +04:00
|
|
|
handleExistingPermission: function handleExistingPermission(request,
|
|
|
|
typesInfo) {
|
|
|
|
typesInfo.forEach(function(type) {
|
|
|
|
type.action =
|
|
|
|
Services.perms.testExactPermissionFromPrincipal(request.principal,
|
|
|
|
type.access);
|
2014-05-13 09:58:04 +04:00
|
|
|
if (shouldPrompt(type.access, type.action)) {
|
2014-02-10 00:34:40 +04:00
|
|
|
type.action = Ci.nsIPermissionManager.PROMPT_ACTION;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-05-13 09:58:04 +04:00
|
|
|
// If all permissions are allowed already and no more than one option,
|
|
|
|
// call allow() without prompting.
|
2014-02-10 00:34:40 +04:00
|
|
|
let checkAllowPermission = function(type) {
|
2014-05-13 09:58:04 +04:00
|
|
|
if (type.action == Ci.nsIPermissionManager.ALLOW_ACTION &&
|
|
|
|
type.options.length <= 1) {
|
2014-02-10 00:34:40 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (typesInfo.every(checkAllowPermission)) {
|
|
|
|
debug("all permission requests are allowed");
|
2014-05-13 09:58:04 +04:00
|
|
|
request.allow(buildDefaultChoices(typesInfo));
|
2012-03-17 02:23:28 +04:00
|
|
|
return true;
|
|
|
|
}
|
2014-02-10 00:34:40 +04:00
|
|
|
|
|
|
|
// If all permissions are DENY_ACTION or UNKNOWN_ACTION, call cancel()
|
|
|
|
// without prompting.
|
|
|
|
let checkDenyPermission = function(type) {
|
|
|
|
if (type.action == Ci.nsIPermissionManager.DENY_ACTION ||
|
|
|
|
type.action == Ci.nsIPermissionManager.UNKNOWN_ACTION) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (typesInfo.every(checkDenyPermission)) {
|
|
|
|
debug("all permission requests are denied");
|
2012-03-17 02:23:28 +04:00
|
|
|
request.cancel();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2014-02-10 00:34:40 +04:00
|
|
|
// multiple requests should be audio and video
|
|
|
|
checkMultipleRequest: function checkMultipleRequest(typesInfo) {
|
|
|
|
if (typesInfo.length == 1) {
|
|
|
|
return true;
|
|
|
|
} else if (typesInfo.length > 1) {
|
|
|
|
let checkIfAllowMultiRequest = function(type) {
|
|
|
|
return (ALLOW_MULTIPLE_REQUESTS.indexOf(type.access) !== -1);
|
|
|
|
}
|
|
|
|
if (typesInfo.every(checkIfAllowMultiRequest)) {
|
|
|
|
debug("legal multiple requests");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
handledByApp: function handledByApp(request, typesInfo) {
|
2013-01-10 17:56:45 +04:00
|
|
|
if (request.principal.appId == Ci.nsIScriptSecurityManager.NO_APP_ID ||
|
|
|
|
request.principal.appId == Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID) {
|
|
|
|
// This should not really happen
|
|
|
|
request.cancel();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let appsService = Cc["@mozilla.org/AppsService;1"]
|
|
|
|
.getService(Ci.nsIAppsService);
|
|
|
|
let app = appsService.getAppByLocalId(request.principal.appId);
|
|
|
|
|
2014-02-10 00:34:40 +04:00
|
|
|
// Check each permission if it's denied by permission manager with app's
|
|
|
|
// URL.
|
|
|
|
let notDenyAppPrincipal = function(type) {
|
|
|
|
let url = Services.io.newURI(app.origin, null, null);
|
|
|
|
let principal = secMan.getAppCodebasePrincipal(url,
|
|
|
|
request.principal.appId,
|
|
|
|
/*mozbrowser*/false);
|
|
|
|
let result = Services.perms.testExactPermissionFromPrincipal(principal,
|
|
|
|
type.access);
|
|
|
|
|
|
|
|
if (result == Ci.nsIPermissionManager.ALLOW_ACTION ||
|
|
|
|
result == Ci.nsIPermissionManager.PROMPT_ACTION) {
|
|
|
|
type.deny = false;
|
|
|
|
}
|
|
|
|
return !type.deny;
|
|
|
|
}
|
2014-05-13 09:58:04 +04:00
|
|
|
// Cancel the entire request if one of the requested permissions is denied
|
|
|
|
if (!typesInfo.every(notDenyAppPrincipal)) {
|
2014-02-10 00:34:40 +04:00
|
|
|
request.cancel();
|
|
|
|
return true;
|
2013-01-10 17:56:45 +04:00
|
|
|
}
|
|
|
|
|
2014-02-10 00:34:40 +04:00
|
|
|
return false;
|
2013-01-10 17:56:45 +04:00
|
|
|
},
|
|
|
|
|
2014-02-10 00:34:40 +04:00
|
|
|
handledByPermissionType: function handledByPermissionType(request, typesInfo) {
|
|
|
|
for (let i in typesInfo) {
|
|
|
|
if (permissionSpecificChecker.hasOwnProperty(typesInfo[i].permission) &&
|
|
|
|
permissionSpecificChecker[typesInfo[i].permission](request)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2013-10-04 20:41:57 +04:00
|
|
|
},
|
|
|
|
|
2013-05-23 19:52:04 +04:00
|
|
|
_id: 0,
|
2012-03-17 02:23:28 +04:00
|
|
|
prompt: function(request) {
|
2014-02-10 00:34:40 +04:00
|
|
|
// Initialize the typesInfo and set the default value.
|
|
|
|
let typesInfo = [];
|
|
|
|
let perms = request.types.QueryInterface(Ci.nsIArray);
|
|
|
|
for (let idx = 0; idx < perms.length; idx++) {
|
|
|
|
let perm = perms.queryElementAt(idx, Ci.nsIContentPermissionType);
|
|
|
|
let tmp = {
|
|
|
|
permission: perm.type,
|
|
|
|
access: (perm.access && perm.access !== "unused") ?
|
|
|
|
perm.type + "-" + perm.access : perm.type,
|
2013-09-10 19:41:59 +04:00
|
|
|
options: [],
|
2014-02-10 00:34:40 +04:00
|
|
|
deny: true,
|
|
|
|
action: Ci.nsIPermissionManager.UNKNOWN_ACTION
|
|
|
|
};
|
2013-09-10 19:41:59 +04:00
|
|
|
|
|
|
|
// Append available options, if any.
|
|
|
|
let options = perm.options.QueryInterface(Ci.nsIArray);
|
|
|
|
for (let i = 0; i < options.length; i++) {
|
|
|
|
let option = options.queryElementAt(i, Ci.nsISupportsString).data;
|
|
|
|
tmp.options.push(option);
|
|
|
|
}
|
2014-02-10 00:34:40 +04:00
|
|
|
typesInfo.push(tmp);
|
|
|
|
}
|
2013-09-10 19:41:59 +04:00
|
|
|
|
2014-05-13 09:58:04 +04:00
|
|
|
if (secMan.isSystemPrincipal(request.principal)) {
|
|
|
|
request.allow(buildDefaultChoices(typesInfo));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-10 00:34:40 +04:00
|
|
|
if (typesInfo.length == 0) {
|
|
|
|
request.cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!this.checkMultipleRequest(typesInfo)) {
|
|
|
|
request.cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.handledByApp(request, typesInfo) ||
|
|
|
|
this.handledByPermissionType(request, typesInfo)) {
|
2013-10-04 20:41:57 +04:00
|
|
|
return;
|
|
|
|
}
|
2013-01-10 17:56:45 +04:00
|
|
|
|
2012-03-17 02:23:28 +04:00
|
|
|
// returns true if the request was handled
|
2014-02-10 00:34:40 +04:00
|
|
|
if (this.handleExistingPermission(request, typesInfo)) {
|
2012-03-17 02:23:28 +04:00
|
|
|
return;
|
2014-02-10 00:34:40 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 09:58:04 +04:00
|
|
|
// prompt PROMPT_ACTION request or request with options.
|
|
|
|
typesInfo = typesInfo.filter(function(type) {
|
|
|
|
return !type.deny && (type.action == Ci.nsIPermissionManager.PROMPT_ACTION || type.options.length > 0) ;
|
2014-02-10 00:34:40 +04:00
|
|
|
});
|
2012-03-17 02:23:28 +04:00
|
|
|
|
2013-01-07 20:45:29 +04:00
|
|
|
let frame = request.element;
|
2013-05-23 19:52:04 +04:00
|
|
|
let requestId = this._id++;
|
2013-01-07 20:45:29 +04:00
|
|
|
|
|
|
|
if (!frame) {
|
2014-02-10 00:34:40 +04:00
|
|
|
this.delegatePrompt(request, requestId, typesInfo);
|
2013-05-23 19:52:04 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
frame = frame.wrappedJSObject;
|
|
|
|
var cancelRequest = function() {
|
|
|
|
frame.removeEventListener("mozbrowservisibilitychange", onVisibilityChange);
|
|
|
|
request.cancel();
|
2013-01-07 20:45:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
var self = this;
|
2013-05-23 19:52:04 +04:00
|
|
|
var onVisibilityChange = function(evt) {
|
|
|
|
if (evt.detail.visible === true)
|
|
|
|
return;
|
|
|
|
|
2014-02-10 00:34:40 +04:00
|
|
|
self.cancelPrompt(request, requestId, typesInfo);
|
2013-05-23 19:52:04 +04:00
|
|
|
cancelRequest();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the request was initiated from a hidden iframe
|
|
|
|
// we don't forward it to content and cancel it right away
|
|
|
|
let domRequest = frame.getVisible();
|
|
|
|
domRequest.onsuccess = function gv_success(evt) {
|
2013-01-07 20:45:29 +04:00
|
|
|
if (!evt.target.result) {
|
2013-05-23 19:52:04 +04:00
|
|
|
cancelRequest();
|
2013-01-07 20:45:29 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-23 19:52:04 +04:00
|
|
|
// Monitor the frame visibility and cancel the request if the frame goes
|
|
|
|
// away but the request is still here.
|
|
|
|
frame.addEventListener("mozbrowservisibilitychange", onVisibilityChange);
|
|
|
|
|
2014-02-10 00:34:40 +04:00
|
|
|
self.delegatePrompt(request, requestId, typesInfo, function onCallback() {
|
2013-05-23 19:52:04 +04:00
|
|
|
frame.removeEventListener("mozbrowservisibilitychange", onVisibilityChange);
|
|
|
|
});
|
2013-01-07 20:45:29 +04:00
|
|
|
};
|
2013-05-23 19:52:04 +04:00
|
|
|
|
|
|
|
// Something went wrong. Let's cancel the request just in case.
|
|
|
|
domRequest.onerror = function gv_error() {
|
|
|
|
cancelRequest();
|
|
|
|
}
|
2013-01-07 20:45:29 +04:00
|
|
|
},
|
|
|
|
|
2014-02-10 00:34:40 +04:00
|
|
|
cancelPrompt: function(request, requestId, typesInfo) {
|
|
|
|
this.sendToBrowserWindow("cancel-permission-prompt", request, requestId,
|
|
|
|
typesInfo);
|
2013-05-23 19:52:04 +04:00
|
|
|
},
|
2012-04-11 21:05:35 +04:00
|
|
|
|
2014-02-10 00:34:40 +04:00
|
|
|
delegatePrompt: function(request, requestId, typesInfo, callback) {
|
2012-04-11 21:05:35 +04:00
|
|
|
|
2014-02-10 00:34:40 +04:00
|
|
|
this.sendToBrowserWindow("permission-prompt", request, requestId, typesInfo,
|
2013-09-10 19:41:59 +04:00
|
|
|
function(type, remember, choices) {
|
2013-05-23 19:52:04 +04:00
|
|
|
if (type == "permission-allow") {
|
2014-02-10 00:34:40 +04:00
|
|
|
rememberPermission(typesInfo, request.principal, !remember);
|
2013-08-09 21:02:33 +04:00
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
2013-09-10 19:41:59 +04:00
|
|
|
request.allow(choices);
|
2012-04-11 21:05:35 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-10 00:34:40 +04:00
|
|
|
let addDenyPermission = function(type) {
|
|
|
|
debug("add " + type.permission +
|
|
|
|
" to permission manager with DENY_ACTION");
|
|
|
|
if (remember) {
|
|
|
|
Services.perms.addFromPrincipal(request.principal, type.access,
|
|
|
|
Ci.nsIPermissionManager.DENY_ACTION);
|
2014-03-12 16:29:23 +04:00
|
|
|
} else if (PERMISSION_NO_SESSION.indexOf(type.access) < 0) {
|
2014-02-10 00:34:40 +04:00
|
|
|
Services.perms.addFromPrincipal(request.principal, type.access,
|
|
|
|
Ci.nsIPermissionManager.DENY_ACTION,
|
|
|
|
Ci.nsIPermissionManager.EXPIRE_SESSION,
|
|
|
|
0);
|
|
|
|
}
|
2012-10-23 06:22:27 +04:00
|
|
|
}
|
2014-02-10 00:34:40 +04:00
|
|
|
typesInfo.forEach(addDenyPermission);
|
2012-10-23 06:22:27 +04:00
|
|
|
|
2013-08-09 21:02:33 +04:00
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
2012-04-11 21:05:35 +04:00
|
|
|
request.cancel();
|
|
|
|
});
|
2013-05-23 19:52:04 +04:00
|
|
|
},
|
|
|
|
|
2014-02-10 00:34:40 +04:00
|
|
|
sendToBrowserWindow: function(type, request, requestId, typesInfo, callback) {
|
2013-05-23 19:52:04 +04:00
|
|
|
if (callback) {
|
2014-04-07 17:59:48 +04:00
|
|
|
SystemAppProxy.addEventListener("mozContentEvent", function contentEvent(evt) {
|
2013-05-23 19:52:04 +04:00
|
|
|
let detail = evt.detail;
|
|
|
|
if (detail.id != requestId)
|
|
|
|
return;
|
2014-04-07 17:59:48 +04:00
|
|
|
SystemAppProxy.removeEventListener("mozContentEvent", contentEvent);
|
2013-05-23 19:52:04 +04:00
|
|
|
|
2013-09-10 19:41:59 +04:00
|
|
|
callback(detail.type, detail.remember, detail.choices);
|
2013-05-23 19:52:04 +04:00
|
|
|
})
|
|
|
|
}
|
2012-04-11 21:05:35 +04:00
|
|
|
|
2012-09-12 22:00:55 +04:00
|
|
|
let principal = request.principal;
|
|
|
|
let isApp = principal.appStatus != Ci.nsIPrincipal.APP_STATUS_NOT_INSTALLED;
|
2013-01-09 16:43:15 +04:00
|
|
|
let remember = (principal.appStatus == Ci.nsIPrincipal.APP_STATUS_PRIVILEGED ||
|
|
|
|
principal.appStatus == Ci.nsIPrincipal.APP_STATUS_CERTIFIED)
|
|
|
|
? true
|
|
|
|
: request.remember;
|
2014-05-13 09:58:04 +04:00
|
|
|
let isGranted = typesInfo.every(function(type) {
|
|
|
|
return type.action == Ci.nsIPermissionManager.ALLOW_ACTION;
|
|
|
|
});
|
2014-02-10 00:34:40 +04:00
|
|
|
let permissions = {};
|
|
|
|
for (let i in typesInfo) {
|
|
|
|
debug("prompt " + typesInfo[i].permission);
|
2013-09-10 19:41:59 +04:00
|
|
|
permissions[typesInfo[i].permission] = typesInfo[i].options;
|
2014-02-10 00:34:40 +04:00
|
|
|
}
|
2012-09-12 22:00:55 +04:00
|
|
|
|
2012-07-13 06:28:19 +04:00
|
|
|
let details = {
|
2013-05-23 19:52:04 +04:00
|
|
|
type: type,
|
2014-02-10 00:34:40 +04:00
|
|
|
permissions: permissions,
|
2012-09-12 22:00:55 +04:00
|
|
|
id: requestId,
|
|
|
|
origin: principal.origin,
|
2012-10-25 00:19:01 +04:00
|
|
|
isApp: isApp,
|
2014-05-13 09:58:04 +04:00
|
|
|
remember: remember,
|
|
|
|
isGranted: isGranted,
|
2012-07-13 06:28:19 +04:00
|
|
|
};
|
2012-09-12 22:00:55 +04:00
|
|
|
|
2014-04-07 17:59:48 +04:00
|
|
|
if (isApp) {
|
|
|
|
details.manifestURL = DOMApplicationRegistry.getManifestURLByLocalId(principal.appId);
|
2012-09-12 22:00:55 +04:00
|
|
|
}
|
2014-06-04 22:11:06 +04:00
|
|
|
|
|
|
|
// request.element is defined for OOP content, while request.window
|
|
|
|
// is defined for In-Process content.
|
|
|
|
// In both cases the message needs to be dispatched to the top-level
|
|
|
|
// <iframe mozbrowser> container in the system app.
|
|
|
|
// So the above code iterates over window.realFrameElement in order
|
|
|
|
// to crosss mozbrowser iframes boundaries and find the top-level
|
|
|
|
// one in the system app.
|
|
|
|
// window.realFrameElement will be |null| if the code try to cross
|
|
|
|
// content -> chrome boundaries.
|
|
|
|
let targetElement = request.element;
|
|
|
|
let targetWindow = request.window || targetElement.ownerDocument.defaultView;
|
|
|
|
while (targetWindow.realFrameElement) {
|
|
|
|
targetElement = targetWindow.realFrameElement;
|
|
|
|
targetWindow = targetElement.ownerDocument.defaultView;
|
|
|
|
}
|
|
|
|
|
|
|
|
SystemAppProxy.dispatchEvent(details, targetElement);
|
2012-03-17 02:23:28 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
classID: Components.ID("{8c719f03-afe0-4aac-91ff-6c215895d467}"),
|
|
|
|
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPermissionPrompt])
|
|
|
|
};
|
|
|
|
|
2013-10-04 20:41:57 +04:00
|
|
|
(function() {
|
|
|
|
// Do not allow GetUserMedia while in call.
|
|
|
|
permissionSpecificChecker["audio-capture"] = function(request) {
|
|
|
|
if (AudioManager.phoneState === Ci.nsIAudioManager.PHONE_STATE_IN_CALL) {
|
|
|
|
request.cancel();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
2012-03-17 02:23:28 +04:00
|
|
|
//module initialization
|
2012-10-31 20:13:28 +04:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ContentPermissionPrompt]);
|