2012-09-28 15:16:29 -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";
|
|
|
|
|
|
|
|
const Ci = Components.interfaces;
|
2012-10-02 22:38:06 -07:00
|
|
|
const Cu = Components.utils;
|
2012-09-28 15:16:29 -07:00
|
|
|
|
2012-10-02 22:38:06 -07:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/AppsUtils.jsm");
|
2012-10-23 13:11:02 -07:00
|
|
|
Cu.import("resource://gre/modules/PermissionSettings.jsm");
|
2012-12-14 17:32:30 -08:00
|
|
|
Cu.import("resource://gre/modules/PermissionsTable.jsm");
|
2012-10-02 22:38:06 -07:00
|
|
|
|
2012-12-14 17:32:30 -08:00
|
|
|
this.EXPORTED_SYMBOLS = ["PermissionsInstaller"];
|
2012-09-28 15:16:29 -07:00
|
|
|
const UNKNOWN_ACTION = Ci.nsIPermissionManager.UNKNOWN_ACTION;
|
|
|
|
const ALLOW_ACTION = Ci.nsIPermissionManager.ALLOW_ACTION;
|
|
|
|
const DENY_ACTION = Ci.nsIPermissionManager.DENY_ACTION;
|
|
|
|
const PROMPT_ACTION = Ci.nsIPermissionManager.PROMPT_ACTION;
|
|
|
|
|
2012-10-02 22:38:06 -07:00
|
|
|
// Permission access flags
|
|
|
|
const READONLY = "readonly";
|
|
|
|
const CREATEONLY = "createonly";
|
|
|
|
const READCREATE = "readcreate";
|
|
|
|
const READWRITE = "readwrite";
|
|
|
|
|
|
|
|
const PERM_TO_STRING = ["unknown", "allow", "deny", "prompt"];
|
|
|
|
|
|
|
|
function debug(aMsg) {
|
|
|
|
//dump("-*-*- PermissionsInstaller.jsm : " + aMsg + "\n");
|
|
|
|
}
|
|
|
|
|
2012-11-28 02:57:16 -08:00
|
|
|
// An array carring all the possible (expanded) permission names.
|
2012-10-25 10:12:14 -07:00
|
|
|
let AllPossiblePermissions = [];
|
|
|
|
for (let permName in PermissionsTable) {
|
2012-12-11 00:09:40 -08:00
|
|
|
let expandedPermNames = [];
|
2012-10-25 10:12:14 -07:00
|
|
|
if (PermissionsTable[permName].access) {
|
2012-12-11 00:09:40 -08:00
|
|
|
expandedPermNames = expandPermissions(permName, READWRITE);
|
2012-10-25 10:12:14 -07:00
|
|
|
} else {
|
2012-12-11 00:09:40 -08:00
|
|
|
expandedPermNames = expandPermissions(permName);
|
2012-10-25 10:12:14 -07:00
|
|
|
}
|
2012-12-11 00:09:40 -08:00
|
|
|
AllPossiblePermissions = AllPossiblePermissions.concat(expandedPermNames);
|
2012-10-25 10:12:14 -07:00
|
|
|
}
|
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.PermissionsInstaller = {
|
2012-11-28 02:57:16 -08:00
|
|
|
/**
|
|
|
|
* Install permissisions or remove deprecated permissions upon re-install.
|
2012-10-10 09:16:49 -07:00
|
|
|
* @param object aApp
|
|
|
|
* The just-installed app configuration.
|
2012-11-28 02:57:16 -08:00
|
|
|
* The properties used are manifestURL, origin and manifest.
|
2012-10-02 22:38:06 -07:00
|
|
|
* @param boolean aIsReinstall
|
|
|
|
* Indicates the app was just re-installed
|
2012-10-10 09:16:49 -07:00
|
|
|
* @param function aOnError
|
|
|
|
* A function called if an error occurs
|
2012-10-02 22:38:06 -07:00
|
|
|
* @returns void
|
|
|
|
**/
|
|
|
|
installPermissions: function installPermissions(aApp, aIsReinstall, aOnError) {
|
|
|
|
try {
|
|
|
|
let newManifest = new ManifestHelper(aApp.manifest, aApp.origin);
|
|
|
|
if (!newManifest.permissions && !aIsReinstall) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIsReinstall) {
|
|
|
|
// Compare the original permissions against the new permissions
|
|
|
|
// Remove any deprecated Permissions
|
|
|
|
|
|
|
|
if (newManifest.permissions) {
|
2012-11-28 02:57:16 -08:00
|
|
|
// Expand permission names.
|
|
|
|
let newPermNames = [];
|
|
|
|
for (let permName in newManifest.permissions) {
|
|
|
|
let expandedPermNames =
|
|
|
|
expandPermissions(permName,
|
2012-12-11 00:09:40 -08:00
|
|
|
newManifest.permissions[permName].access);
|
2012-11-28 02:57:16 -08:00
|
|
|
newPermNames = newPermNames.concat(expandedPermNames);
|
2012-10-02 22:38:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
for (let idx in AllPossiblePermissions) {
|
2012-11-28 02:57:16 -08:00
|
|
|
let permName = AllPossiblePermissions[idx];
|
|
|
|
let index = newPermNames.indexOf(permName);
|
2012-10-02 22:38:06 -07:00
|
|
|
if (index == -1) {
|
2012-11-28 02:57:16 -08:00
|
|
|
// See if the permission was installed previously.
|
|
|
|
let permValue =
|
|
|
|
PermissionSettingsModule.getPermission(permName,
|
|
|
|
aApp.manifestURL,
|
|
|
|
aApp.origin,
|
|
|
|
false);
|
|
|
|
if (permValue == "unknown" || permValue == "deny") {
|
2012-10-02 22:38:06 -07:00
|
|
|
// All 'deny' permissions should be preserved
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Remove the deprecated permission
|
2013-01-26 09:56:23 -08:00
|
|
|
PermissionSettingsModule.removePermission(permName,
|
|
|
|
aApp.manifestURL,
|
|
|
|
aApp.origin,
|
|
|
|
false);
|
2012-10-02 22:38:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 02:57:16 -08:00
|
|
|
// Check to see if the 'webapp' is app/privileged/certified.
|
|
|
|
let appStatus;
|
2012-10-10 09:16:49 -07:00
|
|
|
switch (AppsUtils.getAppManifestStatus(aApp.manifest)) {
|
2012-10-02 22:38:06 -07:00
|
|
|
case Ci.nsIPrincipal.APP_STATUS_CERTIFIED:
|
2012-11-28 02:57:16 -08:00
|
|
|
appStatus = "certified";
|
2012-10-02 22:38:06 -07:00
|
|
|
break;
|
|
|
|
case Ci.nsIPrincipal.APP_STATUS_PRIVILEGED:
|
2012-11-28 02:57:16 -08:00
|
|
|
appStatus = "privileged";
|
2012-10-02 22:38:06 -07:00
|
|
|
break;
|
|
|
|
case Ci.nsIPrincipal.APP_STATUS_INSTALLED:
|
2012-11-28 02:57:16 -08:00
|
|
|
appStatus = "app";
|
2012-10-02 22:38:06 -07:00
|
|
|
break;
|
|
|
|
default:
|
2012-11-28 02:57:16 -08:00
|
|
|
// Cannot determine app type, abort install by throwing an error.
|
|
|
|
throw new Error("PermissionsInstaller.jsm: " +
|
|
|
|
"Cannot determine the app's status. Install cancelled.");
|
|
|
|
break;
|
2012-10-02 22:38:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
for (let permName in newManifest.permissions) {
|
|
|
|
if (!PermissionsTable[permName]) {
|
2012-10-26 20:45:25 -07:00
|
|
|
Cu.reportError("PermissionsInstaller.jsm: '" + permName + "'" +
|
2012-11-28 02:57:16 -08:00
|
|
|
" is not a valid Webapps permission name.");
|
2012-11-19 12:31:15 -08:00
|
|
|
dump("PermissionsInstaller.jsm: '" + permName + "'" +
|
2012-11-28 02:57:16 -08:00
|
|
|
" is not a valid Webapps permission name.");
|
2012-10-26 20:45:25 -07:00
|
|
|
continue;
|
2012-10-02 22:38:06 -07:00
|
|
|
}
|
2012-11-28 02:57:16 -08:00
|
|
|
|
|
|
|
let expandedPermNames =
|
|
|
|
expandPermissions(permName,
|
2012-12-11 00:09:40 -08:00
|
|
|
newManifest.permissions[permName].access);
|
2012-11-28 02:57:16 -08:00
|
|
|
for (let idx in expandedPermNames) {
|
|
|
|
this._setPermission(expandedPermNames[idx],
|
|
|
|
PERM_TO_STRING[PermissionsTable[permName][appStatus]],
|
|
|
|
aApp);
|
2012-10-02 22:38:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (ex) {
|
2012-11-19 12:31:15 -08:00
|
|
|
dump("Caught webapps install permissions error for " + aApp.origin);
|
2012-10-02 22:38:06 -07:00
|
|
|
Cu.reportError(ex);
|
|
|
|
if (aOnError) {
|
|
|
|
aOnError();
|
|
|
|
}
|
|
|
|
}
|
2012-10-10 09:16:49 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2012-11-28 02:57:16 -08:00
|
|
|
* Set a permission value.
|
|
|
|
* @param string aPermName
|
2012-10-10 09:16:49 -07:00
|
|
|
* The permission name.
|
2012-11-28 02:57:16 -08:00
|
|
|
* @param string aPermValue
|
2012-10-10 09:16:49 -07:00
|
|
|
* The permission value.
|
|
|
|
* @param object aApp
|
|
|
|
* The just-installed app configuration.
|
2012-11-28 02:57:16 -08:00
|
|
|
* The properties used are manifestURL and origin.
|
2012-10-10 09:16:49 -07:00
|
|
|
* @returns void
|
|
|
|
**/
|
2012-11-28 02:57:16 -08:00
|
|
|
_setPermission: function setPermission(aPermName, aPermValue, aApp) {
|
|
|
|
PermissionSettingsModule.addPermission({
|
|
|
|
type: aPermName,
|
|
|
|
origin: aApp.origin,
|
|
|
|
manifestURL: aApp.manifestURL,
|
|
|
|
value: aPermValue,
|
|
|
|
browserFlag: false
|
|
|
|
});
|
|
|
|
}
|
2012-11-19 10:12:10 -08:00
|
|
|
};
|