| Index: chrome/renderer/resources/event_bindings.js
|
| diff --git a/chrome/renderer/resources/event_bindings.js b/chrome/renderer/resources/event_bindings.js
|
| index 5fb16f9584f7003c3363d366ce37ff7c7a6c1d20..3def161f7d300c292ca337e6668f69e76a838ff2 100644
|
| --- a/chrome/renderer/resources/event_bindings.js
|
| +++ b/chrome/renderer/resources/event_bindings.js
|
| @@ -24,9 +24,24 @@ var chrome = chrome || {};
|
| // chrome.tabs.onChanged.addListener(function(data) { alert(data); });
|
| // chromeHidden.Event.dispatch("tab-changed", "hi");
|
| // will result in an alert dialog that says 'hi'.
|
| - chrome.Event = function(opt_eventName) {
|
| + chrome.Event = function(opt_eventName, opt_argSchemas) {
|
| this.eventName_ = opt_eventName;
|
| this.listeners_ = [];
|
| +
|
| + // Validate event parameters if we are in debug.
|
| + if (opt_argSchemas &&
|
| + chromeHidden.validateCallbacks &&
|
| + chromeHidden.validate) {
|
| +
|
| + this.validate_ = function(args) {
|
| + try {
|
| + chromeHidden.validate(args, opt_argSchemas);
|
| + } catch (exception) {
|
| + return "Event validation error during " + opt_eventName + " -- " +
|
| + exception;
|
| + }
|
| + }
|
| + }
|
| };
|
|
|
| // A map of event names to the event object that is registered to that name.
|
| @@ -45,7 +60,7 @@ var chrome = chrome || {};
|
| if (args) {
|
| args = JSON.parse(args);
|
| }
|
| - attachedNamedEvents[name].dispatch.apply(
|
| + return attachedNamedEvents[name].dispatch.apply(
|
| attachedNamedEvents[name], args);
|
| }
|
| };
|
| @@ -106,6 +121,12 @@ var chrome = chrome || {};
|
| // arguments to this function each listener.
|
| chrome.Event.prototype.dispatch = function(varargs) {
|
| var args = Array.prototype.slice.call(arguments);
|
| + if (this.validate_) {
|
| + var validationErrors = this.validate_(args);
|
| + if (validationErrors) {
|
| + return validationErrors;
|
| + }
|
| + }
|
| for (var i = 0; i < this.listeners_.length; i++) {
|
| try {
|
| this.listeners_[i].apply(null, args);
|
|
|