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

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: Added an earlier check for the IPC communication 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..83cfd2fd9da6820519b905fcab517235faf2f61c 100644
--- a/chrome/renderer/resources/extensions/binding.js
+++ b/chrome/renderer/resources/extensions/binding.js
@@ -15,15 +15,18 @@ 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 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) {
@@ -48,7 +51,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 =
@@ -121,7 +134,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_ = [];
@@ -243,6 +256,7 @@ Binding.prototype = {
// Setup Functions.
if (schema.functions) {
+ var doubleLogging = "abcdefg";
palmer 2013/03/21 18:39:38 This is never used?
felt 2013/03/21 21:59:23 Whoops, left in from testing. On 2013/03/21 18:39
forEach(schema.functions, function(i, functionDef) {
if (functionDef.name in mod) {
throw new Error('Function ' + functionDef.name +
@@ -286,6 +300,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);
@@ -297,6 +313,7 @@ Binding.prototype = {
this.definition.parameters,
optArgs);
}
+ sendRequestHandler.clearCalledSendRequest();
// Validate return value if defined - only in debug.
if (chromeHidden.validateCallbacks &&

Powered by Google App Engine
This is Rietveld 408576698