OLD | NEW |
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 utils = require('utils'); | 18 var utils = require('utils'); |
19 var CHECK = requireNative('logging').CHECK; | 19 var CHECK = requireNative('logging').CHECK; |
20 var sendRequestHandler = require('sendRequest'); | 20 var sendRequestHandler = require('sendRequest'); |
21 var sendRequest = sendRequestHandler.sendRequest; | 21 var sendRequest = sendRequestHandler.sendRequest; |
22 var logActivity = requireNative('activityLogger').LogActivity; | 22 var logActivity = requireNative('activityLogger'); |
23 | 23 |
24 // Stores the name and definition of each API function, with methods to | 24 // Stores the name and definition of each API function, with methods to |
25 // modify their behaviour (such as a custom way to handle requests to the | 25 // modify their behaviour (such as a custom way to handle requests to the |
26 // API, a custom callback, etc). | 26 // API, a custom callback, etc). |
27 function APIFunctions(namespace) { | 27 function APIFunctions(namespace) { |
28 this.apiFunctions_ = {}; | 28 this.apiFunctions_ = {}; |
29 this.unavailableApiFunctions_ = {}; | 29 this.unavailableApiFunctions_ = {}; |
30 this.namespace = namespace; | 30 this.namespace = namespace; |
31 } | 31 } |
32 | 32 |
(...skipping 13 matching lines...) Expand all Loading... |
46 if (this.unavailableApiFunctions_.hasOwnProperty(apiName)) | 46 if (this.unavailableApiFunctions_.hasOwnProperty(apiName)) |
47 return; | 47 return; |
48 if (!this.apiFunctions_.hasOwnProperty(apiName)) | 48 if (!this.apiFunctions_.hasOwnProperty(apiName)) |
49 throw new Error('Tried to set hook for unknown API "' + apiName + '"'); | 49 throw new Error('Tried to set hook for unknown API "' + apiName + '"'); |
50 this.apiFunctions_[apiName][propertyName] = customizedFunction; | 50 this.apiFunctions_[apiName][propertyName] = customizedFunction; |
51 }; | 51 }; |
52 | 52 |
53 APIFunctions.prototype.setHandleRequest = | 53 APIFunctions.prototype.setHandleRequest = |
54 function(apiName, customizedFunction) { | 54 function(apiName, customizedFunction) { |
55 var prefix = this.namespace; | 55 var prefix = this.namespace; |
| 56 // TODO(ataly): Need to replace/redefine apply and slice. |
56 return this.setHook_(apiName, 'handleRequest', | 57 return this.setHook_(apiName, 'handleRequest', |
57 function() { | 58 function() { |
58 var ret = customizedFunction.apply(this, arguments); | 59 var ret = customizedFunction.apply(this, arguments); |
59 // Logs API calls to the Activity Log if it doesn't go through an | 60 // Logs API calls to the Activity Log if it doesn't go through an |
60 // ExtensionFunction. | 61 // ExtensionFunction. |
61 if (!sendRequestHandler.getCalledSendRequest()) | 62 if (!sendRequestHandler.getCalledSendRequest()) |
62 logActivity(extensionId, prefix + "." + apiName, | 63 logActivity.LogAPICall(extensionId, prefix + "." + apiName, |
63 Array.prototype.slice.call(arguments)); | 64 Array.prototype.slice.call(arguments)); |
64 return ret; | 65 return ret; |
65 }); | 66 }); |
66 }; | 67 }; |
67 | 68 |
68 APIFunctions.prototype.setUpdateArgumentsPostValidate = | 69 APIFunctions.prototype.setUpdateArgumentsPostValidate = |
69 function(apiName, customizedFunction) { | 70 function(apiName, customizedFunction) { |
70 return this.setHook_( | 71 return this.setHook_( |
71 apiName, 'updateArgumentsPostValidate', customizedFunction); | 72 apiName, 'updateArgumentsPostValidate', customizedFunction); |
72 }; | 73 }; |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 }); | 412 }); |
412 }; | 413 }; |
413 | 414 |
414 addProperties(mod, schema); | 415 addProperties(mod, schema); |
415 this.runHooks_(mod); | 416 this.runHooks_(mod); |
416 return mod; | 417 return mod; |
417 } | 418 } |
418 }; | 419 }; |
419 | 420 |
420 exports.Binding = Binding; | 421 exports.Binding = Binding; |
OLD | NEW |