B2G/gecko/dom/apps/src/PermissionsInstaller.jsm
/**
   * Install permissisions or remove deprecated permissions upon re-install.
   * @param object aApp
   *        The just-installed app configuration.
   *        The properties used are manifestURL, origin and manifest.
   * @param boolean aIsReinstall
   *        Indicates the app was just re-installed
   * @param function aOnError
   *        A function called if an error occurs
   * @returns void
   **/
Install permissisions or remove deprecated permissions upon re-install.
@param object aApp
The just-installed app configuration.
The properties used are manifestURL, origin and manifest.
@param boolean aIsReinstall
Indicates the app was just re-installed
@param function aOnError
A function called if an error occurs
@returns void
Install permissisions or remove deprecated permissions upon re - install . @param object aApp The just - installed app configuration . The properties used are manifestURL origin and manifest . @param boolean aIsReinstall Indicates the app was just re - installed @param function aOnError A function called if an error occurs @returns void
function installPermissions(aApp, aIsReinstall, aOnError) {
    try {
      let newManifest = new ManifestHelper(aApp.manifest, aApp.origin);
      if (!newManifest.permissions && !aIsReinstall) {
        return;
      }
      if (aIsReinstall) {
        if (newManifest.permissions) {
          let newPermNames = [];
          for (let permName in newManifest.permissions) {
            let expandedPermNames =
              expandPermissions(permName,
                                newManifest.permissions[permName].access);
            newPermNames = newPermNames.concat(expandedPermNames);
          }
          for (let idx in AllPossiblePermissions) {
            let permName = AllPossiblePermissions[idx];
            let index = newPermNames.indexOf(permName);
            if (index == -1) {
              let permValue =
                PermissionSettingsModule.getPermission(permName,
                                                       aApp.manifestURL,
                                                       aApp.origin,
                                                       false);
              if (permValue == "unknown" || permValue == "deny") {
                continue;
              }
              this._setPermission(permName, "unknown", aApp);
            }
          }
        }
      }
      let appStatus;
      switch (AppsUtils.getAppManifestStatus(aApp.manifest)) {
      case Ci.nsIPrincipal.APP_STATUS_CERTIFIED:
        appStatus = "certified";
        break;
      case Ci.nsIPrincipal.APP_STATUS_PRIVILEGED:
        appStatus = "privileged";
        break;
      case Ci.nsIPrincipal.APP_STATUS_INSTALLED:
        appStatus = "app";
        break;
      default:
        throw new Error("PermissionsInstaller.jsm: " +
                        "Cannot determine the app's status. Install cancelled.");
        break;
      }
      for (let permName in newManifest.permissions) {
        if (!PermissionsTable[permName]) {
          Cu.reportError("PermissionsInstaller.jsm: '" + permName + "'" +
                         " is not a valid Webapps permission name.");
          dump("PermissionsInstaller.jsm: '" + permName + "'" +
               " is not a valid Webapps permission name.");
          continue;
        }
        let expandedPermNames =
          expandPermissions(permName,
                            newManifest.permissions[permName].access);
        for (let idx in expandedPermNames) {
          this._setPermission(expandedPermNames[idx],
                              PERM_TO_STRING[PermissionsTable[permName][appStatus]],
                              aApp);
        }
      }
    }
    catch (ex) {
      dump("Caught webapps install permissions error for " + aApp.origin);
      Cu.reportError(ex);
      if (aOnError) {
        aOnError();
      }
    }
  }
function installPermissions ( aApp , aIsReinstall , aOnError ) { try { let newManifest = new ManifestHelper ( aApp . manifest , aApp . origin ) ; if ( ! newManifest . permissions && ! aIsReinstall ) { return ; } if ( aIsReinstall ) { if ( newManifest . permissions ) { let newPermNames = [ ] ; for ( let permName in newManifest . permissions ) { let expandedPermNames = expandPermissions ( permName , newManifest . permissions [ permName ] . access ) ; newPermNames = newPermNames . concat ( expandedPermNames ) ; } for ( let idx in AllPossiblePermissions ) { let permName = AllPossiblePermissions [ idx ] ; let index = newPermNames . indexOf ( permName ) ; if ( index == - 1 ) { let permValue = PermissionSettingsModule . getPermission ( permName , aApp . manifestURL , aApp . origin , false ) ; if ( permValue == "unknown" || permValue == "deny" ) { continue ; } this . _setPermission ( permName , "unknown" , aApp ) ; } } } } let appStatus ; switch ( AppsUtils . getAppManifestStatus ( aApp . manifest ) ) { case Ci . nsIPrincipal . APP_STATUS_CERTIFIED : appStatus = "certified" ; break ; case Ci . nsIPrincipal . APP_STATUS_PRIVILEGED : appStatus = "privileged" ; break ; case Ci . nsIPrincipal . APP_STATUS_INSTALLED : appStatus = "app" ; break ; default : throw new Error ( "PermissionsInstaller.jsm: " + "Cannot determine the app's status. Install cancelled." ) ; break ; } for ( let permName in newManifest . permissions ) { if ( ! PermissionsTable [ permName ] ) { Cu . reportError ( "PermissionsInstaller.jsm: '" + permName + "'" + " is not a valid Webapps permission name." ) ; dump ( "PermissionsInstaller.jsm: '" + permName + "'" + " is not a valid Webapps permission name." ) ; continue ; } let expandedPermNames = expandPermissions ( permName , newManifest . permissions [ permName ] . access ) ; for ( let idx in expandedPermNames ) { this . _setPermission ( expandedPermNames [ idx ] , PERM_TO_STRING [ PermissionsTable [ permName ] [ appStatus ] ] , aApp ) ; } } } catch ( ex ) { dump ( "Caught webapps install permissions error for " + aApp . origin ) ; Cu . reportError ( ex ) ; if ( aOnError ) { aOnError ( ) ; } } }
Install permissisions or remove deprecated permissions upon re-install.
Install permissisions or remove deprecated permissions upon re - install .
// Compare the original permissions against the new permissions // Remove any deprecated Permissions // Expand permission names. // See if the permission was installed previously. // All 'deny' permissions should be preserved // Remove the deprecated permission // TODO: use PermSettings.remove, see bug 793204 // Check to see if the 'webapp' is app/privileged/certified. // Cannot determine app type, abort install by throwing an error.