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

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: Rebased 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 b5a65a206aac434733851eefb376202022a9c901..80c81242e7d2ca63da64bb1a40bcb68829ee973e 100644
--- a/chrome/renderer/resources/extensions/binding.js
+++ b/chrome/renderer/resources/extensions/binding.js
@@ -15,16 +15,19 @@ var extensionId = process.GetExtensionId();
var manifestVersion = process.GetManifestVersion();
var schemaRegistry = requireNative('schema_registry');
var schemaUtils = require('schemaUtils');
-var sendRequest = require('sendRequest').sendRequest;
var utils = require('utils');
var CHECK = requireNative('logging').CHECK;
+var sendRequestHandler = require('sendRequest');
+var sendRequest = sendRequestHandler.sendRequest;
+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) {
@@ -49,7 +52,17 @@ APIFunctions.prototype.setHook_ =
APIFunctions.prototype.setHandleRequest =
function(apiName, customizedFunction) {
- return this.setHook_(apiName, 'handleRequest', customizedFunction);
+ var prefix = this.namespace;
+ return this.setHook_(apiName, 'handleRequest',
+ function() {
+ var ret = customizedFunction.apply(this, arguments);
+ // Logs API calls to the Activity Log if it doesn't go through an
+ // ExtensionFunction.
+ if (!sendRequestHandler.getCalledSendRequest())
+ logActivity(extensionId, prefix + "." + apiName,
+ Array.prototype.slice.call(arguments));
+ return ret;
+ });
};
APIFunctions.prototype.setUpdateArgumentsPostValidate =
@@ -135,7 +148,7 @@ var platform = getPlatform();
function Binding(schema) {
this.schema_ = schema;
- this.apiFunctions_ = new APIFunctions();
+ this.apiFunctions_ = new APIFunctions(schema.namespace);
this.customEvent_ = null;
this.customHooks_ = [];
};
@@ -288,6 +301,8 @@ Binding.prototype = {
if (this.updateArgumentsPostValidate)
args = this.updateArgumentsPostValidate.apply(this, args);
+ sendRequestHandler.clearCalledSendRequest();
+
var retval;
if (this.handleRequest) {
retval = this.handleRequest.apply(this, args);
@@ -299,6 +314,7 @@ Binding.prototype = {
this.definition.parameters,
optArgs);
}
+ sendRequestHandler.clearCalledSendRequest();
// Validate return value if defined - only in debug.
if (chromeHidden.validateCallbacks &&
« no previous file with comments | « chrome/renderer/extensions/dom_activity_logger.h ('k') | chrome/renderer/resources/extensions/send_request.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698