Chromium Code Reviews| Index: chrome/renderer/resources/extensions/app_custom_bindings.js |
| diff --git a/chrome/renderer/resources/extensions/app_custom_bindings.js b/chrome/renderer/resources/extensions/app_custom_bindings.js |
| index 1a8bbcc7d6dab3ecaf05cee5574a61aed13e9ca4..7fdfc262c2ffff1d8672ab23b45d2e36a1d291e1 100644 |
| --- a/chrome/renderer/resources/extensions/app_custom_bindings.js |
| +++ b/chrome/renderer/resources/extensions/app_custom_bindings.js |
| @@ -2,9 +2,12 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -// Custom bindings for the app API. |
| +// Custom binding for the app API. |
| var appNatives = requireNative('app'); |
| +var chrome = requireNative('chrome').GetChrome(); |
| +var GetAvailability = requireNative('v8_context').GetAvailability; |
| +var DCHECK = requireNative('logging').DCHECK; |
| // This becomes chrome.app |
| var app = { |
| @@ -23,7 +26,7 @@ var app = { |
| // documentation. |
| app.__defineGetter__('isInstalled', appNatives.GetIsInstalled); |
| -// Called by app_bindings.cc. |
| +// Called by app_binding.cc. |
| // This becomes chromeHidden.app |
| var chromeHiddenApp = { |
| onGetAppNotifyChannelResponse: function(channelId, error, callbackId) { |
| @@ -43,7 +46,7 @@ var chromeHiddenApp = { |
| // appNotification stuff. |
| // |
| -// TODO(kalman): move this stuff to its own custom bindings. |
| +// TODO(kalman): move this stuff to its own custom binding. |
| // It will be bit tricky since I'll need to look into why there are |
| // permissions defined for app notifications, yet this always sets it up? |
| var callbacks = {}; |
| @@ -67,8 +70,23 @@ app.installState = function getInstallState(callback) { |
| appNatives.GetInstallState(callbackId); |
| }; |
| -// These must match the names in InstallAppBindings() in |
| +function defineCheckAvailabilityGetter(name, apiName, target) { |
|
not at google - send to devlin
2013/02/13 01:45:49
defineLazyGetter?
Comment why it's necessary?
cduvall
2013/02/15 00:40:28
This actually doesn't need the lazy getter anymore
|
| + exports.__defineGetter__(name, function() { |
| + var availability = GetAvailability(apiName); |
| + if (!availability.is_available) { |
| + // If this API is not available, return undefined. An exception is not |
| + // thrown like the other APIs because it is not guaranteed that this will |
| + // be loaded in a try catch block. |
| + return; |
|
not at google - send to devlin
2013/02/13 01:45:49
might as well say return undefined;
cduvall
2013/02/15 00:40:28
Done.
|
| + } |
| + return target; |
| + }); |
| +} |
| + |
| +// These must match the names in InstallAppbinding() in |
| // chrome/renderer/extensions/dispatcher.cc. |
| -exports.chromeApp = app; |
| -exports.chromeAppNotifications = appNotifications; |
| -exports.chromeHiddenApp = chromeHiddenApp; |
| +defineCheckAvailabilityGetter('chromeApp', 'app', app); |
| +defineCheckAvailabilityGetter('chromeAppNotifications', |
| + 'app', |
| + appNotifications); |
| +defineCheckAvailabilityGetter('chromeHiddenApp', 'app', chromeHiddenApp); |