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

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: Final changes 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
« no previous file with comments | « mojo/public/js/bindings/connection.js ('k') | mojo/public/js/bindings/validation_unittests.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..efb5eb0e6ab211abce254e213d1cdc8599e347ae 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.payloadValidators_ = [];
this.connector_.setIncomingReceiver({
accept: this.handleIncomingMessage_.bind(this),
@@ -56,13 +57,21 @@ define("mojo/public/js/bindings/router", [
this.incomingReceiver_ = receiver;
};
+ Router.prototype.setPayloadValidators = function(payloadValidators) {
+ this.payloadValidators_ = payloadValidators;
+ };
+
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.payloadValidators_.length; ++i)
+ err = this.payloadValidators_[i](messageValidator);
+ if (err !== noError)
this.close();
if (message.expectsResponse()) {
« no previous file with comments | « mojo/public/js/bindings/connection.js ('k') | mojo/public/js/bindings/validation_unittests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698