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

Unified Diff: chrome/renderer/resources/event_bindings.js

Issue 173034: Validation of extension api callback and event parameters in DEBUG (Closed)
Patch Set: build docs Created 11 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/renderer_resources.grd ('k') | chrome/renderer/resources/extension_process_bindings.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « chrome/renderer/renderer_resources.grd ('k') | chrome/renderer/resources/extension_process_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698