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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/js/connection.js
diff --git a/mojo/public/js/connection.js b/mojo/public/js/connection.js
index 1ac88ed9e6354e8db83a37b7ec350bd947e0c445..063cbe485e4340e0eae909042a8a2affbf26ff5f 100644
--- a/mojo/public/js/connection.js
+++ b/mojo/public/js/connection.js
@@ -3,20 +3,112 @@
// found in the LICENSE file.
define("mojo/public/js/connection", [
- "mojo/public/js/bindings",
"mojo/public/js/connector",
"mojo/public/js/core",
"mojo/public/js/router",
-], function(bindings, connector, core, router) {
+], function(connector, core, router) {
var Router = router.Router;
- var EmptyProxy = bindings.EmptyProxy;
- var EmptyStub = bindings.EmptyStub;
- var ProxyBindings = bindings.ProxyBindings;
- var StubBindings = bindings.StubBindings;
var TestConnector = connector.TestConnector;
var TestRouter = router.TestRouter;
+ var kProxyProperties = Symbol("proxyProperties");
+ var kStubProperties = Symbol("stubProperties");
+
+ // Public proxy class properties that are managed at runtime by the JS
+ // bindings. See ProxyBindings below.
+ function ProxyProperties(receiver) {
+ this.receiver = receiver;
+ }
+
+ // TODO(hansmuller): remove then after 'Client=' has been removed from Mojom.
+ ProxyProperties.prototype.getLocalDelegate = function() {
+ return this.local && StubBindings(this.local).delegate;
+ }
+
+ // TODO(hansmuller): remove then after 'Client=' has been removed from Mojom.
+ ProxyProperties.prototype.setLocalDelegate = function(impl) {
+ if (this.local)
+ StubBindings(this.local).delegate = impl;
+ else
+ throw new Error("no stub object");
+ }
+
+ ProxyProperties.prototype.close = function() {
+ this.connection.close();
+ }
+
+ // Public stub class properties that are managed at runtime by the JS
+ // bindings. See StubBindings below.
+ function StubProperties(delegate) {
+ this.delegate = delegate;
+ }
+
+ StubProperties.prototype.close = function() {
+ this.connection.close();
+ }
+
+ // The base class for generated proxy classes.
+ function ProxyBase(receiver) {
+ this[kProxyProperties] = new ProxyProperties(receiver);
+
+ // TODO(hansmuller): Temporary, for Chrome backwards compatibility.
+ if (receiver instanceof Router)
+ this.receiver_ = receiver;
+ }
+
+ // The base class for generated stub classes.
+ function StubBase(delegate) {
+ this[kStubProperties] = new StubProperties(delegate);
+ }
+
+ // TODO(hansmuller): remove everything except the connection property doc
+ // after 'Client=' has been removed from Mojom.
+
+ // Provides access to properties added to a proxy object without risking
+ // Mojo interface name collisions. Unless otherwise specified, the initial
+ // value of all properties is undefined.
+ //
+ // ProxyBindings(proxy).connection - The Connection object that links the
+ // proxy for a remote Mojo service to an optional local stub for a local
+ // service. The value of ProxyBindings(proxy).connection.remote == proxy.
+ //
+ // ProxyBindings(proxy).local - The "local" stub object whose delegate
+ // implements the proxy's Mojo client interface.
+ //
+ // ProxyBindings(proxy).setLocalDelegate(impl) - Sets the implementation
+ // delegate of the proxy's client stub object. This is just shorthand
+ // for |StubBindings(ProxyBindings(proxy).local).delegate = impl|.
+ //
+ // ProxyBindings(proxy).getLocalDelegate() - Returns the implementation
+ // delegate of the proxy's client stub object. This is just shorthand
+ // for |StubBindings(ProxyBindings(proxy).local).delegate|.
+
+ function ProxyBindings(proxy) {
+ return (proxy instanceof ProxyBase) ? proxy[kProxyProperties] : proxy;
+ }
+
+ // TODO(hansmuller): remove the remote doc after 'Client=' has been
+ // removed from Mojom.
+
+ // Provides access to properties added to a stub object without risking
+ // Mojo interface name collisions. Unless otherwise specified, the initial
+ // value of all properties is undefined.
+ //
+ // StubBindings(stub).delegate - The optional implementation delegate for
+ // the Mojo interface stub.
+ //
+ // StubBindings(stub).connection - The Connection object that links an
+ // optional proxy for a remote service to this stub. The value of
+ // StubBindings(stub).connection.local == stub.
+ //
+ // StubBindings(stub).remote - A proxy for the the stub's Mojo client
+ // service.
+
+ function StubBindings(stub) {
+ return stub instanceof StubBase ? stub[kStubProperties] : stub;
+ }
+
// TODO(hansmuller): the proxy receiver_ property should be receiver$
function BaseConnection(localStub, remoteProxy, router) {
@@ -184,6 +276,12 @@ define("mojo/public/js/connection", [
var exports = {};
exports.Connection = Connection;
+ exports.EmptyProxy = ProxyBase;
+ exports.EmptyStub = StubBase;
+ exports.ProxyBase = ProxyBase;
+ exports.ProxyBindings = ProxyBindings;
+ exports.StubBase = StubBase;
+ exports.StubBindings = StubBindings;
exports.TestConnection = TestConnection;
exports.bindProxy = bindProxy;
« 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