B2G/gecko/dom/messages/SystemMessagePermissionsChecker.jsm
/**
   * Check if the system message is permitted to be registered for the given
   * app at start-up based on the permissions claimed in the app's manifest.
   * @param string aSysMsgName
   *        The system messsage name.
   * @param string aOrigin
   *        The app's origin.
   * @param object aManifest
   *        The app's manifest.
   * @returns bool
   *        Is permitted or not.
   **/
Check if the system message is permitted to be registered for the given
app at start-up based on the permissions claimed in the app's manifest.
@param string aSysMsgName
The system messsage name.
@param string aOrigin
The app's origin.
@param object aManifest
The app's manifest.
@returns bool
Is permitted or not.
Check if the system message is permitted to be registered for the given app at start - up based on the permissions claimed in the app ' s manifest . @param string aSysMsgName The system messsage name . @param string aOrigin The app ' s origin . @param object aManifest The app ' s manifest . @returns bool Is permitted or not .
function isSystemMessagePermittedToRegister(aSysMsgName, aOrigin, aManifest) {
    debug("isSystemMessagePermittedToRegister(): " +
          "aSysMsgName: " + aSysMsgName + ", " +
          "aOrigin: " + aOrigin + ", " +
          "aManifest: " + JSON.stringify(aManifest));
    let permNames = this.getSystemMessagePermissions(aSysMsgName);
    if (permNames === null) {
      return false;
    }
    let appStatus;
    switch (AppsUtils.getAppManifestStatus(aManifest)) {
    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("SystemMessagePermissionsChecker.jsm: " +
                      "Cannot decide the app's status. Install cancelled.");
      break;
    }
    let newManifest = new ManifestHelper(aManifest, aOrigin);
    for (let permName in permNames) {
      if (!newManifest.permissions || !newManifest.permissions[permName]) {
        debug("'" + aSysMsgName + "' isn't permitted by '" + permName + "'. " +
              "Please add the permission for app: '" + aOrigin + "'.");
        return false;
      }
      let permValue = PermissionsTable[permName][appStatus];
      if (permValue != Ci.nsIPermissionManager.PROMPT_ACTION &&
          permValue != Ci.nsIPermissionManager.ALLOW_ACTION) {
        debug("'" + aSysMsgName + "' isn't permitted by '" + permName + "'. " +
              "Please add the permission for app: '" + aOrigin + "'.");
        return false;
      }
      let expandedPermNames =
        expandPermissions(permName,
                          newManifest.permissions[permName].access);
      let permNamesWithAccess = permNames[permName];
      for (let idx in permNamesWithAccess) {
        let index = expandedPermNames.indexOf(permNamesWithAccess[idx]);
        if (index == -1) {
          debug("'" + aSysMsgName + "' isn't permitted by '" + permName + "'. " +
                "Please add the permission for app: '" + aOrigin + "'.");
          return false;
        }
      }
    }
    return true;
  }
function isSystemMessagePermittedToRegister ( aSysMsgName , aOrigin , aManifest ) { debug ( "isSystemMessagePermittedToRegister(): " + "aSysMsgName: " + aSysMsgName + ", " + "aOrigin: " + aOrigin + ", " + "aManifest: " + JSON . stringify ( aManifest ) ) ; let permNames = this . getSystemMessagePermissions ( aSysMsgName ) ; if ( permNames === null ) { return false ; } let appStatus ; switch ( AppsUtils . getAppManifestStatus ( aManifest ) ) { 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 ( "SystemMessagePermissionsChecker.jsm: " + "Cannot decide the app's status. Install cancelled." ) ; break ; } let newManifest = new ManifestHelper ( aManifest , aOrigin ) ; for ( let permName in permNames ) { if ( ! newManifest . permissions || ! newManifest . permissions [ permName ] ) { debug ( "'" + aSysMsgName + "' isn't permitted by '" + permName + "'. " + "Please add the permission for app: '" + aOrigin + "'." ) ; return false ; } let permValue = PermissionsTable [ permName ] [ appStatus ] ; if ( permValue != Ci . nsIPermissionManager . PROMPT_ACTION && permValue != Ci . nsIPermissionManager . ALLOW_ACTION ) { debug ( "'" + aSysMsgName + "' isn't permitted by '" + permName + "'. " + "Please add the permission for app: '" + aOrigin + "'." ) ; return false ; } let expandedPermNames = expandPermissions ( permName , newManifest . permissions [ permName ] . access ) ; let permNamesWithAccess = permNames [ permName ] ; for ( let idx in permNamesWithAccess ) { let index = expandedPermNames . indexOf ( permNamesWithAccess [ idx ] ) ; if ( index == - 1 ) { debug ( "'" + aSysMsgName + "' isn't permitted by '" + permName + "'. " + "Please add the permission for app: '" + aOrigin + "'." ) ; return false ; } } } return true ; }
Check if the system message is permitted to be registered for the given
 app at start-up based on the permissions claimed in the app's manifest.
Check if the system message is permitted to be registered for the given app at start - up based on the permissions claimed in the app ' s manifest .
// Check to see if the 'webapp' is app/privileged/certified. // The app doesn't claim valid permissions for this sytem message. // Compare the expanded permission names between the ones in // app's manifest and the ones needed for system message. // Early return false as soon as any permission is not matched. // All the permissions needed for this system message are matched.