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
3 // found in the LICENSE file.
5 define("mojo/public/js/bindings/connection", [
6 "mojo/public/js/bindings/connector",
7 "mojo/public/js/bindings/router",
8 ], function(connector, router) {
11 handle, localFactory, remoteFactory, routerFactory, connectorFactory) {
12 if (routerFactory === undefined)
13 routerFactory = router.Router;
14 this.router_ = new routerFactory(handle, connectorFactory);
15 this.remote = new remoteFactory(this.router_);
16 this.local = new localFactory(this.remote);
17 this.router_.setIncomingReceiver(this.local);
19 var validateRequest = localFactory.prototype.validator;
20 var validateResponse = remoteFactory.prototype.validator;
21 var payloadValidators = [];
23 payloadValidators.push(validateRequest);
25 payloadValidators.push(validateResponse);
26 this.router_.setPayloadValidators(payloadValidators);
29 Connection.prototype.close = function() {
36 Connection.prototype.encounteredError = function() {
37 return this.router_.encounteredError();
40 // The TestConnection subclass is only intended to be used in unit tests.
42 function TestConnection(handle, localFactory, remoteFactory) {
48 connector.TestConnector);
51 TestConnection.prototype = Object.create(Connection.prototype);
54 exports.Connection = Connection;
55 exports.TestConnection = TestConnection;