Mojo JS Bindings: Add support for closing Proxy and Stub connections

BUG=
R=jamesr@chromium.org

Review URL: https://codereview.chromium.org/883953003
diff --git a/mojo/public/js/bindings.js b/mojo/public/js/bindings.js
index c6c98d5..44aa9f4 100644
--- a/mojo/public/js/bindings.js
+++ b/mojo/public/js/bindings.js
@@ -4,7 +4,8 @@
 
 define("mojo/public/js/bindings", [
   "mojo/public/js/router",
-], function(router) {
+  "mojo/public/js/core",
+], function(router, core) {
 
   var Router = router.Router;
 
@@ -30,12 +31,31 @@
       throw new Error("no stub object");
   }
 
+  function connectionHandle(connection) {
+    return connection &&
+        connection.router &&
+        connection.router.connector_ &&
+        connection.router.connector_.handle_;
+  }
+
+  ProxyProperties.prototype.close = function() {
+    var handle = connectionHandle(this.connection);
+    if (handle)
+      core.close(handle);
+  }
+
   // 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() {
+    var handle = connectionHandle(this.connection);
+    if (handle)
+      core.close(handle);
+  }
+
   // The base class for generated proxy classes.
   function ProxyBase(receiver) {
     this[kProxyProperties] = new ProxyProperties(receiver);