| 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 bindings for the app API. |
| 6 | 6 |
| 7 var appNatives = requireNative('app'); | 7 var appNatives = requireNative('app'); |
| 8 var chrome = requireNative('chrome').GetChrome(); | |
| 9 var GetAvailability = requireNative('v8_context').GetAvailability; | |
| 10 | 8 |
| 11 // This becomes chrome.app | 9 // This becomes chrome.app |
| 12 var app = { | 10 var app = { |
| 13 getIsInstalled: appNatives.GetIsInstalled, | 11 getIsInstalled: appNatives.GetIsInstalled, |
| 14 install: appNatives.Install, | 12 install: appNatives.Install, |
| 15 getDetails: appNatives.GetDetails, | 13 getDetails: appNatives.GetDetails, |
| 16 getDetailsForFrame: appNatives.GetDetailsForFrame, | 14 getDetailsForFrame: appNatives.GetDetailsForFrame, |
| 17 runningState: appNatives.GetRunningState | 15 runningState: appNatives.GetRunningState |
| 18 }; | 16 }; |
| 19 | 17 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 38 onInstallStateResponse: function(state, callbackId) { | 36 onInstallStateResponse: function(state, callbackId) { |
| 39 if (callbackId) { | 37 if (callbackId) { |
| 40 callbacks[callbackId](state); | 38 callbacks[callbackId](state); |
| 41 delete callbacks[callbackId]; | 39 delete callbacks[callbackId]; |
| 42 } | 40 } |
| 43 } | 41 } |
| 44 }; | 42 }; |
| 45 | 43 |
| 46 // appNotification stuff. | 44 // appNotification stuff. |
| 47 // | 45 // |
| 48 // TODO(kalman): move this stuff to its own custom binding. | 46 // TODO(kalman): move this stuff to its own custom bindings. |
| 49 // 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 |
| 50 // permissions defined for app notifications, yet this always sets it up? | 48 // permissions defined for app notifications, yet this always sets it up? |
| 51 var callbacks = {}; | 49 var callbacks = {}; |
| 52 var nextCallbackId = 1; | 50 var nextCallbackId = 1; |
| 53 | 51 |
| 54 // This becomes chrome.appNotifications. | 52 // This becomes chrome.appNotifications. |
| 55 var appNotifications = { | 53 var appNotifications = { |
| 56 getChannel: function getChannel(clientId, callback) { | 54 getChannel: function getChannel(clientId, callback) { |
| 57 var callbackId = 0; | 55 var callbackId = 0; |
| 58 if (callback) { | 56 if (callback) { |
| 59 callbackId = nextCallbackId++; | 57 callbackId = nextCallbackId++; |
| 60 callbacks[callbackId] = callback; | 58 callbacks[callbackId] = callback; |
| 61 } | 59 } |
| 62 appNatives.GetAppNotifyChannel(clientId, callbackId); | 60 appNatives.GetAppNotifyChannel(clientId, callbackId); |
| 63 } | 61 } |
| 64 }; | 62 }; |
| 65 | 63 |
| 66 app.installState = function getInstallState(callback) { | 64 app.installState = function getInstallState(callback) { |
| 67 var callbackId = nextCallbackId++; | 65 var callbackId = nextCallbackId++; |
| 68 callbacks[callbackId] = callback; | 66 callbacks[callbackId] = callback; |
| 69 appNatives.GetInstallState(callbackId); | 67 appNatives.GetInstallState(callbackId); |
| 70 }; | 68 }; |
| 71 | 69 |
| 72 // These must match the names in InstallAppbinding() in | 70 // These must match the names in InstallAppBindings() in |
| 73 // chrome/renderer/extensions/dispatcher.cc. | 71 // chrome/renderer/extensions/dispatcher.cc. |
| 74 var availability = GetAvailability('app'); | 72 exports.chromeApp = app; |
| 75 if (availability.is_available) { | 73 exports.chromeAppNotifications = appNotifications; |
| 76 exports.chromeApp = app; | 74 exports.chromeHiddenApp = chromeHiddenApp; |
| 77 exports.chromeAppNotifications = appNotifications; | |
| 78 exports.chromeHiddenApp = chromeHiddenApp; | |
| 79 } | |
| OLD | NEW |