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

Side by Side 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 it to work with another CL that happened while I was working on it 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 require('json_schema'); 5 require('json_schema');
6 require('event_bindings'); 6 require('event_bindings');
7 var chrome = requireNative('chrome').GetChrome(); 7 var chrome = requireNative('chrome').GetChrome();
8 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); 8 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
9 var forEach = require('utils').forEach; 9 var forEach = require('utils').forEach;
10 var GetAvailability = requireNative('v8_context').GetAvailability; 10 var GetAvailability = requireNative('v8_context').GetAvailability;
11 var logging = requireNative('logging'); 11 var logging = requireNative('logging');
12 var process = requireNative('process'); 12 var process = requireNative('process');
13 var contextType = process.GetContextType(); 13 var contextType = process.GetContextType();
14 var extensionId = process.GetExtensionId(); 14 var extensionId = process.GetExtensionId();
15 var manifestVersion = process.GetManifestVersion(); 15 var manifestVersion = process.GetManifestVersion();
16 var schemaRegistry = requireNative('schema_registry'); 16 var schemaRegistry = requireNative('schema_registry');
17 var schemaUtils = require('schemaUtils'); 17 var schemaUtils = require('schemaUtils');
18 var sendRequest = require('sendRequest').sendRequest; 18 var sendRequest = require('sendRequest').sendRequest;
19 var utils = require('utils'); 19 var utils = require('utils');
20 var logActivity = requireNative('activityLogger').LogActivity;
20 21
21 // Stores the name and definition of each API function, with methods to 22 // Stores the name and definition of each API function, with methods to
22 // modify their behaviour (such as a custom way to handle requests to the 23 // modify their behaviour (such as a custom way to handle requests to the
23 // API, a custom callback, etc). 24 // API, a custom callback, etc).
24 function APIFunctions() { 25 function APIFunctions(namespace) {
25 this.apiFunctions_ = {}; 26 this.apiFunctions_ = {};
26 this.unavailableApiFunctions_ = {}; 27 this.unavailableApiFunctions_ = {};
28 this.namespace = namespace;
27 } 29 }
28 30
29 APIFunctions.prototype.register = function(apiName, apiFunction) { 31 APIFunctions.prototype.register = function(apiName, apiFunction) {
30 this.apiFunctions_[apiName] = apiFunction; 32 this.apiFunctions_[apiName] = apiFunction;
31 }; 33 };
32 34
33 // Registers a function as existing but not available, meaning that calls to 35 // Registers a function as existing but not available, meaning that calls to
34 // the set* methods that reference this function should be ignored rather 36 // the set* methods that reference this function should be ignored rather
35 // than throwing Errors. 37 // than throwing Errors.
36 APIFunctions.prototype.registerUnavailable = function(apiName) { 38 APIFunctions.prototype.registerUnavailable = function(apiName) {
37 this.unavailableApiFunctions_[apiName] = apiName; 39 this.unavailableApiFunctions_[apiName] = apiName;
38 }; 40 };
39 41
40 APIFunctions.prototype.setHook_ = 42 APIFunctions.prototype.setHook_ =
41 function(apiName, propertyName, customizedFunction) { 43 function(apiName, propertyName, customizedFunction) {
42 if (this.unavailableApiFunctions_.hasOwnProperty(apiName)) 44 if (this.unavailableApiFunctions_.hasOwnProperty(apiName))
43 return; 45 return;
44 if (!this.apiFunctions_.hasOwnProperty(apiName)) 46 if (!this.apiFunctions_.hasOwnProperty(apiName))
45 throw new Error('Tried to set hook for unknown API "' + apiName + '"'); 47 throw new Error('Tried to set hook for unknown API "' + apiName + '"');
46 this.apiFunctions_[apiName][propertyName] = customizedFunction; 48 this.apiFunctions_[apiName][propertyName] = customizedFunction;
47 }; 49 };
48 50
49 APIFunctions.prototype.setHandleRequest = 51 APIFunctions.prototype.setHandleRequest =
50 function(apiName, customizedFunction) { 52 function(apiName, customizedFunction) {
51 return this.setHook_(apiName, 'handleRequest', customizedFunction); 53 var ext_id = extensionId;
Matt Perry 2013/03/14 20:32:31 is this temporary needed?
felt 2013/03/15 00:04:47 Done.
54 var prefix = this.namespace;
55 return this.setHook_(apiName, 'handleRequest',
56 function() {
57 logActivity(ext_id, prefix + "." + apiName,
58 Array.prototype.slice.call(arguments));
59 return customizedFunction.apply(this, arguments);
60 });
52 }; 61 };
53 62
54 APIFunctions.prototype.setUpdateArgumentsPostValidate = 63 APIFunctions.prototype.setUpdateArgumentsPostValidate =
55 function(apiName, customizedFunction) { 64 function(apiName, customizedFunction) {
56 return this.setHook_( 65 return this.setHook_(
57 apiName, 'updateArgumentsPostValidate', customizedFunction); 66 apiName, 'updateArgumentsPostValidate', customizedFunction);
58 }; 67 };
59 68
60 APIFunctions.prototype.setUpdateArgumentsPreValidate = 69 APIFunctions.prototype.setUpdateArgumentsPreValidate =
61 function(apiName, customizedFunction) { 70 function(apiName, customizedFunction) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 123
115 function isSchemaNodeSupported(schemaNode, platform, manifestVersion) { 124 function isSchemaNodeSupported(schemaNode, platform, manifestVersion) {
116 return isPlatformSupported(schemaNode, platform) && 125 return isPlatformSupported(schemaNode, platform) &&
117 isManifestVersionSupported(schemaNode, manifestVersion); 126 isManifestVersionSupported(schemaNode, manifestVersion);
118 } 127 }
119 128
120 var platform = getPlatform(); 129 var platform = getPlatform();
121 130
122 function Binding(schema) { 131 function Binding(schema) {
123 this.schema_ = schema; 132 this.schema_ = schema;
124 this.apiFunctions_ = new APIFunctions(); 133 this.apiFunctions_ = new APIFunctions(schema.namespace);
125 this.customEvent_ = null; 134 this.customEvent_ = null;
126 this.customTypes_ = {}; 135 this.customTypes_ = {};
127 this.customHooks_ = []; 136 this.customHooks_ = [];
128 }; 137 };
129 138
130 Binding.create = function(apiName) { 139 Binding.create = function(apiName) {
131 return new Binding(schemaRegistry.GetSchema(apiName)); 140 return new Binding(schemaRegistry.GetSchema(apiName));
132 }; 141 };
133 142
134 Binding.prototype = { 143 Binding.prototype = {
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 }); 408 });
400 }; 409 };
401 410
402 addProperties(mod, schema); 411 addProperties(mod, schema);
403 this.runHooks_(mod); 412 this.runHooks_(mod);
404 return mod; 413 return mod;
405 } 414 }
406 }; 415 };
407 416
408 exports.Binding = Binding; 417 exports.Binding = Binding;
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/dom_activity_logger.h ('k') | chrome/test/data/extensions/activity_log/options.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698