| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 var Event = require('event_bindings').Event; | 5 var Event = require('event_bindings').Event; |
| 6 var forEach = require('utils').forEach; | 6 var forEach = require('utils').forEach; |
| 7 // Note: Beware sneaky getters/setters when using GetAvailbility(). Use safe/raw | 7 // Note: Beware sneaky getters/setters when using GetAvailbility(). Use safe/raw |
| 8 // variables as arguments. | 8 // variables as arguments. |
| 9 var GetAvailability = requireNative('v8_context').GetAvailability; | 9 var GetAvailability = requireNative('v8_context').GetAvailability; |
| 10 var exceptionHandler = require('uncaught_exception_handler'); | 10 var exceptionHandler = require('uncaught_exception_handler'); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 var ret = $Function.apply(customizedFunction, this, arguments); | 63 var ret = $Function.apply(customizedFunction, this, arguments); |
| 64 // Logs API calls to the Activity Log if it doesn't go through an | 64 // Logs API calls to the Activity Log if it doesn't go through an |
| 65 // ExtensionFunction. | 65 // ExtensionFunction. |
| 66 if (!sendRequestHandler.getCalledSendRequest()) | 66 if (!sendRequestHandler.getCalledSendRequest()) |
| 67 logActivity.LogAPICall(extensionId, prefix + "." + apiName, | 67 logActivity.LogAPICall(extensionId, prefix + "." + apiName, |
| 68 $Array.slice(arguments)); | 68 $Array.slice(arguments)); |
| 69 return ret; | 69 return ret; |
| 70 }); | 70 }); |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 APIFunctions.prototype.setHandleRequestWithPromise = | |
| 74 function(apiName, customizedFunction) { | |
| 75 var prefix = this.namespace; | |
| 76 return this.setHook_(apiName, 'handleRequest', function() { | |
| 77 var name = prefix + '.' + apiName; | |
| 78 logActivity.LogAPICall(extensionId, name, $Array.slice(arguments)); | |
| 79 var stack = exceptionHandler.getExtensionStackTrace(); | |
| 80 var callback = arguments[arguments.length - 1]; | |
| 81 var args = $Array.slice(arguments, 0, arguments.length - 1); | |
| 82 var keepAlivePromise = requireAsync('keep_alive').then(function(module) { | |
| 83 return module.createKeepAlive(); | |
| 84 }); | |
| 85 $Function.apply(customizedFunction, this, args).then(function(result) { | |
| 86 if (callback) { | |
| 87 exceptionHandler.safeCallbackApply(name, {'stack': stack}, callback, | |
| 88 [result]); | |
| 89 } | |
| 90 }).catch(function(error) { | |
| 91 if (callback) { | |
| 92 var message = exceptionHandler.safeErrorToString(error, true); | |
| 93 lastError.run(name, message, stack, callback); | |
| 94 } | |
| 95 }).then(function() { | |
| 96 keepAlivePromise.then(function(keepAlive) { | |
| 97 keepAlive.close(); | |
| 98 }); | |
| 99 }); | |
| 100 }); | |
| 101 }; | |
| 102 | |
| 103 APIFunctions.prototype.setUpdateArgumentsPostValidate = | 73 APIFunctions.prototype.setUpdateArgumentsPostValidate = |
| 104 function(apiName, customizedFunction) { | 74 function(apiName, customizedFunction) { |
| 105 return this.setHook_( | 75 return this.setHook_( |
| 106 apiName, 'updateArgumentsPostValidate', customizedFunction); | 76 apiName, 'updateArgumentsPostValidate', customizedFunction); |
| 107 }; | 77 }; |
| 108 | 78 |
| 109 APIFunctions.prototype.setUpdateArgumentsPreValidate = | 79 APIFunctions.prototype.setUpdateArgumentsPreValidate = |
| 110 function(apiName, customizedFunction) { | 80 function(apiName, customizedFunction) { |
| 111 return this.setHook_( | 81 return this.setHook_( |
| 112 apiName, 'updateArgumentsPreValidate', customizedFunction); | 82 apiName, 'updateArgumentsPreValidate', customizedFunction); |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 availability.message); | 540 availability.message); |
| 571 return; | 541 return; |
| 572 } | 542 } |
| 573 | 543 |
| 574 this.runHooks_(mod, schema); | 544 this.runHooks_(mod, schema); |
| 575 return mod; | 545 return mod; |
| 576 } | 546 } |
| 577 }; | 547 }; |
| 578 | 548 |
| 579 exports.$set('Binding', Binding); | 549 exports.$set('Binding', Binding); |
| OLD | NEW |