| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Custom bindings for the app API. |
| 6 |
| 7 var appNatives = requireNative('app'); |
| 8 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
| 9 |
| 10 chromeHidden.registerCustomHook('app', function(bindingsAPI) { |
| 11 var apiFunctions = bindingsAPI.apiFunctions; |
| 12 |
| 13 // Note: everything in chrome.app is synchronous. |
| 14 apiFunctions.setHandleRequest('getIsInstalled', appNatives.GetIsInstalled); |
| 15 apiFunctions.setHandleRequest('install', appNatives.Install); |
| 16 apiFunctions.setHandleRequest('getDetails', appNatives.GetDetails); |
| 17 apiFunctions.setHandleRequest('getDetailsForFrame', |
| 18 appNatives.GetDetailsForFrame); |
| 19 |
| 20 // Tricky; "getIsInstalled" is actually exposed as the getter "isInstalled", |
| 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). |
| 23 // |
| 24 // So, define it manually, and let the getIsInstalled function act as its |
| 25 // documentation. |
| 26 chrome.app.__defineGetter__('isInstalled', appNatives.GetIsInstalled); |
| 27 |
| 28 // Called by app_bindings.cc. |
| 29 chromeHidden.app = { |
| 30 onGetAppNotifyChannelResponse: function(channelId, error, callbackId) { |
| 31 if (callbackId) { |
| 32 callbacks[callbackId](channelId, error); |
| 33 delete callbacks[callbackId]; |
| 34 } |
| 35 } |
| 36 }; |
| 37 |
| 38 // appNotification stuff. |
| 39 // |
| 40 // TODO(kalman): move this stuff to its own custom bindings. |
| 41 // It will be bit tricky since I'll need to look into why there are |
| 42 // permissions defined for app notifications, yet this always sets it up? |
| 43 var callbacks = {}; |
| 44 var nextCallbackId = 1; |
| 45 |
| 46 chrome.appNotifications = new function() { |
| 47 this.getChannel = function(clientId, callback) { |
| 48 var callbackId = 0; |
| 49 if (callback) { |
| 50 callbackId = nextCallbackId++; |
| 51 callbacks[callbackId] = callback; |
| 52 } |
| 53 appNatives.GetAppNotifyChannel(clientId, callbackId); |
| 54 }; |
| 55 }(); |
| 56 }); |
| OLD | NEW |