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