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. | 71 // TODO(kalman): move this stuff to its own custom bindings. |
75 var callbacks = {}; | 72 var callbacks = {}; |
76 var nextCallbackId = 1; | 73 var nextCallbackId = 1; |
77 | 74 |
78 app.installState = function getInstallState(callback) { | 75 app.installState = function getInstallState(callback) { |
79 var callbackId = nextCallbackId++; | 76 var callbackId = nextCallbackId++; |
80 callbacks[callbackId] = callback; | 77 callbacks[callbackId] = callback; |
81 appNatives.GetInstallState(callbackId); | 78 appNatives.GetInstallState(callbackId); |
82 }; | 79 }; |
83 if (extensionId) | 80 if (extensionId) |
84 app.installState = wrapForLogging(app.installState); | 81 app.installState = wrapForLogging(app.installState); |
85 | 82 |
86 // These must match the names in InstallAppbinding() in | 83 // This must match InstallAppBindings() in |
87 // chrome/renderer/extensions/dispatcher.cc. | 84 // chrome/renderer/extensions/dispatcher.cc. |
88 exports.chromeApp = app; | 85 exports.chromeApp = app; |
89 exports.chromeHiddenApp = chromeHiddenApp; | 86 exports.onInstallStateResponse = onInstallStateResponse; |
OLD | NEW |