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

Side by Side Diff: mojo/public/js/connection.js

Issue 2549683002: Mojo JS bindings: introduce concepts that are more similar to C++ bindings: (Closed)
Patch Set: put interface control methods in the |ptr| property Created 4 years 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 unified diff | Download patch
OLDNEW
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/bindings",
7 "mojo/public/js/connector", 6 "mojo/public/js/connector",
8 "mojo/public/js/core", 7 "mojo/public/js/core",
9 "mojo/public/js/router", 8 "mojo/public/js/router",
10 ], function(bindings, connector, core, router) { 9 ], function(connector, core, router) {
11 10
12 var Router = router.Router; 11 var Router = router.Router;
13 var EmptyProxy = bindings.EmptyProxy;
14 var EmptyStub = bindings.EmptyStub;
15 var ProxyBindings = bindings.ProxyBindings;
16 var StubBindings = bindings.StubBindings;
17 var TestConnector = connector.TestConnector; 12 var TestConnector = connector.TestConnector;
18 var TestRouter = router.TestRouter; 13 var TestRouter = router.TestRouter;
19 14
15 var kProxyProperties = Symbol("proxyProperties");
16 var kStubProperties = Symbol("stubProperties");
17
18 // Public proxy class properties that are managed at runtime by the JS
19 // bindings. See ProxyBindings below.
20 function ProxyProperties(receiver) {
21 this.receiver = receiver;
22 }
23
24 // TODO(hansmuller): remove then after 'Client=' has been removed from Mojom.
25 ProxyProperties.prototype.getLocalDelegate = function() {
26 return this.local && StubBindings(this.local).delegate;
27 }
28
29 // TODO(hansmuller): remove then after 'Client=' has been removed from Mojom.
30 ProxyProperties.prototype.setLocalDelegate = function(impl) {
31 if (this.local)
32 StubBindings(this.local).delegate = impl;
33 else
34 throw new Error("no stub object");
35 }
36
37 ProxyProperties.prototype.close = function() {
38 this.connection.close();
39 }
40
41 // Public stub class properties that are managed at runtime by the JS
42 // bindings. See StubBindings below.
43 function StubProperties(delegate) {
44 this.delegate = delegate;
45 }
46
47 StubProperties.prototype.close = function() {
48 this.connection.close();
49 }
50
51 // The base class for generated proxy classes.
52 function ProxyBase(receiver) {
53 this[kProxyProperties] = new ProxyProperties(receiver);
54
55 // TODO(hansmuller): Temporary, for Chrome backwards compatibility.
56 if (receiver instanceof Router)
57 this.receiver_ = receiver;
58 }
59
60 // The base class for generated stub classes.
61 function StubBase(delegate) {
62 this[kStubProperties] = new StubProperties(delegate);
63 }
64
65 // TODO(hansmuller): remove everything except the connection property doc
66 // after 'Client=' has been removed from Mojom.
67
68 // Provides access to properties added to a proxy object without risking
69 // Mojo interface name collisions. Unless otherwise specified, the initial
70 // value of all properties is undefined.
71 //
72 // ProxyBindings(proxy).connection - The Connection object that links the
73 // proxy for a remote Mojo service to an optional local stub for a local
74 // service. The value of ProxyBindings(proxy).connection.remote == proxy.
75 //
76 // ProxyBindings(proxy).local - The "local" stub object whose delegate
77 // implements the proxy's Mojo client interface.
78 //
79 // ProxyBindings(proxy).setLocalDelegate(impl) - Sets the implementation
80 // delegate of the proxy's client stub object. This is just shorthand
81 // for |StubBindings(ProxyBindings(proxy).local).delegate = impl|.
82 //
83 // ProxyBindings(proxy).getLocalDelegate() - Returns the implementation
84 // delegate of the proxy's client stub object. This is just shorthand
85 // for |StubBindings(ProxyBindings(proxy).local).delegate|.
86
87 function ProxyBindings(proxy) {
88 return (proxy instanceof ProxyBase) ? proxy[kProxyProperties] : proxy;
89 }
90
91 // TODO(hansmuller): remove the remote doc after 'Client=' has been
92 // removed from Mojom.
93
94 // Provides access to properties added to a stub object without risking
95 // Mojo interface name collisions. Unless otherwise specified, the initial
96 // value of all properties is undefined.
97 //
98 // StubBindings(stub).delegate - The optional implementation delegate for
99 // the Mojo interface stub.
100 //
101 // StubBindings(stub).connection - The Connection object that links an
102 // optional proxy for a remote service to this stub. The value of
103 // StubBindings(stub).connection.local == stub.
104 //
105 // StubBindings(stub).remote - A proxy for the the stub's Mojo client
106 // service.
107
108 function StubBindings(stub) {
109 return stub instanceof StubBase ? stub[kStubProperties] : stub;
110 }
111
20 // TODO(hansmuller): the proxy receiver_ property should be receiver$ 112 // TODO(hansmuller): the proxy receiver_ property should be receiver$
21 113
22 function BaseConnection(localStub, remoteProxy, router) { 114 function BaseConnection(localStub, remoteProxy, router) {
23 this.router_ = router; 115 this.router_ = router;
24 this.local = localStub; 116 this.local = localStub;
25 this.remote = remoteProxy; 117 this.remote = remoteProxy;
26 118
27 this.router_.setIncomingReceiver(localStub); 119 this.router_.setIncomingReceiver(localStub);
28 this.router_.setErrorHandler(function() { 120 this.router_.setErrorHandler(function() {
29 if (StubBindings(this.local) && 121 if (StubBindings(this.local) &&
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 function bindStubDerivedImpl(obj) { 269 function bindStubDerivedImpl(obj) {
178 var pipe = core.createMessagePipe(); 270 var pipe = core.createMessagePipe();
179 var router = new Router(pipe.handle0); 271 var router = new Router(pipe.handle0);
180 var connection = new BaseConnection(obj, undefined, router); 272 var connection = new BaseConnection(obj, undefined, router);
181 obj.connection = connection; 273 obj.connection = connection;
182 return pipe.handle1; 274 return pipe.handle1;
183 } 275 }
184 276
185 var exports = {}; 277 var exports = {};
186 exports.Connection = Connection; 278 exports.Connection = Connection;
279 exports.EmptyProxy = ProxyBase;
280 exports.EmptyStub = StubBase;
281 exports.ProxyBase = ProxyBase;
282 exports.ProxyBindings = ProxyBindings;
283 exports.StubBase = StubBase;
284 exports.StubBindings = StubBindings;
187 exports.TestConnection = TestConnection; 285 exports.TestConnection = TestConnection;
188 286
189 exports.bindProxy = bindProxy; 287 exports.bindProxy = bindProxy;
190 exports.getProxy = getProxy; 288 exports.getProxy = getProxy;
191 exports.bindImpl = bindImpl; 289 exports.bindImpl = bindImpl;
192 exports.bindHandleToProxy = bindHandleToProxy; 290 exports.bindHandleToProxy = bindHandleToProxy;
193 exports.bindHandleToStub = bindHandleToStub; 291 exports.bindHandleToStub = bindHandleToStub;
194 exports.bindStubDerivedImpl = bindStubDerivedImpl; 292 exports.bindStubDerivedImpl = bindStubDerivedImpl;
195 return exports; 293 return exports;
196 }); 294 });
OLDNEW
« no previous file with comments | « mojo/public/js/bindings.js ('k') | mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698