Chromium Code Reviews| Index: mojo/public/js/bindings.js |
| diff --git a/mojo/public/js/bindings.js b/mojo/public/js/bindings.js |
| index f3e40d293ebb025f4bf3c8a3c4e01c81626b5aa4..9a97ab41c683efd5f204531d5e25829b39e2ae0f 100644 |
| --- a/mojo/public/js/bindings.js |
| +++ b/mojo/public/js/bindings.js |
| @@ -4,10 +4,12 @@ |
| define("mojo/public/js/bindings", [ |
| "mojo/public/js/core", |
| - "mojo/public/js/lib/control_message_proxy", |
| "mojo/public/js/interface_types", |
| + "mojo/public/js/lib/interface_endpoint_client", |
| "mojo/public/js/router", |
| -], function(core, controlMessageProxy, types, router) { |
| +], function(core, types, interfaceEndpointClient, router) { |
| + |
| + var InterfaceEndpointClient = interfaceEndpointClient.InterfaceEndpointClient; |
| // --------------------------------------------------------------------------- |
| @@ -27,10 +29,12 @@ define("mojo/public/js/bindings", [ |
| this.interfaceType_ = interfaceType; |
| this.router_ = null; |
| + this.interfaceEndpointClient_ = null; |
| this.proxy_ = null; |
| - // |router_| is lazily initialized. |handle_| is valid between bind() and |
| - // the initialization of |router_|. |
| + // |router_| and |interfaceEndpointClient_| are lazily initialized. |
| + // |handle_| is valid between bind() and |
| + // the initialization of |router_| and |interfaceEndpointClient_|. |
| this.handle_ = null; |
| this.controlMessageProxy_ = null; |
|
yzshen1
2017/03/28 00:45:59
I think this one is not used anymore?
wangjimmy
2017/03/29 17:01:18
Done.
|
| @@ -57,6 +61,10 @@ define("mojo/public/js/bindings", [ |
| // immediately. |
| InterfacePtrController.prototype.reset = function() { |
| this.version = 0; |
| + if (this.interfaceEndpointClient_) { |
| + this.interfaceEndpointClient_.closeWithReason(); |
|
yzshen1
2017/03/28 00:45:59
How about we rename the method to close(), which c
wangjimmy
2017/03/29 17:01:18
Done. I agreed. Renamed to close
|
| + this.interfaceEndpointClient_ = null; |
| + } |
| if (this.router_) { |
| this.router_.close(); |
| this.router_ = null; |
| @@ -69,13 +77,20 @@ define("mojo/public/js/bindings", [ |
| } |
| }; |
| - InterfacePtrController.prototype.setConnectionErrorHandler |
| - = function(callback) { |
| + InterfacePtrController.prototype.resetWithReason = function(reason) { |
| + this.configureProxyIfNecessary_(); |
| + this.interfaceEndpointClient_.closeWithReason(reason); |
| + this.interfaceEndpointClient_ = null; |
| + this.reset(); |
| + }; |
| + |
| + InterfacePtrController.prototype.setConnectionErrorHandler = function( |
| + callback) { |
| if (!this.isBound()) |
| throw new Error("Cannot set connection error handler if not bound."); |
| this.configureProxyIfNecessary_(); |
| - this.router_.setErrorHandler(callback); |
| + this.interfaceEndpointClient_.setConnectionErrorHandler(callback); |
| }; |
| InterfacePtrController.prototype.passInterface = function() { |
| @@ -100,9 +115,9 @@ define("mojo/public/js/bindings", [ |
| return this.proxy_; |
| }; |
| - InterfacePtrController.prototype.enableTestingMode = function() { |
| + InterfacePtrController.prototype.waitForNextMessageForTesting = function() { |
| this.configureProxyIfNecessary_(); |
| - return this.router_.enableTestingMode(); |
| + this.router_.waitForNextMessageForTesting(); |
| }; |
| InterfacePtrController.prototype.configureProxyIfNecessary_ = function() { |
| @@ -111,12 +126,15 @@ define("mojo/public/js/bindings", [ |
| this.router_ = new router.Router(this.handle_); |
| this.handle_ = null; |
| - this.router_ .setPayloadValidators([this.interfaceType_.validateResponse]); |
| - this.controlMessageProxy_ = new |
| - controlMessageProxy.ControlMessageProxy(this.router_); |
| + this.interfaceEndpointClient_ = new InterfaceEndpointClient( |
| + this.router_.createLocalEndpointHandle(types.kMasterInterfaceId), |
| + this.router_); |
| - this.proxy_ = new this.interfaceType_.proxyClass(this.router_); |
| + this.interfaceEndpointClient_ .setPayloadValidators([ |
| + this.interfaceType_.validateResponse]); |
| + this.proxy_ = new this.interfaceType_.proxyClass( |
| + this.interfaceEndpointClient_); |
| }; |
| InterfacePtrController.prototype.queryVersion = function() { |
| @@ -126,7 +144,7 @@ define("mojo/public/js/bindings", [ |
| } |
| this.configureProxyIfNecessary_(); |
| - return this.controlMessageProxy_.queryVersion().then( |
| + return this.interfaceEndpointClient_.queryVersion().then( |
| onQueryVersion.bind(this)); |
| }; |
| @@ -137,7 +155,7 @@ define("mojo/public/js/bindings", [ |
| return; |
| } |
| this.version = version; |
| - this.controlMessageProxy_.requireVersion(version); |
| + this.interfaceEndpointClient_.requireVersion(version); |
| }; |
| // --------------------------------------------------------------------------- |
| @@ -159,6 +177,7 @@ define("mojo/public/js/bindings", [ |
| this.interfaceType_ = interfaceType; |
| this.impl_ = impl; |
| this.router_ = null; |
| + this.interfaceEndpointClient_ = null; |
| this.stub_ = null; |
| if (requestOrHandle) |
| @@ -174,7 +193,7 @@ define("mojo/public/js/bindings", [ |
| // TODO(yzshen): Set the version of the interface pointer. |
| this.bind(makeRequest(ptr)); |
| return ptr; |
| - } |
| + }; |
| Binding.prototype.bind = function(requestOrHandle) { |
| this.close(); |
| @@ -184,26 +203,45 @@ define("mojo/public/js/bindings", [ |
| if (!core.isHandle(handle)) |
| return; |
| + this.router_ = new router.Router(handle); |
| + |
| this.stub_ = new this.interfaceType_.stubClass(this.impl_); |
| - this.router_ = new router.Router(handle, this.interfaceType_.kVersion); |
| - this.router_.setIncomingReceiver(this.stub_); |
| - this.router_ .setPayloadValidators([this.interfaceType_.validateRequest]); |
| + this.interfaceEndpointClient_ = new InterfaceEndpointClient( |
| + this.router_.createLocalEndpointHandle(types.kMasterInterfaceId), |
| + this.router_, this.interfaceType_.kVersion); |
| + this.interfaceEndpointClient_.setIncomingReceiver(this.stub_); |
| + this.interfaceEndpointClient_ .setPayloadValidators([ |
| + this.interfaceType_.validateRequest]); |
| }; |
| Binding.prototype.close = function() { |
| if (!this.isBound()) |
| return; |
| + if (this.interfaceEndpointClient_) { |
| + this.interfaceEndpointClient_.closeWithReason(); |
| + this.interfaceEndpointClient_ = null; |
| + } |
| + |
| this.router_.close(); |
| this.router_ = null; |
| this.stub_ = null; |
| }; |
| + Binding.prototype.closeWithReason = function(reason) { |
| + if (this.interfaceEndpointClient_) { |
| + this.interfaceEndpointClient_.closeWithReason(reason); |
| + this.interfaceEndpointClient_ = null; |
| + } |
| + this.close(); |
| + }; |
| + |
| Binding.prototype.setConnectionErrorHandler |
| = function(callback) { |
| - if (!this.isBound()) |
| + if (!this.isBound()) { |
| throw new Error("Cannot set connection error handler if not bound."); |
| - this.router_.setErrorHandler(callback); |
| + } |
| + this.interfaceEndpointClient_.setConnectionErrorHandler(callback); |
| }; |
| Binding.prototype.unbind = function() { |
| @@ -216,8 +254,8 @@ define("mojo/public/js/bindings", [ |
| return result; |
| }; |
| - Binding.prototype.enableTestingMode = function() { |
| - return this.router_.enableTestingMode(); |
| + Binding.prototype.waitForNextMessageForTesting = function() { |
| + this.router_.waitForNextMessageForTesting(); |
| }; |
| // --------------------------------------------------------------------------- |