| 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 chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | |
| 9 | 8 |
| 10 chrome.app = { | 9 // This becomes chrome.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 }; | 15 }; |
| 16 | 16 |
| 17 // Tricky; "getIsInstalled" is actually exposed as the getter "isInstalled", | 17 // 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 | 18 // 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). | 19 // worth it for this one special case). |
| 20 // | 20 // |
| 21 // So, define it manually, and let the getIsInstalled function act as its | 21 // So, define it manually, and let the getIsInstalled function act as its |
| 22 // documentation. | 22 // documentation. |
| 23 chrome.app.__defineGetter__('isInstalled', appNatives.GetIsInstalled); | 23 app.__defineGetter__('isInstalled', appNatives.GetIsInstalled); |
| 24 | 24 |
| 25 // Called by app_bindings.cc. | 25 // Called by app_bindings.cc. |
| 26 chromeHidden.app = { | 26 // This becomes chromeHidden.app |
| 27 var chromeHiddenApp = { |
| 27 onGetAppNotifyChannelResponse: function(channelId, error, callbackId) { | 28 onGetAppNotifyChannelResponse: function(channelId, error, callbackId) { |
| 28 if (callbackId) { | 29 if (callbackId) { |
| 29 callbacks[callbackId](channelId, error); | 30 callbacks[callbackId](channelId, error); |
| 30 delete callbacks[callbackId]; | 31 delete callbacks[callbackId]; |
| 31 } | 32 } |
| 32 } | 33 } |
| 33 }; | 34 }; |
| 34 | 35 |
| 35 // appNotification stuff. | 36 // appNotification stuff. |
| 36 // | 37 // |
| 37 // TODO(kalman): move this stuff to its own custom bindings. | 38 // TODO(kalman): move this stuff to its own custom bindings. |
| 38 // It will be bit tricky since I'll need to look into why there are | 39 // It will be bit tricky since I'll need to look into why there are |
| 39 // permissions defined for app notifications, yet this always sets it up? | 40 // permissions defined for app notifications, yet this always sets it up? |
| 40 var callbacks = {}; | 41 var callbacks = {}; |
| 41 var nextCallbackId = 1; | 42 var nextCallbackId = 1; |
| 42 | 43 |
| 43 chrome.appNotifications = { | 44 // This becomes chrome.appNotifications. |
| 45 var appNotifications = { |
| 44 getChannel: function getChannel(clientId, callback) { | 46 getChannel: function getChannel(clientId, callback) { |
| 45 var callbackId = 0; | 47 var callbackId = 0; |
| 46 if (callback) { | 48 if (callback) { |
| 47 callbackId = nextCallbackId++; | 49 callbackId = nextCallbackId++; |
| 48 callbacks[callbackId] = callback; | 50 callbacks[callbackId] = callback; |
| 49 } | 51 } |
| 50 appNatives.GetAppNotifyChannel(clientId, callbackId); | 52 appNatives.GetAppNotifyChannel(clientId, callbackId); |
| 51 } | 53 } |
| 52 }; | 54 }; |
| 55 |
| 56 // These must match the names in InstallAppBindings() in |
| 57 // extension_dispatcher.cc. |
| 58 exports.chromeApp = app; |
| 59 exports.chromeAppNotifications = appNotifications; |
| 60 exports.chromeHiddenApp = chromeHiddenApp; |
| OLD | NEW |