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.onInstallStateResponse = function(){}; | 10 exports.onInstallStateResponse = function(){}; |
11 return; | 11 return; |
12 } | 12 } |
13 | 13 |
14 var appNatives = requireNative('app'); | 14 var appNatives = requireNative('app'); |
15 var process = requireNative('process'); | 15 var process = requireNative('process'); |
16 var extensionId = process.GetExtensionId(); | 16 var extensionId = process.GetExtensionId(); |
17 var logActivity = requireNative('activityLogger'); | 17 var logActivity = requireNative('activityLogger'); |
18 | 18 |
19 function wrapForLogging(fun) { | 19 function wrapForLogging(fun) { |
20 var id = extensionId; | 20 var id = extensionId; |
21 return (function() { | 21 return (function() { |
22 // TODO(ataly): We need to make sure we use the right prototype for | 22 // TODO(ataly): We need to make sure we use the right prototype for |
23 // fun.apply. Array slice can either be rewritten or similarly defined. | 23 // fun.apply. Array slice can either be rewritten or similarly defined. |
24 logActivity.LogAPICall(id, "app." + fun.name, | 24 logActivity.LogAPICall(id, "app." + fun.name, |
25 Array.prototype.slice.call(arguments)); | 25 $Array.slice(arguments)); |
26 return fun.apply(this, arguments); | 26 return $Function.apply(fun, this, arguments); |
27 }); | 27 }); |
28 } | 28 } |
29 | 29 |
30 // This becomes chrome.app | 30 // This becomes chrome.app |
31 var app; | 31 var app; |
32 if (!extensionId) { | 32 if (!extensionId) { |
33 app = { | 33 app = { |
34 getIsInstalled: appNatives.GetIsInstalled, | 34 getIsInstalled: appNatives.GetIsInstalled, |
35 getDetails: appNatives.GetDetails, | 35 getDetails: appNatives.GetDetails, |
36 getDetailsForFrame: appNatives.GetDetailsForFrame, | 36 getDetailsForFrame: appNatives.GetDetailsForFrame, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 callbacks[callbackId] = callback; | 74 callbacks[callbackId] = callback; |
75 appNatives.GetInstallState(callbackId); | 75 appNatives.GetInstallState(callbackId); |
76 }; | 76 }; |
77 if (extensionId) | 77 if (extensionId) |
78 app.installState = wrapForLogging(app.installState); | 78 app.installState = wrapForLogging(app.installState); |
79 | 79 |
80 // This must match InstallAppBindings() in | 80 // This must match InstallAppBindings() in |
81 // chrome/renderer/extensions/dispatcher.cc. | 81 // chrome/renderer/extensions/dispatcher.cc. |
82 exports.chromeApp = app; | 82 exports.chromeApp = app; |
83 exports.onInstallStateResponse = onInstallStateResponse; | 83 exports.onInstallStateResponse = onInstallStateResponse; |
OLD | NEW |