Chromium Code Reviews| 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()) { |