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

Side by Side Diff: chrome/renderer/resources/extensions/schema_generated_bindings.js

Issue 12517011: Added activity logging for ext APIs with custom bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: lint fix 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 // Generates the chrome.* API bindings from a list of schemas. 5 // Generates the chrome.* API bindings from a list of schemas.
6 6
7 // TODO(battre): cleanup the usage of packages everywhere, as described here 7 // TODO(battre): cleanup the usage of packages everywhere, as described here
8 // http://codereview.chromium.org/10392008/diff/38/chrome/renderer/resources/e xtensions/schema_generated_bindings.js 8 // http://codereview.chromium.org/10392008/diff/38/chrome/renderer/resources/e xtensions/schema_generated_bindings.js
9 9
10 require('json_schema'); 10 require('json_schema');
11 require('event_bindings'); 11 require('event_bindings');
12 var GetExtensionAPIDefinition = 12 var GetExtensionAPIDefinition =
13 requireNative('apiDefinitions').GetExtensionAPIDefinition; 13 requireNative('apiDefinitions').GetExtensionAPIDefinition;
14 var sendRequest = require('sendRequest').sendRequest; 14 var sendRequest = require('sendRequest').sendRequest;
15 var utils = require('utils'); 15 var utils = require('utils');
16 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); 16 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
17 var schemaUtils = require('schemaUtils'); 17 var schemaUtils = require('schemaUtils');
18 var logActivity = requireNative('activityLogger').LogActivity;
18 19
19 // The object to generate the bindings for "internal" APIs in, so that 20 // The object to generate the bindings for "internal" APIs in, so that
20 // extensions can't directly call them (without access to chromeHidden), 21 // extensions can't directly call them (without access to chromeHidden),
21 // but are still needed for internal mechanisms of extensions (e.g. events). 22 // but are still needed for internal mechanisms of extensions (e.g. events).
22 // 23 //
23 // This is distinct to the "*Private" APIs which are controlled via 24 // This is distinct to the "*Private" APIs which are controlled via
24 // having strict permissions and aren't generated *anywhere* unless needed. 25 // having strict permissions and aren't generated *anywhere* unless needed.
25 var internalAPIs = {}; 26 var internalAPIs = {};
26 chromeHidden.internalAPIs = internalAPIs; 27 chromeHidden.internalAPIs = internalAPIs;
27 28
28 // Stores the name and definition of each API function, with methods to 29 // Stores the name and definition of each API function, with methods to
29 // modify their behaviour (such as a custom way to handle requests to the 30 // modify their behaviour (such as a custom way to handle requests to the
30 // API, a custom callback, etc). 31 // API, a custom callback, etc).
31 function APIFunctions() { 32 function APIFunctions() {
32 this._apiFunctions = {}; 33 this._apiFunctions = {};
33 this._unavailableApiFunctions = {}; 34 this._unavailableApiFunctions = {};
35 this.extensionId = "unknown";
34 } 36 }
35 APIFunctions.prototype.register = function(apiName, apiFunction) { 37 APIFunctions.prototype.register = function(apiName, apiFunction) {
36 this._apiFunctions[apiName] = apiFunction; 38 this._apiFunctions[apiName] = apiFunction;
37 }; 39 };
38 // Registers a function as existing but not available, meaning that calls to 40 // Registers a function as existing but not available, meaning that calls to
39 // the set* methods that reference this function should be ignored rather 41 // the set* methods that reference this function should be ignored rather
40 // than throwing Errors. 42 // than throwing Errors.
41 APIFunctions.prototype.registerUnavailable = function(apiName) { 43 APIFunctions.prototype.registerUnavailable = function(apiName) {
42 this._unavailableApiFunctions[apiName] = apiName; 44 this._unavailableApiFunctions[apiName] = apiName;
43 }; 45 };
44 APIFunctions.prototype._setHook = 46 APIFunctions.prototype._setHook =
45 function(apiName, propertyName, customizedFunction) { 47 function(apiName, propertyName, customizedFunction) {
46 if (this._unavailableApiFunctions.hasOwnProperty(apiName)) 48 if (this._unavailableApiFunctions.hasOwnProperty(apiName))
47 return; 49 return;
48 if (!this._apiFunctions.hasOwnProperty(apiName)) 50 if (!this._apiFunctions.hasOwnProperty(apiName))
49 throw new Error('Tried to set hook for unknown API "' + apiName + '"'); 51 throw new Error('Tried to set hook for unknown API "' + apiName + '"');
50 this._apiFunctions[apiName][propertyName] = customizedFunction; 52 this._apiFunctions[apiName][propertyName] = customizedFunction;
51 }; 53 };
52 APIFunctions.prototype.setHandleRequest = 54 APIFunctions.prototype.setHandleRequest =
53 function(apiName, customizedFunction) { 55 function(apiName, customizedFunction) {
54 return this._setHook(apiName, 'handleRequest', customizedFunction); 56 var ext_id = this.extensionId;
57 return this._setHook(apiName, 'handleRequest',
58 function() {
59 logActivity(ext_id, apiName,
Matt Perry 2013/03/14 20:32:31 Unfortunately, some APIs that use setHandleRequest
felt 2013/03/15 00:04:47 Good catch. OK, I did a version of the second one
60 Array.prototype.slice.call(arguments));
61 return customizedFunction.apply(this, arguments);
62 });
55 }; 63 };
56 APIFunctions.prototype.setUpdateArgumentsPostValidate = 64 APIFunctions.prototype.setUpdateArgumentsPostValidate =
57 function(apiName, customizedFunction) { 65 function(apiName, customizedFunction) {
58 return this._setHook( 66 return this._setHook(
59 apiName, 'updateArgumentsPostValidate', customizedFunction); 67 apiName, 'updateArgumentsPostValidate', customizedFunction);
60 }; 68 };
61 APIFunctions.prototype.setUpdateArgumentsPreValidate = 69 APIFunctions.prototype.setUpdateArgumentsPreValidate =
62 function(apiName, customizedFunction) { 70 function(apiName, customizedFunction) {
63 return this._setHook( 71 return this._setHook(
64 apiName, 'updateArgumentsPreValidate', customizedFunction); 72 apiName, 'updateArgumentsPreValidate', customizedFunction);
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 function addUnprivilegedAccessGetter(mod, name) { 258 function addUnprivilegedAccessGetter(mod, name) {
251 mod.__defineGetter__(name, function() { 259 mod.__defineGetter__(name, function() {
252 throw new Error( 260 throw new Error(
253 '"' + name + '" can only be used in extension processes. See ' + 261 '"' + name + '" can only be used in extension processes. See ' +
254 'the content scripts documentation for more details.'); 262 'the content scripts documentation for more details.');
255 }); 263 });
256 } 264 }
257 265
258 // Setup Functions. 266 // Setup Functions.
259 if (apiDef.functions) { 267 if (apiDef.functions) {
268 apiFunctions.extensionId = extensionId;
260 apiDef.functions.forEach(function(functionDef) { 269 apiDef.functions.forEach(function(functionDef) {
261 if (functionDef.name in mod) { 270 if (functionDef.name in mod) {
262 throw new Error('Function ' + functionDef.name + 271 throw new Error('Function ' + functionDef.name +
263 ' already defined in ' + apiDef.namespace); 272 ' already defined in ' + apiDef.namespace);
264 } 273 }
265 274
266 var apiFunctionName = apiDef.namespace + "." + functionDef.name; 275 var apiFunctionName = apiDef.namespace + "." + functionDef.name;
267 276
268 if (!isSchemaNodeSupported(functionDef, platform, manifestVersion)) { 277 if (!isSchemaNodeSupported(functionDef, platform, manifestVersion)) {
269 apiFunctions.registerUnavailable(apiFunctionName); 278 apiFunctions.registerUnavailable(apiFunctionName);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 hook({ 437 hook({
429 apiFunctions: new NamespacedAPIFunctions(apiDef.namespace, 438 apiFunctions: new NamespacedAPIFunctions(apiDef.namespace,
430 apiFunctions), 439 apiFunctions),
431 apiDefinitions: apiDefinitions, 440 apiDefinitions: apiDefinitions,
432 }, extensionId, contextType); 441 }, extensionId, contextType);
433 }); 442 });
434 443
435 if (chrome.test) 444 if (chrome.test)
436 chrome.test.getApiDefinitions = GetExtensionAPIDefinition; 445 chrome.test.getApiDefinitions = GetExtensionAPIDefinition;
437 }); 446 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698