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 appNatives = requireNative('app'); | 7 var appNatives = requireNative('app'); |
8 var process = requireNative('process'); | 8 var process = requireNative('process'); |
9 var extensionId = process.GetExtensionId(); | 9 var extensionId = process.GetExtensionId(); |
10 var logActivity = requireNative('activityLogger'); | 10 var logActivity = requireNative('activityLogger'); |
(...skipping 17 matching lines...) Expand all Loading... | |
28 getDetails: wrapForLogging(appNatives.GetDetails), | 28 getDetails: wrapForLogging(appNatives.GetDetails), |
29 runningState: wrapForLogging(appNatives.GetRunningState) | 29 runningState: wrapForLogging(appNatives.GetRunningState) |
30 }; | 30 }; |
31 | 31 |
32 // Tricky; "getIsInstalled" is actually exposed as the getter "isInstalled", | 32 // Tricky; "getIsInstalled" is actually exposed as the getter "isInstalled", |
33 // but we don't have a way to express this in the schema JSON (nor is it | 33 // but we don't have a way to express this in the schema JSON (nor is it |
34 // worth it for this one special case). | 34 // worth it for this one special case). |
35 // | 35 // |
36 // So, define it manually, and let the getIsInstalled function act as its | 36 // So, define it manually, and let the getIsInstalled function act as its |
37 // documentation. | 37 // documentation. |
38 app.__defineGetter__('isInstalled', wrapForLogging(appNatives.GetIsInstalled)); | 38 $Object.defineProperty( |
Devlin
2017/05/04 18:58:50
all these changes are just to guard against untrus
| |
39 app, 'isInstalled', | |
40 { | |
41 __proto__: null, | |
42 configurable: true, | |
43 enumerable: true, | |
44 writable: true, | |
45 get: wrapForLogging(appNatives.GetIsInstalled), | |
46 }); | |
39 | 47 |
40 // Called by app_bindings.cc. | 48 // Called by app_bindings.cc. |
41 function onInstallStateResponse(state, callbackId) { | 49 function onInstallStateResponse(state, callbackId) { |
42 var callback = callbacks[callbackId]; | 50 var callback = callbacks[callbackId]; |
43 delete callbacks[callbackId]; | 51 delete callbacks[callbackId]; |
44 if (typeof(callback) == 'function') { | 52 if (typeof callback == 'function') { |
45 try { | 53 try { |
46 callback(state); | 54 callback(state); |
47 } catch (e) { | 55 } catch (e) { |
48 console.error('Exception in chrome.app.installState response handler: ' + | 56 console.error('Exception in chrome.app.installState response handler: ' + |
49 e.stack); | 57 e.stack); |
50 } | 58 } |
51 } | 59 } |
52 } | 60 } |
53 | 61 |
54 // TODO(kalman): move this stuff to its own custom bindings. | 62 // TODO(kalman): move this stuff to its own custom bindings. |
55 var callbacks = {}; | 63 var callbacks = { __proto__: null }; |
56 var nextCallbackId = 1; | 64 var nextCallbackId = 1; |
57 | 65 |
58 app.installState = function getInstallState(callback) { | 66 function getInstallState(callback) { |
59 var callbackId = nextCallbackId++; | 67 var callbackId = nextCallbackId++; |
60 callbacks[callbackId] = callback; | 68 callbacks[callbackId] = callback; |
61 appNatives.GetInstallState(callbackId); | 69 appNatives.GetInstallState(callbackId); |
62 }; | 70 } |
63 if (extensionId) | 71 |
64 app.installState = wrapForLogging(app.installState); | 72 $Object.defineProperty( |
73 app, 'installState', | |
74 { | |
75 __proto__: null, | |
76 configurable: true, | |
77 enumerable: true, | |
78 writable: true, | |
79 get: wrapForLogging(getInstallState), | |
80 }); | |
65 | 81 |
66 exports.$set('binding', app); | 82 exports.$set('binding', app); |
67 exports.$set('onInstallStateResponse', onInstallStateResponse); | 83 exports.$set('onInstallStateResponse', onInstallStateResponse); |
OLD | NEW |