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

Unified Diff: mojo/public/js/bindings/router.js

Issue 488173006: Integrate Mojo JS validation bindings with the Router (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed a template indentO Created 6 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
Index: mojo/public/js/bindings/router.js
diff --git a/mojo/public/js/bindings/router.js b/mojo/public/js/bindings/router.js
index 648ecd455816f9549070470fe982248b9b8d7731..91c6450e842846e7010a809f56209fb95863a887 100644
--- a/mojo/public/js/bindings/router.js
+++ b/mojo/public/js/bindings/router.js
@@ -13,6 +13,7 @@ define("mojo/public/js/bindings/router", [
this.incomingReceiver_ = null;
this.nextRequestID_ = 0;
this.responders_ = {};
+ this.validators_ = [];
this.connector_.setIncomingReceiver({
accept: this.handleIncomingMessage_.bind(this),
@@ -56,13 +57,21 @@ define("mojo/public/js/bindings/router", [
this.incomingReceiver_ = receiver;
};
+ Router.prototype.setValidators = function(validators) {
yzshen1 2014/08/27 18:21:39 It seems better to name it payload validators to i
hansmuller 2014/08/27 21:07:03 Good point.
+ this.validators_ = validators;
+ };
+
Router.prototype.encounteredError = function() {
return this.connector_.encounteredError();
};
Router.prototype.handleIncomingMessage_ = function(message) {
- var v = new validator.Validator(message);
- if (v.validateMessageHeader() !== validator.validationError.NONE)
+ var noError = validator.validationError.NONE;
+ var messageValidator = new validator.Validator(message);
+ var err = messageValidator.validateMessageHeader();
+ for (var i = 0; err === noError && i < this.validators_.length; ++i)
+ err = this.validators_[i](messageValidator);
+ if (err !== noError)
this.close();
if (message.expectsResponse()) {

Powered by Google App Engine
This is Rietveld 408576698