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 | 8 |
9 // This becomes chrome.app | 9 // This becomes chrome.app |
10 var app = { | 10 var app = { |
11 getIsInstalled: appNatives.GetIsInstalled, | 11 getIsInstalled: appNatives.GetIsInstalled, |
12 install: appNatives.Install, | 12 install: appNatives.Install, |
13 getDetails: appNatives.GetDetails, | 13 getDetails: appNatives.GetDetails, |
14 getDetailsForFrame: appNatives.GetDetailsForFrame | 14 getDetailsForFrame: appNatives.GetDetailsForFrame, |
| 15 runningState: appNatives.GetRunningState |
15 }; | 16 }; |
16 | 17 |
17 // Tricky; "getIsInstalled" is actually exposed as the getter "isInstalled", | 18 // Tricky; "getIsInstalled" is actually exposed as the getter "isInstalled", |
18 // but we don't have a way to express this in the schema JSON (nor is it | 19 // but we don't have a way to express this in the schema JSON (nor is it |
19 // worth it for this one special case). | 20 // worth it for this one special case). |
20 // | 21 // |
21 // So, define it manually, and let the getIsInstalled function act as its | 22 // So, define it manually, and let the getIsInstalled function act as its |
22 // documentation. | 23 // documentation. |
23 app.__defineGetter__('isInstalled', appNatives.GetIsInstalled); | 24 app.__defineGetter__('isInstalled', appNatives.GetIsInstalled); |
24 | 25 |
25 // Called by app_bindings.cc. | 26 // Called by app_bindings.cc. |
26 // This becomes chromeHidden.app | 27 // This becomes chromeHidden.app |
27 var chromeHiddenApp = { | 28 var chromeHiddenApp = { |
28 onGetAppNotifyChannelResponse: function(channelId, error, callbackId) { | 29 onGetAppNotifyChannelResponse: function(channelId, error, callbackId) { |
29 if (callbackId) { | 30 if (callbackId) { |
30 callbacks[callbackId](channelId, error); | 31 callbacks[callbackId](channelId, error); |
31 delete callbacks[callbackId]; | 32 delete callbacks[callbackId]; |
32 } | 33 } |
| 34 }, |
| 35 |
| 36 onInstallStateResponse: function(state, callbackId) { |
| 37 if (callbackId) { |
| 38 callbacks[callbackId](state); |
| 39 delete callbacks[callbackId]; |
| 40 } |
33 } | 41 } |
34 }; | 42 }; |
35 | 43 |
36 // appNotification stuff. | 44 // appNotification stuff. |
37 // | 45 // |
38 // TODO(kalman): move this stuff to its own custom bindings. | 46 // TODO(kalman): move this stuff to its own custom bindings. |
39 // It will be bit tricky since I'll need to look into why there are | 47 // It will be bit tricky since I'll need to look into why there are |
40 // permissions defined for app notifications, yet this always sets it up? | 48 // permissions defined for app notifications, yet this always sets it up? |
41 var callbacks = {}; | 49 var callbacks = {}; |
42 var nextCallbackId = 1; | 50 var nextCallbackId = 1; |
43 | 51 |
44 // This becomes chrome.appNotifications. | 52 // This becomes chrome.appNotifications. |
45 var appNotifications = { | 53 var appNotifications = { |
46 getChannel: function getChannel(clientId, callback) { | 54 getChannel: function getChannel(clientId, callback) { |
47 var callbackId = 0; | 55 var callbackId = 0; |
48 if (callback) { | 56 if (callback) { |
49 callbackId = nextCallbackId++; | 57 callbackId = nextCallbackId++; |
50 callbacks[callbackId] = callback; | 58 callbacks[callbackId] = callback; |
51 } | 59 } |
52 appNatives.GetAppNotifyChannel(clientId, callbackId); | 60 appNatives.GetAppNotifyChannel(clientId, callbackId); |
53 } | 61 } |
54 }; | 62 }; |
55 | 63 |
| 64 app.installState = function getInstallState(callback) { |
| 65 var callbackId = nextCallbackId++; |
| 66 callbacks[callbackId] = callback; |
| 67 appNatives.GetInstallState(callbackId); |
| 68 }; |
| 69 |
56 // These must match the names in InstallAppBindings() in | 70 // These must match the names in InstallAppBindings() in |
57 // extension_dispatcher.cc. | 71 // extension_dispatcher.cc. |
58 exports.chromeApp = app; | 72 exports.chromeApp = app; |
59 exports.chromeAppNotifications = appNotifications; | 73 exports.chromeAppNotifications = appNotifications; |
60 exports.chromeHiddenApp = chromeHiddenApp; | 74 exports.chromeHiddenApp = chromeHiddenApp; |
OLD | NEW |