dart-gde/chrome.dart — pull request #145 by aefalcon (2014-02-27 02:12:28+00:00)
Title: Use a getter to fetch the JsObject for an API each time it is needed

While `chrome.permissions` does properly add/remove permissions, there's a problem with assigning the `JsObject` namespace as a `final` variable that prevents it from working.

```dart
class ChromeIdentity extends ChromeApi {
static final JsObject _identity = chrome['identity'];
bool get available => _identity != null;
}
```

As above, `_identity` is set at instantiation. If the permission isn't granted at that point, `available` will evaluate to `false`. Later if the permission is added through `chrome.permissions`, `available` will continue to evaluate to `false` because `_identity` is `final`. This causes `UnsupportedError()` to be thrown even when the API has become supported.

This solution uses a getter to fetch the `JsObject` namespace, so if it is exposed later, it would then be accessible.

```dart
class ChromePermissions extends ChromeApi {
JsObject get _permissions => chrome['permissions'];
bool get available => _permissions != null;
}
```

Unfortunately this also requires a change to `ChromeStreamController` which wants a reference to the namespace. This solution passes a function returning the `JsObject` to the `ChromeStreamController`.

```dart
class ChromeStreamController {
JsObject get _api => _apiProvider();
final Function _apiProvider;
}
```

The `ChromeStreamController` are instantiated as below:
```dart
ChromePermissions._() {
var getApi = () => _permissions;
_onAdded =
new ChromeStreamController.oneArg(getApi, 'onAdded', _createPermissions);
_onRemoved =
new ChromeStreamController.oneArg(getApi, 'onRemoved', _createPermissions);
}
```