ChromePermissions class
class ChromePermissions extends ChromeApi { static final JsObject _permissions = chrome['permissions']; ChromePermissions._(); bool get available => _permissions != null; /** * Gets the extension's current set of permissions. * * Returns: * The extension's active permissions. */ Future<Permissions> getAll() { if (_permissions == null) _throwNotAvailable(); var completer = new ChromeCompleter<Permissions>.oneArg(_createPermissions); _permissions.callMethod('getAll', [completer.callback]); return completer.future; } /** * Checks if the extension has the specified permissions. * * Returns: * True if the extension has the specified permissions. */ Future<bool> contains(Permissions permissions) { if (_permissions == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _permissions.callMethod('contains', [jsify(permissions), completer.callback]); return completer.future; } /** * Requests access to the specified permissions. These permissions must be * defined in the optional_permissions field of the manifest. If there are any * problems requesting the permissions, [runtime.lastError] will be set. * * Returns: * True if the user granted the specified permissions. */ Future<bool> request(Permissions permissions) { if (_permissions == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _permissions.callMethod('request', [jsify(permissions), completer.callback]); return completer.future; } /** * Removes access to the specified permissions. If there are any problems * removing the permissions, [runtime.lastError] will be set. * * Returns: * True if the permissions were removed. */ Future<bool> remove(Permissions permissions) { if (_permissions == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _permissions.callMethod('remove', [jsify(permissions), completer.callback]); return completer.future; } /** * Fired when the extension acquires new permissions. */ Stream<Permissions> get onAdded => _onAdded.stream; final ChromeStreamController<Permissions> _onAdded = new ChromeStreamController<Permissions>.oneArg(_permissions, 'onAdded', _createPermissions); /** * Fired when access to permissions has been removed from the extension. */ Stream<Permissions> get onRemoved => _onRemoved.stream; final ChromeStreamController<Permissions> _onRemoved = new ChromeStreamController<Permissions>.oneArg(_permissions, 'onRemoved', _createPermissions); void _throwNotAvailable() { throw new UnsupportedError("'chrome.permissions' is not available"); } }
Extends
ChromeApi > ChromePermissions
Properties
final bool available #
Returns true if the API is available. The common causes of an API not being avilable are:
- a permission is missing in the application's manifest.json file
- the API is defined on a newer version of Chrome then the current runtime
bool get available => _permissions != null;
final Stream<Permissions> onAdded #
Fired when the extension acquires new permissions.
Stream<Permissions> get onAdded => _onAdded.stream;
final Stream<Permissions> onRemoved #
Fired when access to permissions has been removed from the extension.
Stream<Permissions> get onRemoved => _onRemoved.stream;
Methods
Future<bool> contains(Permissions permissions) #
Checks if the extension has the specified permissions.
Returns: True if the extension has the specified permissions.
Future<bool> contains(Permissions permissions) { if (_permissions == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _permissions.callMethod('contains', [jsify(permissions), completer.callback]); return completer.future; }
Future<Permissions> getAll() #
Gets the extension's current set of permissions.
Returns: The extension's active permissions.
Future<Permissions> getAll() { if (_permissions == null) _throwNotAvailable(); var completer = new ChromeCompleter<Permissions>.oneArg(_createPermissions); _permissions.callMethod('getAll', [completer.callback]); return completer.future; }
Future<bool> remove(Permissions permissions) #
Removes access to the specified permissions. If there are any problems
removing the permissions, runtime.lastError
will be set.
Returns: True if the permissions were removed.
Future<bool> remove(Permissions permissions) { if (_permissions == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _permissions.callMethod('remove', [jsify(permissions), completer.callback]); return completer.future; }
Future<bool> request(Permissions permissions) #
Requests access to the specified permissions. These permissions must be
defined in the optional_permissions field of the manifest. If there are any
problems requesting the permissions, runtime.lastError
will be set.
Returns: True if the user granted the specified permissions.
Future<bool> request(Permissions permissions) { if (_permissions == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _permissions.callMethod('request', [jsify(permissions), completer.callback]); return completer.future; }