Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1061)

Unified Diff: chrome/renderer/resources/extensions/app_custom_bindings.js

Issue 11571014: Lazy load chrome.* APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: apitest.js Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);

Powered by Google App Engine
This is Rietveld 408576698