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

Unified Diff: chrome/renderer/resources/extensions/binding.js

Issue 12517011: Added activity logging for ext APIs with custom bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Modified setHandleRequest to avoid double logging Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/resources/extensions/binding.js
diff --git a/chrome/renderer/resources/extensions/binding.js b/chrome/renderer/resources/extensions/binding.js
index 9fdb392e9aae13d9e6bee6836718a4ecaecd2efa..859a9c3da1c8116439b13cd214bc0c58acb1c91f 100644
--- a/chrome/renderer/resources/extensions/binding.js
+++ b/chrome/renderer/resources/extensions/binding.js
@@ -17,13 +17,15 @@ var schemaRegistry = requireNative('schema_registry');
var schemaUtils = require('schemaUtils');
var sendRequest = require('sendRequest').sendRequest;
var utils = require('utils');
+var logActivity = requireNative('activityLogger').LogActivity;
// Stores the name and definition of each API function, with methods to
// modify their behaviour (such as a custom way to handle requests to the
// API, a custom callback, etc).
-function APIFunctions() {
+function APIFunctions(namespace) {
this.apiFunctions_ = {};
this.unavailableApiFunctions_ = {};
+ this.namespace = namespace;
}
APIFunctions.prototype.register = function(apiName, apiFunction) {
@@ -46,9 +48,22 @@ APIFunctions.prototype.setHook_ =
this.apiFunctions_[apiName][propertyName] = customizedFunction;
};
+// Logs API calls to the Activity Log. However we do *not* want to log API
+// calls that use ExtensionFunctions. Set usesExtensionFunction=true if your
+// API call uses an ExtensionFunction (i.e., invokes sendRequest).
APIFunctions.prototype.setHandleRequest =
- function(apiName, customizedFunction) {
- return this.setHook_(apiName, 'handleRequest', customizedFunction);
+ function(apiName, customizedFunction, usesExtensionFunction) {
+ if (usesExtensionFunction) {
+ return this.setHook_(apiName, 'handleRequest', customizedFunction);
+ } else {
+ var prefix = this.namespace;
+ return this.setHook_(apiName, 'handleRequest',
+ function() {
+ logActivity(extensionId, prefix + "." + apiName,
+ Array.prototype.slice.call(arguments));
+ return customizedFunction.apply(this, arguments);
+ });
+ }
};
APIFunctions.prototype.setUpdateArgumentsPostValidate =
@@ -121,7 +136,7 @@ var platform = getPlatform();
function Binding(schema) {
this.schema_ = schema;
- this.apiFunctions_ = new APIFunctions();
+ this.apiFunctions_ = new APIFunctions(schema.namespace);
this.customEvent_ = null;
this.customTypes_ = {};
this.customHooks_ = [];

Powered by Google App Engine
This is Rietveld 408576698