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", [ | 5 define("mojo/public/js/bindings", [ |
6 "mojo/public/js/router", | 6 "mojo/public/js/router", |
7 ], function(router) { | 7 "mojo/public/js/core", |
| 8 ], function(router, core) { |
8 | 9 |
9 var Router = router.Router; | 10 var Router = router.Router; |
10 | 11 |
11 var kProxyProperties = Symbol("proxyProperties"); | 12 var kProxyProperties = Symbol("proxyProperties"); |
12 var kStubProperties = Symbol("stubProperties"); | 13 var kStubProperties = Symbol("stubProperties"); |
13 | 14 |
14 // Public proxy class properties that are managed at runtime by the JS | 15 // Public proxy class properties that are managed at runtime by the JS |
15 // bindings. See ProxyBindings below. | 16 // bindings. See ProxyBindings below. |
16 function ProxyProperties(receiver) { | 17 function ProxyProperties(receiver) { |
17 this.receiver = receiver; | 18 this.receiver = receiver; |
18 } | 19 } |
19 | 20 |
20 // TODO(hansmuller): remove then after 'Client=' has been removed from Mojom. | 21 // TODO(hansmuller): remove then after 'Client=' has been removed from Mojom. |
21 ProxyProperties.prototype.getLocalDelegate = function() { | 22 ProxyProperties.prototype.getLocalDelegate = function() { |
22 return this.local && StubBindings(this.local).delegate; | 23 return this.local && StubBindings(this.local).delegate; |
23 } | 24 } |
24 | 25 |
25 // TODO(hansmuller): remove then after 'Client=' has been removed from Mojom. | 26 // TODO(hansmuller): remove then after 'Client=' has been removed from Mojom. |
26 ProxyProperties.prototype.setLocalDelegate = function(impl) { | 27 ProxyProperties.prototype.setLocalDelegate = function(impl) { |
27 if (this.local) | 28 if (this.local) |
28 StubBindings(this.local).delegate = impl; | 29 StubBindings(this.local).delegate = impl; |
29 else | 30 else |
30 throw new Error("no stub object"); | 31 throw new Error("no stub object"); |
31 } | 32 } |
32 | 33 |
| 34 function connectionHandle(connection) { |
| 35 return connection && |
| 36 connection.router && |
| 37 connection.router.connector_ && |
| 38 connection.router.connector_.handle_; |
| 39 } |
| 40 |
| 41 ProxyProperties.prototype.close = function() { |
| 42 var handle = connectionHandle(this.connection); |
| 43 if (handle) |
| 44 core.close(handle); |
| 45 } |
| 46 |
33 // Public stub class properties that are managed at runtime by the JS | 47 // Public stub class properties that are managed at runtime by the JS |
34 // bindings. See StubBindings below. | 48 // bindings. See StubBindings below. |
35 function StubProperties(delegate) { | 49 function StubProperties(delegate) { |
36 this.delegate = delegate; | 50 this.delegate = delegate; |
37 } | 51 } |
38 | 52 |
| 53 StubProperties.prototype.close = function() { |
| 54 var handle = connectionHandle(this.connection); |
| 55 if (handle) |
| 56 core.close(handle); |
| 57 } |
| 58 |
39 // The base class for generated proxy classes. | 59 // The base class for generated proxy classes. |
40 function ProxyBase(receiver) { | 60 function ProxyBase(receiver) { |
41 this[kProxyProperties] = new ProxyProperties(receiver); | 61 this[kProxyProperties] = new ProxyProperties(receiver); |
42 | 62 |
43 // TODO(hansmuller): Temporary, for Chrome backwards compatibility. | 63 // TODO(hansmuller): Temporary, for Chrome backwards compatibility. |
44 if (receiver instanceof Router) | 64 if (receiver instanceof Router) |
45 this.receiver_ = receiver; | 65 this.receiver_ = receiver; |
46 } | 66 } |
47 | 67 |
48 // The base class for generated stub classes. | 68 // The base class for generated stub classes. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 119 |
100 var exports = {}; | 120 var exports = {}; |
101 exports.EmptyProxy = ProxyBase; | 121 exports.EmptyProxy = ProxyBase; |
102 exports.EmptyStub = StubBase; | 122 exports.EmptyStub = StubBase; |
103 exports.ProxyBase = ProxyBase; | 123 exports.ProxyBase = ProxyBase; |
104 exports.ProxyBindings = ProxyBindings; | 124 exports.ProxyBindings = ProxyBindings; |
105 exports.StubBase = StubBase; | 125 exports.StubBase = StubBase; |
106 exports.StubBindings = StubBindings; | 126 exports.StubBindings = StubBindings; |
107 return exports; | 127 return exports; |
108 }); | 128 }); |
OLD | NEW |