Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: chrome/renderer/resources/extensions/app_custom_bindings.js

Issue 2859233003: [Extensions] Improve app custom bindings (Closed)
Patch Set: . Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/renderer/extensions/chrome_extensions_dispatcher_delegate.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 var isInstalled = wrapForLogging(appNatives.GetIsInstalled);
39 $Object.defineProperty(
40 app, 'isInstalled',
41 {
42 __proto__: null,
43 configurable: true,
44 enumerable: true,
45 get: function() { return isInstalled(); },
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 var installState = wrapForLogging(getInstallState);
73 $Object.defineProperty(
74 app, 'installState',
75 {
76 __proto__: null,
77 configurable: true,
78 enumerable: true,
79 get: function() { return installState; },
jbroman 2017/05/08 14:25:25 This makes it an accessor property as opposed to a
Devlin 2017/05/11 14:30:38 Done.
80 });
65 81
66 exports.$set('binding', app); 82 exports.$set('binding', app);
67 exports.$set('onInstallStateResponse', onInstallStateResponse); 83 exports.$set('onInstallStateResponse', onInstallStateResponse);
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/chrome_extensions_dispatcher_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698