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 binding for the app API. | 5 // Custom binding for the app API. |
6 | 6 |
7 var appNatives = requireNative('app'); | 7 var appNatives = requireNative('app'); |
8 var chrome = requireNative('chrome').GetChrome(); | 8 var chrome = requireNative('chrome').GetChrome(); |
9 var GetAvailability = requireNative('v8_context').GetAvailability; | 9 var GetAvailability = requireNative('v8_context').GetAvailability; |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 // 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 |
22 // worth it for this one special case). | 22 // worth it for this one special case). |
23 // | 23 // |
24 // 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 |
25 // documentation. | 25 // documentation. |
26 app.__defineGetter__('isInstalled', appNatives.GetIsInstalled); | 26 app.__defineGetter__('isInstalled', appNatives.GetIsInstalled); |
27 | 27 |
28 // Called by app_bindings.cc. | 28 // Called by app_bindings.cc. |
29 // This becomes chromeHidden.app | 29 // This becomes chromeHidden.app |
30 var chromeHiddenApp = { | 30 var chromeHiddenApp = { |
31 onGetAppNotifyChannelResponse: function(channelId, error, callbackId) { | |
32 if (callbackId) { | |
33 callbacks[callbackId](channelId, error); | |
34 delete callbacks[callbackId]; | |
35 } | |
36 }, | |
37 | |
38 onInstallStateResponse: function(state, callbackId) { | 31 onInstallStateResponse: function(state, callbackId) { |
39 if (callbackId) { | 32 if (callbackId) { |
40 callbacks[callbackId](state); | 33 callbacks[callbackId](state); |
41 delete callbacks[callbackId]; | 34 delete callbacks[callbackId]; |
42 } | 35 } |
43 } | 36 } |
44 }; | 37 }; |
45 | 38 |
46 // appNotification stuff. | 39 // TODO(kalman): move this stuff to its own custom bindings. |
47 // | |
48 // TODO(kalman): move this stuff to its own custom binding. | |
49 // It will be bit tricky since I'll need to look into why there are | |
50 // permissions defined for app notifications, yet this always sets it up? | |
51 var callbacks = {}; | 40 var callbacks = {}; |
52 var nextCallbackId = 1; | 41 var nextCallbackId = 1; |
53 | 42 |
54 // This becomes chrome.appNotifications. | |
55 var appNotifications = { | |
56 getChannel: function getChannel(clientId, callback) { | |
57 var callbackId = 0; | |
58 if (callback) { | |
59 callbackId = nextCallbackId++; | |
60 callbacks[callbackId] = callback; | |
61 } | |
62 appNatives.GetAppNotifyChannel(clientId, callbackId); | |
63 } | |
64 }; | |
65 | |
66 app.installState = function getInstallState(callback) { | 43 app.installState = function getInstallState(callback) { |
67 var callbackId = nextCallbackId++; | 44 var callbackId = nextCallbackId++; |
68 callbacks[callbackId] = callback; | 45 callbacks[callbackId] = callback; |
69 appNatives.GetInstallState(callbackId); | 46 appNatives.GetInstallState(callbackId); |
70 }; | 47 }; |
71 | 48 |
72 // These must match the names in InstallAppbinding() in | 49 // These must match the names in InstallAppbinding() in |
73 // chrome/renderer/extensions/dispatcher.cc. | 50 // chrome/renderer/extensions/dispatcher.cc. |
74 var availability = GetAvailability('app'); | 51 var availability = GetAvailability('app'); |
75 if (availability.is_available) { | 52 if (availability.is_available) { |
76 exports.chromeApp = app; | 53 exports.chromeApp = app; |
77 exports.chromeAppNotifications = appNotifications; | |
78 exports.chromeHiddenApp = chromeHiddenApp; | 54 exports.chromeHiddenApp = chromeHiddenApp; |
79 } | 55 } |
OLD | NEW |