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-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
|
|
|
|
**/
|
2014-06-11 01:47:00 -07:00
|
|
|
installPermissions: function installPermissions(aApp, aIsReinstall, aOnError,
|
|
|
|
aIsSystemUpdate) {
|
2012-10-02 22:38:06 -07:00
|
|
|
try {
|
2014-07-30 14:00:15 -07:00
|
|
|
let newManifest =
|
|
|
|
new ManifestHelper(aApp.manifest, aApp.origin, aApp.manifestURL);
|
2012-10-02 22:38:06 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-01-08 17:14:22 -08:00
|
|
|
// Add the appcache related permissions.
|
|
|
|
if (newManifest.appcache_path) {
|
|
|
|
newPermNames = newPermNames.concat(["offline-app", "pin-app"]);
|
|
|
|
}
|
|
|
|
|
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";
|
2014-09-16 13:14:02 -07:00
|
|
|
if (aApp.kind == "hosted-trusted") {
|
|
|
|
appStatus = "trusted";
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2014-01-08 17:14:22 -08:00
|
|
|
// Add the appcache related permissions. We allow it for all kinds of
|
|
|
|
// apps.
|
|
|
|
if (newManifest.appcache_path) {
|
|
|
|
this._setPermission("offline-app", "allow", aApp);
|
|
|
|
this._setPermission("pin-app", "allow", aApp);
|
|
|
|
}
|
|
|
|
|
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) {
|
2014-06-11 01:47:00 -07:00
|
|
|
|
|
|
|
let isPromptPermission =
|
|
|
|
PermissionsTable[permName][appStatus] === PROMPT_ACTION;
|
|
|
|
|
2014-05-26 03:30:11 -07:00
|
|
|
// We silently upgrade the permission to whatever the permission
|
|
|
|
// is for certified apps (ALLOW or PROMPT) only if the
|
|
|
|
// following holds true:
|
|
|
|
// * The app is preinstalled
|
|
|
|
// * The permission that would be granted is PROMPT
|
|
|
|
// * The app is privileged
|
|
|
|
let permission =
|
2014-06-11 01:47:00 -07:00
|
|
|
aApp.isPreinstalled && isPromptPermission &&
|
2014-05-26 03:30:11 -07:00
|
|
|
appStatus === "privileged"
|
|
|
|
? PermissionsTable[permName]["certified"]
|
|
|
|
: PermissionsTable[permName][appStatus];
|
|
|
|
|
2014-06-11 01:47:00 -07:00
|
|
|
let permValue = PERM_TO_STRING[permission];
|
|
|
|
if (!aIsSystemUpdate && isPromptPermission) {
|
|
|
|
// If it's not a system update, then we should keep the prompt
|
|
|
|
// permissions that have been granted or denied previously.
|
|
|
|
permValue =
|
2014-07-08 02:45:00 -07:00
|
|
|
PermissionSettingsModule.getPermission(expandedPermNames[idx],
|
2014-06-11 01:47:00 -07:00
|
|
|
aApp.manifestURL,
|
|
|
|
aApp.origin,
|
|
|
|
false);
|
|
|
|
if (permValue === "unknown") {
|
|
|
|
permValue = PERM_TO_STRING[permission];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this._setPermission(expandedPermNames[idx], permValue, 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
|
|
|
};
|