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/connection", [ | 5 define("mojo/public/js/connection", [ |
6 "mojo/public/js/connector", | 6 "mojo/public/js/connector", |
7 "mojo/public/js/core", | 7 "mojo/public/js/core", |
8 "mojo/public/js/router", | 8 "mojo/public/js/router", |
9 ], function(connector, core, routerModule) { | 9 ], function(connector, core, routerModule) { |
10 | 10 |
| 11 // TODO(hansmuller): the proxy connection_ property should connection$ |
| 12 // TODO(hansmuller): the proxy receiver_ property should be receiver$ |
| 13 |
11 function BaseConnection(localStub, remoteProxy, router) { | 14 function BaseConnection(localStub, remoteProxy, router) { |
12 this.router_ = router; | 15 this.router_ = router; |
13 this.local = localStub; | 16 this.local = localStub; |
14 this.remote = remoteProxy; | 17 this.remote = remoteProxy; |
15 | 18 |
16 this.router_.setIncomingReceiver(localStub); | 19 this.router_.setIncomingReceiver(localStub); |
17 if (this.remote) | 20 if (this.remote) |
18 this.remote.receiver_ = router; | 21 this.remote.receiver_ = router; |
19 | 22 |
20 // Validate incoming messages: remote responses and local requests. | 23 // Validate incoming messages: remote responses and local requests. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } | 84 } |
82 | 85 |
83 function getStubConnection(stub, proxyInterface) { | 86 function getStubConnection(stub, proxyInterface) { |
84 if (!stub.connection_) { | 87 if (!stub.connection_) { |
85 var proxy = proxyInterface.client && new proxyInterface.client.proxyClass; | 88 var proxy = proxyInterface.client && new proxyInterface.client.proxyClass; |
86 stub.connection_ = createOpenConnection(stub, proxy); | 89 stub.connection_ = createOpenConnection(stub, proxy); |
87 } | 90 } |
88 return stub.connection_; | 91 return stub.connection_; |
89 } | 92 } |
90 | 93 |
| 94 function initProxyInstance(proxy, proxyInterface, receiver) { |
| 95 if (proxyInterface.client) { |
| 96 Object.defineProperty(proxy, 'client$', { |
| 97 get: function() { |
| 98 var connection = getProxyConnection(proxy, proxyInterface); |
| 99 return connection.local && connection.local.delegate$ |
| 100 }, |
| 101 set: function(value) { |
| 102 var connection = getProxyConnection(proxy, proxyInterface); |
| 103 if (connection.local) |
| 104 connection.local.delegate$ = value; |
| 105 } |
| 106 }); |
| 107 } |
| 108 if (receiver instanceof routerModule.Router) { |
| 109 // TODO(hansmuller): Temporary, for Chrome backwards compatibility. |
| 110 proxy.receiver_ = receiver; |
| 111 } else if (receiver) { |
| 112 var router = new routerModule.Router(receiver); |
| 113 var stub = proxyInterface.client && new proxyInterface.client.stubClass; |
| 114 proxy.connection_ = new BaseConnection(stub, proxy, router); |
| 115 proxy.connection_.messagePipeHandle = receiver; |
| 116 } |
| 117 } |
91 | 118 |
92 var exports = {}; | 119 var exports = {}; |
93 exports.Connection = Connection; | 120 exports.Connection = Connection; |
94 exports.TestConnection = TestConnection; | 121 exports.TestConnection = TestConnection; |
95 exports.getProxyConnection = getProxyConnection; | 122 exports.getProxyConnection = getProxyConnection; |
96 exports.getStubConnection = getStubConnection; | 123 exports.getStubConnection = getStubConnection; |
| 124 exports.initProxyInstance = initProxyInstance; |
97 return exports; | 125 return exports; |
98 }); | 126 }); |
OLD | NEW |