Index: chrome/renderer/resources/extensions/app_custom_bindings.js |
diff --git a/chrome/renderer/resources/extensions/app_custom_bindings.js b/chrome/renderer/resources/extensions/app_custom_bindings.js |
index 303bea6932d1fc09c8ee3fe0b536a7013d339a9a..f69f65f18a6cd43cd837b1b7e3fb3371278430ca 100644 |
--- a/chrome/renderer/resources/extensions/app_custom_bindings.js |
+++ b/chrome/renderer/resources/extensions/app_custom_bindings.js |
@@ -13,15 +13,37 @@ if (!GetAvailability('app').is_available) { |
var appNatives = requireNative('app'); |
var chrome = requireNative('chrome').GetChrome(); |
+var process = requireNative('process'); |
+var extensionId = process.GetExtensionId(); |
+var logActivity = requireNative('activityLogger').LogActivity; |
+ |
+function wrapForLogging(fun) { |
+ var id = extensionId; |
+ var slicer = Array.prototype.slice; |
+ return (function() { |
+ logActivity("API", id, "app." + fun.name, slicer.call(arguments)); |
+ return fun.apply(this, arguments); |
+ }); |
+} |
// This becomes chrome.app |
-var app = { |
- getIsInstalled: appNatives.GetIsInstalled, |
- install: appNatives.Install, |
- getDetails: appNatives.GetDetails, |
- getDetailsForFrame: appNatives.GetDetailsForFrame, |
- runningState: appNatives.GetRunningState |
-}; |
+if (!extensionId) { |
Matt Perry
2013/04/09 20:56:59
When can the extensionId be NULL?
felt
2013/04/10 00:21:38
If this is a website, extensionId is null and we d
|
+ var app = { |
Matt Perry
2013/04/09 20:56:59
I think you need to declare "var app;" at toplevel
felt
2013/04/10 00:21:38
It works fine actually. But maybe it's more clear
|
+ getIsInstalled: appNatives.GetIsInstalled, |
+ install: appNatives.Install, |
+ getDetails: appNatives.GetDetails, |
+ getDetailsForFrame: appNatives.GetDetailsForFrame, |
+ runningState: appNatives.GetRunningState |
+ }; |
+} else { |
+ var app = { |
+ getIsInstalled: wrapForLogging(appNatives.GetIsInstalled), |
+ install: wrapForLogging(appNatives.Install), |
+ getDetails: wrapForLogging(appNatives.GetDetails), |
+ getDetailsForFrame: wrapForLogging(appNatives.GetDetailsForFrame), |
+ runningState: wrapForLogging(appNatives.GetRunningState) |
+ }; |
+} |
// Tricky; "getIsInstalled" is actually exposed as the getter "isInstalled", |
// but we don't have a way to express this in the schema JSON (nor is it |
@@ -29,7 +51,11 @@ var app = { |
// |
// So, define it manually, and let the getIsInstalled function act as its |
// documentation. |
-app.__defineGetter__('isInstalled', appNatives.GetIsInstalled); |
+if (!extensionId) |
+ app.__defineGetter__('isInstalled', appNatives.GetIsInstalled); |
+else |
+ app.__defineGetter__('isInstalled', |
+ wrapForLogging(appNatives.GetIsInstalled)); |
// Called by app_bindings.cc. |
// This becomes chromeHidden.app |
@@ -51,6 +77,8 @@ app.installState = function getInstallState(callback) { |
callbacks[callbackId] = callback; |
appNatives.GetInstallState(callbackId); |
}; |
+if (extensionId) |
+ app.installState = wrapForLogging(app.installState); |
// These must match the names in InstallAppbinding() in |
// chrome/renderer/extensions/dispatcher.cc. |