OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Custom bindings for the app API. | 5 // Custom bindings for the app API. |
6 | 6 |
7 var appNatives = requireNative('app'); | 7 var appNatives = requireNative('app'); |
| 8 var DCHECK = requireNative('logging').DCHECK; |
| 9 var chrome = requireNative('chrome').GetChrome(); |
8 | 10 |
9 // This becomes chrome.app | 11 // This becomes chrome.app |
10 var app = { | 12 var app = { |
11 getIsInstalled: appNatives.GetIsInstalled, | 13 getIsInstalled: appNatives.GetIsInstalled, |
12 install: appNatives.Install, | 14 install: appNatives.Install, |
13 getDetails: appNatives.GetDetails, | 15 getDetails: appNatives.GetDetails, |
14 getDetailsForFrame: appNatives.GetDetailsForFrame, | 16 getDetailsForFrame: appNatives.GetDetailsForFrame, |
15 runningState: appNatives.GetRunningState | 17 runningState: appNatives.GetRunningState |
16 }; | 18 }; |
17 | 19 |
18 // Tricky; "getIsInstalled" is actually exposed as the getter "isInstalled", | 20 // Tricky; "getIsInstalled" is actually exposed as the getter "isInstalled", |
19 // but we don't have a way to express this in the schema JSON (nor is it | 21 // but we don't have a way to express this in the schema JSON (nor is it |
20 // worth it for this one special case). | 22 // worth it for this one special case). |
21 // | 23 // |
22 // So, define it manually, and let the getIsInstalled function act as its | 24 // So, define it manually, and let the getIsInstalled function act as its |
23 // documentation. | 25 // documentation. |
24 app.__defineGetter__('isInstalled', appNatives.GetIsInstalled); | 26 app.__defineGetter__('isInstalled', appNatives.GetIsInstalled); |
25 | 27 |
| 28 // Define getters for app sub-APIs like app.runtime. |
| 29 // TODO(cduvall): Take this out once object chain works. |
| 30 app.__defineGetter__('runtime', function() { |
| 31 return chrome['app.runtime']; |
| 32 }); |
| 33 |
| 34 app.__defineGetter__('window', function() { |
| 35 return chrome['app.window']; |
| 36 }); |
| 37 |
| 38 app.__defineGetter__('currentWindowInternal', function() { |
| 39 return chrome['app.currentWindowInternal']; |
| 40 }); |
| 41 |
26 // Called by app_bindings.cc. | 42 // Called by app_bindings.cc. |
27 // This becomes chromeHidden.app | 43 // This becomes chromeHidden.app |
28 var chromeHiddenApp = { | 44 var chromeHiddenApp = { |
29 onGetAppNotifyChannelResponse: function(channelId, error, callbackId) { | 45 onGetAppNotifyChannelResponse: function(channelId, error, callbackId) { |
30 if (callbackId) { | 46 if (callbackId) { |
31 callbacks[callbackId](channelId, error); | 47 callbacks[callbackId](channelId, error); |
32 delete callbacks[callbackId]; | 48 delete callbacks[callbackId]; |
33 } | 49 } |
34 }, | 50 }, |
35 | 51 |
(...skipping 29 matching lines...) Expand all Loading... |
65 var callbackId = nextCallbackId++; | 81 var callbackId = nextCallbackId++; |
66 callbacks[callbackId] = callback; | 82 callbacks[callbackId] = callback; |
67 appNatives.GetInstallState(callbackId); | 83 appNatives.GetInstallState(callbackId); |
68 }; | 84 }; |
69 | 85 |
70 // These must match the names in InstallAppBindings() in | 86 // These must match the names in InstallAppBindings() in |
71 // chrome/renderer/extensions/dispatcher.cc. | 87 // chrome/renderer/extensions/dispatcher.cc. |
72 exports.chromeApp = app; | 88 exports.chromeApp = app; |
73 exports.chromeAppNotifications = appNotifications; | 89 exports.chromeAppNotifications = appNotifications; |
74 exports.chromeHiddenApp = chromeHiddenApp; | 90 exports.chromeHiddenApp = chromeHiddenApp; |
OLD | NEW |