| 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 GetAvailability = requireNative('v8_context').GetAvailability; | 7 var GetAvailability = requireNative('v8_context').GetAvailability; |
| 8 if (!GetAvailability('app').is_available) { | 8 if (!GetAvailability('app').is_available) { |
| 9 exports.chromeApp = {}; | 9 exports.chromeApp = {}; |
| 10 exports.chromeHiddenApp = {}; | 10 exports.onInstallStateResponse = function(){}; |
| 11 return; | 11 return; |
| 12 } | 12 } |
| 13 | 13 |
| 14 var appNatives = requireNative('app'); | 14 var appNatives = requireNative('app'); |
| 15 var chrome = requireNative('chrome').GetChrome(); | 15 var chrome = requireNative('chrome').GetChrome(); |
| 16 var process = requireNative('process'); | 16 var process = requireNative('process'); |
| 17 var extensionId = process.GetExtensionId(); | 17 var extensionId = process.GetExtensionId(); |
| 18 var logActivity = requireNative('activityLogger'); | 18 var logActivity = requireNative('activityLogger'); |
| 19 | 19 |
| 20 function wrapForLogging(fun) { | 20 function wrapForLogging(fun) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 // | 54 // |
| 55 // So, define it manually, and let the getIsInstalled function act as its | 55 // So, define it manually, and let the getIsInstalled function act as its |
| 56 // documentation. | 56 // documentation. |
| 57 if (!extensionId) | 57 if (!extensionId) |
| 58 app.__defineGetter__('isInstalled', appNatives.GetIsInstalled); | 58 app.__defineGetter__('isInstalled', appNatives.GetIsInstalled); |
| 59 else | 59 else |
| 60 app.__defineGetter__('isInstalled', | 60 app.__defineGetter__('isInstalled', |
| 61 wrapForLogging(appNatives.GetIsInstalled)); | 61 wrapForLogging(appNatives.GetIsInstalled)); |
| 62 | 62 |
| 63 // Called by app_bindings.cc. | 63 // Called by app_bindings.cc. |
| 64 // This becomes chromeHidden.app | 64 function onInstallStateResponse(state, callbackId) { |
| 65 var chromeHiddenApp = { | 65 var callback = callbacks[callbackId]; |
| 66 onInstallStateResponse: function(state, callbackId) { | 66 delete callbacks[callbackId]; |
| 67 if (callbackId) { | 67 if (callback) |
| 68 callbacks[callbackId](state); | 68 callback(state); |
| 69 delete callbacks[callbackId]; | 69 } |
| 70 } | |
| 71 } | |
| 72 }; | |
| 73 | 70 |
| 74 // TODO(kalman): move this stuff to its own custom bindings. | |
| 75 var callbacks = {}; | 71 var callbacks = {}; |
| 76 var nextCallbackId = 1; | 72 var nextCallbackId = 1; |
| 77 | 73 |
| 78 app.installState = function getInstallState(callback) { | 74 app.installState = function getInstallState(callback) { |
| 79 var callbackId = nextCallbackId++; | 75 var callbackId = nextCallbackId++; |
| 80 callbacks[callbackId] = callback; | 76 callbacks[callbackId] = callback; |
| 81 appNatives.GetInstallState(callbackId); | 77 appNatives.GetInstallState(callbackId); |
| 82 }; | 78 }; |
| 83 if (extensionId) | 79 if (extensionId) |
| 84 app.installState = wrapForLogging(app.installState); | 80 app.installState = wrapForLogging(app.installState); |
| 85 | 81 |
| 86 // These must match the names in InstallAppbinding() in | 82 // This must match InstallAppbinding() in |
| 87 // chrome/renderer/extensions/dispatcher.cc. | 83 // chrome/renderer/extensions/dispatcher.cc. |
| 84 // |
| 85 // TODO(kalman): we can get rid of this when the bindings code can be run in |
| 86 // all renderers - very soon! |
| 88 exports.chromeApp = app; | 87 exports.chromeApp = app; |
| 89 exports.chromeHiddenApp = chromeHiddenApp; | 88 exports.onInstallStateResponse = onInstallStateResponse; |
| OLD | NEW |