OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 define("mojo/public/js/bindings/router", [ | 5 define("mojo/public/js/bindings/router", [ |
6 "mojo/public/js/bindings/codec", | 6 "mojo/public/js/bindings/codec", |
7 "mojo/public/js/bindings/connector", | 7 "mojo/public/js/bindings/connector", |
8 ], function(codec, connector) { | 8 ], function(codec, connector) { |
9 | 9 |
10 function Router(handle) { | 10 function Router(handle) { |
11 this.connector_ = new connector.Connector(handle); | 11 this.connector_ = new connector.Connector(handle); |
12 this.incomingReceiver_ = null; | 12 this.incomingReceiver_ = null; |
13 this.nextRequestID_ = 0; | 13 this.nextRequestID_ = 0; |
14 this.responders_ = {}; | 14 this.responders_ = {}; |
15 | 15 |
16 this.connector_.setIncomingReceiver({ | 16 this.connector_.setIncomingReceiver({ |
17 accept: this.handleIncomingMessage_.bind(this), | 17 accept: this.handleIncomingMessage_.bind(this), |
18 }); | 18 }); |
19 this.connector_.setErrorHandler({ | 19 this.connector_.setErrorHandler({ |
20 onError: this.handleConnectionError_.bind(this), | 20 onError: this.handleConnectionError_.bind(this), |
21 }); | 21 }); |
22 } | 22 } |
23 | 23 |
24 Router.prototype.close = function() { | 24 Router.prototype.close = function() { |
25 this.responders_ = {}; // Drop any responders. | 25 this.responders_ = {}; // Drop any responders. |
26 this.connector_.close(); | 26 this.connector_.close(); |
27 }; | 27 }; |
28 | 28 |
| 29 Router.prototype.setFuzzer = function(fuzzer) { |
| 30 this.connector_.setFuzzer(fuzzer); |
| 31 } |
| 32 |
29 Router.prototype.accept = function(message) { | 33 Router.prototype.accept = function(message) { |
30 this.connector_.accept(message); | 34 this.connector_.accept(message); |
31 }; | 35 }; |
32 | 36 |
33 Router.prototype.reject = function(message) { | 37 Router.prototype.reject = function(message) { |
34 // TODO(mpcomplete): no way to trasmit errors over a Connection. | 38 // TODO(mpcomplete): no way to trasmit errors over a Connection. |
35 }; | 39 }; |
36 | 40 |
37 Router.prototype.acceptWithResponder = function(message, responder) { | 41 Router.prototype.acceptWithResponder = function(message, responder) { |
38 // Reserve 0 in case we want it to convey special meaning in the future. | 42 // Reserve 0 in case we want it to convey special meaning in the future. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 Router.prototype.handleConnectionError_ = function(result) { | 88 Router.prototype.handleConnectionError_ = function(result) { |
85 for (var each in this.responders_) | 89 for (var each in this.responders_) |
86 this.responders_[each].reject(result); | 90 this.responders_[each].reject(result); |
87 this.close(); | 91 this.close(); |
88 }; | 92 }; |
89 | 93 |
90 var exports = {}; | 94 var exports = {}; |
91 exports.Router = Router; | 95 exports.Router = Router; |
92 return exports; | 96 return exports; |
93 }); | 97 }); |
OLD | NEW |