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

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

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 months 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
« no previous file with comments | « mojo/public/js/BUILD.gn ('k') | mojo/public/js/buffer.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 define("mojo/public/js/bindings", [
6 "mojo/public/js/router",
7 "mojo/public/js/core",
8 ], function(router, core) {
9
10 var Router = router.Router;
11
12 var kProxyProperties = Symbol("proxyProperties");
13 var kStubProperties = Symbol("stubProperties");
14
15 // Public proxy class properties that are managed at runtime by the JS
16 // bindings. See ProxyBindings below.
17 function ProxyProperties(receiver) {
18 this.receiver = receiver;
19 }
20
21 // TODO(hansmuller): remove then after 'Client=' has been removed from Mojom.
22 ProxyProperties.prototype.getLocalDelegate = function() {
23 return this.local && StubBindings(this.local).delegate;
24 }
25
26 // TODO(hansmuller): remove then after 'Client=' has been removed from Mojom.
27 ProxyProperties.prototype.setLocalDelegate = function(impl) {
28 if (this.local)
29 StubBindings(this.local).delegate = impl;
30 else
31 throw new Error("no stub object");
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
47 // Public stub class properties that are managed at runtime by the JS
48 // bindings. See StubBindings below.
49 function StubProperties(delegate) {
50 this.delegate = delegate;
51 }
52
53 StubProperties.prototype.close = function() {
54 var handle = connectionHandle(this.connection);
55 if (handle)
56 core.close(handle);
57 }
58
59 // The base class for generated proxy classes.
60 function ProxyBase(receiver) {
61 this[kProxyProperties] = new ProxyProperties(receiver);
62
63 // TODO(hansmuller): Temporary, for Chrome backwards compatibility.
64 if (receiver instanceof Router)
65 this.receiver_ = receiver;
66 }
67
68 // The base class for generated stub classes.
69 function StubBase(delegate) {
70 this[kStubProperties] = new StubProperties(delegate);
71 }
72
73 // TODO(hansmuller): remove everything except the connection property doc
74 // after 'Client=' has been removed from Mojom.
75
76 // Provides access to properties added to a proxy object without risking
77 // Mojo interface name collisions. Unless otherwise specified, the initial
78 // value of all properties is undefined.
79 //
80 // ProxyBindings(proxy).connection - The Connection object that links the
81 // proxy for a remote Mojo service to an optional local stub for a local
82 // service. The value of ProxyBindings(proxy).connection.remote == proxy.
83 //
84 // ProxyBindings(proxy).local - The "local" stub object whose delegate
85 // implements the proxy's Mojo client interface.
86 //
87 // ProxyBindings(proxy).setLocalDelegate(impl) - Sets the implementation
88 // delegate of the proxy's client stub object. This is just shorthand
89 // for |StubBindings(ProxyBindings(proxy).local).delegate = impl|.
90 //
91 // ProxyBindings(proxy).getLocalDelegate() - Returns the implementation
92 // delegate of the proxy's client stub object. This is just shorthand
93 // for |StubBindings(ProxyBindings(proxy).local).delegate|.
94
95 function ProxyBindings(proxy) {
96 return (proxy instanceof ProxyBase) ? proxy[kProxyProperties] : proxy;
97 }
98
99 // TODO(hansmuller): remove the remote doc after 'Client=' has been
100 // removed from Mojom.
101
102 // Provides access to properties added to a stub object without risking
103 // Mojo interface name collisions. Unless otherwise specified, the initial
104 // value of all properties is undefined.
105 //
106 // StubBindings(stub).delegate - The optional implementation delegate for
107 // the Mojo interface stub.
108 //
109 // StubBindings(stub).connection - The Connection object that links an
110 // optional proxy for a remote service to this stub. The value of
111 // StubBindings(stub).connection.local == stub.
112 //
113 // StubBindings(stub).remote - A proxy for the the stub's Mojo client
114 // service.
115
116 function StubBindings(stub) {
117 return stub instanceof StubBase ? stub[kStubProperties] : stub;
118 }
119
120 var exports = {};
121 exports.EmptyProxy = ProxyBase;
122 exports.EmptyStub = StubBase;
123 exports.ProxyBase = ProxyBase;
124 exports.ProxyBindings = ProxyBindings;
125 exports.StubBase = StubBase;
126 exports.StubBindings = StubBindings;
127 return exports;
128 });
OLDNEW
« no previous file with comments | « mojo/public/js/BUILD.gn ('k') | mojo/public/js/buffer.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698