2012-09-19 11:19:00 -07: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/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2012-09-28 15:16:29 -07:00
|
|
|
function debug(aMsg) {
|
2012-10-23 13:11:02 -07:00
|
|
|
//dump("-*- PermissionSettings.js: " + aMsg + "\n");
|
2012-09-28 15:16:29 -07:00
|
|
|
}
|
2012-09-19 11:19:00 -07:00
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2012-12-14 17:32:30 -08:00
|
|
|
Cu.import("resource://gre/modules/PermissionsTable.jsm");
|
2012-09-19 11:19:00 -07:00
|
|
|
|
2012-09-21 11:30:09 -07:00
|
|
|
var cpm = Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsISyncMessageSender);
|
2012-09-19 11:19:00 -07:00
|
|
|
|
|
|
|
// PermissionSettings
|
|
|
|
|
|
|
|
const PERMISSIONSETTINGS_CONTRACTID = "@mozilla.org/permissionSettings;1";
|
2013-01-26 09:56:23 -08:00
|
|
|
const PERMISSIONSETTINGS_CID = Components.ID("{cd2cf7a1-f4c1-487b-8c1b-1a71c7097431}");
|
2012-09-19 11:19:00 -07:00
|
|
|
|
|
|
|
function PermissionSettings()
|
|
|
|
{
|
|
|
|
debug("Constructor");
|
|
|
|
}
|
|
|
|
|
2012-10-23 13:11:02 -07:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this,
|
|
|
|
"appsService",
|
|
|
|
"@mozilla.org/AppsService;1",
|
|
|
|
"nsIAppsService");
|
2012-09-19 11:19:00 -07:00
|
|
|
|
|
|
|
PermissionSettings.prototype = {
|
2012-11-28 02:57:16 -08:00
|
|
|
get: function get(aPermName, aManifestURL, aOrigin, aBrowserFlag) {
|
|
|
|
debug("Get called with: " + aPermName + ", " + aManifestURL + ", " + aOrigin + ", " + aBrowserFlag);
|
2012-09-19 11:19:00 -07:00
|
|
|
let uri = Services.io.newURI(aOrigin, null, null);
|
|
|
|
let appID = appsService.getAppLocalIdByManifestURL(aManifestURL);
|
2014-04-29 10:27:51 -07:00
|
|
|
let principal = Services.scriptSecurityManager.getAppCodebasePrincipal(uri, appID, aBrowserFlag);
|
|
|
|
let result = Services.perms.testExactPermanentPermission(principal, aPermName);
|
2012-09-19 11:19:00 -07:00
|
|
|
|
|
|
|
switch (result)
|
|
|
|
{
|
|
|
|
case Ci.nsIPermissionManager.UNKNOWN_ACTION:
|
2012-09-28 15:16:29 -07:00
|
|
|
return "unknown";
|
2012-09-19 11:19:00 -07:00
|
|
|
case Ci.nsIPermissionManager.ALLOW_ACTION:
|
|
|
|
return "allow";
|
|
|
|
case Ci.nsIPermissionManager.DENY_ACTION:
|
|
|
|
return "deny";
|
|
|
|
case Ci.nsIPermissionManager.PROMPT_ACTION:
|
|
|
|
return "prompt";
|
|
|
|
default:
|
|
|
|
dump("Unsupported PermissionSettings Action!\n");
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-12-14 17:32:30 -08:00
|
|
|
isExplicit: function isExplicit(aPermName, aManifestURL, aOrigin,
|
|
|
|
aBrowserFlag) {
|
|
|
|
debug("isExplicit: " + aPermName + ", " + aManifestURL + ", " + aOrigin);
|
|
|
|
let uri = Services.io.newURI(aOrigin, null, null);
|
2015-01-31 11:10:50 -08:00
|
|
|
let app = appsService.getAppByManifestURL(aManifestURL);
|
|
|
|
let principal = Services.scriptSecurityManager
|
|
|
|
.getAppCodebasePrincipal(uri, app.localId, aBrowserFlag);
|
2012-12-14 17:32:30 -08:00
|
|
|
|
2015-01-31 11:10:50 -08:00
|
|
|
return isExplicitInPermissionsTable(aPermName,
|
|
|
|
principal.appStatus,
|
|
|
|
app.kind);
|
2012-12-14 17:32:30 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function set(aPermName, aPermValue, aManifestURL, aOrigin,
|
|
|
|
aBrowserFlag) {
|
|
|
|
debug("Set called with: " + aPermName + ", " + aManifestURL + ", " +
|
2013-01-26 09:56:23 -08:00
|
|
|
aOrigin + ", " + aPermValue + ", " + aBrowserFlag);
|
|
|
|
let currentPermValue = this.get(aPermName, aManifestURL, aOrigin,
|
2013-01-17 13:50:59 -08:00
|
|
|
aBrowserFlag);
|
2012-09-19 11:19:00 -07:00
|
|
|
let action;
|
2012-12-14 17:32:30 -08:00
|
|
|
// Check for invalid calls so that we throw an exception rather than get
|
|
|
|
// killed by parent process
|
2013-01-26 09:56:23 -08:00
|
|
|
if (currentPermValue === "unknown" ||
|
2013-01-17 13:50:59 -08:00
|
|
|
aPermValue === "unknown" ||
|
2012-12-14 17:32:30 -08:00
|
|
|
!this.isExplicit(aPermName, aManifestURL, aOrigin, aBrowserFlag)) {
|
|
|
|
let errorMsg = "PermissionSettings.js: '" + aPermName + "'" +
|
2013-01-17 13:50:59 -08:00
|
|
|
" is an implicit permission for '" + aManifestURL +
|
|
|
|
"' or the permission isn't set";
|
2012-12-14 17:32:30 -08:00
|
|
|
Cu.reportError(errorMsg);
|
|
|
|
throw new Components.Exception(errorMsg);
|
|
|
|
}
|
|
|
|
|
2012-09-19 11:19:00 -07:00
|
|
|
cpm.sendSyncMessage("PermissionSettings:AddPermission", {
|
2012-11-28 02:57:16 -08:00
|
|
|
type: aPermName,
|
2012-09-19 11:19:00 -07:00
|
|
|
origin: aOrigin,
|
|
|
|
manifestURL: aManifestURL,
|
2012-11-28 02:57:16 -08:00
|
|
|
value: aPermValue,
|
2012-09-19 11:19:00 -07:00
|
|
|
browserFlag: aBrowserFlag
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-01-26 09:56:23 -08:00
|
|
|
remove: function remove(aPermName, aManifestURL, aOrigin) {
|
|
|
|
let uri = Services.io.newURI(aOrigin, null, null);
|
|
|
|
let appID = appsService.getAppLocalIdByManifestURL(aManifestURL);
|
2014-04-29 10:27:51 -07:00
|
|
|
let principal = Services.scriptSecurityManager.getAppCodebasePrincipal(uri, appID, true);
|
2013-01-26 09:56:23 -08:00
|
|
|
|
|
|
|
if (principal.appStatus !== Ci.nsIPrincipal.APP_STATUS_NOT_INSTALLED) {
|
|
|
|
let errorMsg = "PermissionSettings.js: '" + aOrigin + "'" +
|
|
|
|
" is installed or permission is implicit, cannot remove '" +
|
|
|
|
aPermName + "'.";
|
|
|
|
Cu.reportError(errorMsg);
|
|
|
|
throw new Components.Exception(errorMsg);
|
|
|
|
}
|
|
|
|
|
|
|
|
// PermissionSettings.jsm handles delete when value is "unknown"
|
|
|
|
cpm.sendSyncMessage("PermissionSettings:AddPermission", {
|
|
|
|
type: aPermName,
|
|
|
|
origin: aOrigin,
|
|
|
|
manifestURL: aManifestURL,
|
|
|
|
value: "unknown",
|
|
|
|
browserFlag: true
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-09-19 11:19:00 -07:00
|
|
|
classID : PERMISSIONSETTINGS_CID,
|
2014-03-22 06:58:24 -07:00
|
|
|
QueryInterface : XPCOMUtils.generateQI([])
|
2012-09-19 11:19:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([PermissionSettings])
|