Permissions API (Firefox OS)

Non-standard
This feature is not on a current W3C standards track, but it is supported on the Firefox OS platform. Although implementations may change in the future and it is not supported widely across browsers, it is suitable for use in code dedicated to Firefox OS apps.

This API is available on Firefox OS for internal applications only.

 

The Permissions API is used to display and let the user manage all the permissions requested by apps. With this API, an application can read the permissions of another application and is also able to change those permissions.

The permission manager is accessible through the navigator.mozPermissionSettings property which is an instance of the PermissionSettings interface.

Installed app permission

Each application requests some permission through its app manifest. Each time an application will try to use an API that require an explicit permission, the user will be prompted to grant or deny the permission. If he chooses not to be prompted again, the user has no means for changing his mind. With this API it's possible to give the user an interface to manage all the permissions he gave to any application.

This is possible by using the PermissionSettings.get(), set(), and isExplicit() methods.

Reading permission

To know the current status of a given permission, use the PermissionSettings.get() method. This method return a string giving the current status of the permission for the specific app. Possible values are:

allow
The permission was granted and doesn't require any further user interaction.
denied
The permission was denied, whether by the system or the user.
prompt
The permission will be asked explicitly to the user through a prompt when needed.
unknown
The application did not ask for this permission and can't even prompt the user to get it.
// Let's check all installed apps
var apps = navigator.mozApps.mgmt.getAll();
apps.onsuccess = function () {
  var permission = navigator.mozPermissionSettings;
  // Let's check the permission of each app
  apps.result.forEach(function (app) {
    var request, appName = app.manifest.name;
    for (request in app.manifest.permissions) {
      // Let's get the current permission for each permission request by the application
      var p = permission.get(request, app.manifestURL, app.origin, false);
      console.log(appName + ' asked for "' + request + '" permission, which is "' + p + '"')
    }
  });
}

Setting permission

To set a permission, simply use the PermissionSettings.set() method. Possible values are the same as the ones retrieved through the get method.

Note: Depending on the privileges of the applications, some permission are implicit. If for some reason the application tries to change permission for an implicit one, an error will be thrown. In order to avoid such errors, it's possible to check if the permission is explicit with the PermissionSettings.isExplicit() method.

// Let's check all installed apps
var apps = navigator.mozApps.mgmt.getAll();
apps.onsuccess = function () {
  var permission = navigator.mozPermissionSettings;
  // Let's grant the permission of each app
  apps.result.forEach(function (app) {
    var request, appName = app.manifest.name;
    for (request in app.manifest.permissions) {
      // If the permission is not explicit
      if (!permission.isExplicit(request, app.manifestURL, app.origin, false) {
        // Let's ask the user for all permissions requested by the application
        permission.set(request, 'prompt', app.manifestURL, app.origin, false);
      }
    }
  });
}

Specification

Not part of any specification.

See also

Document Tags and Contributors

 Contributors to this page: chrisdavidmills, teoli
 Last updated by: chrisdavidmills,