Index: mojo/public/js/bindings.js |
diff --git a/mojo/public/js/bindings.js b/mojo/public/js/bindings.js |
index a944e2f7aaf28d4cbcf8f6d9e1dfbd14cfc016f4..f3e40d293ebb025f4bf3c8a3c4e01c81626b5aa4 100644 |
--- a/mojo/public/js/bindings.js |
+++ b/mojo/public/js/bindings.js |
@@ -4,12 +4,10 @@ |
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, types, interfaceEndpointClient, router) { |
- |
- var InterfaceEndpointClient = interfaceEndpointClient.InterfaceEndpointClient; |
+], function(core, controlMessageProxy, types, router) { |
// --------------------------------------------------------------------------- |
@@ -29,13 +27,12 @@ |
this.interfaceType_ = interfaceType; |
this.router_ = null; |
- this.interfaceEndpointClient_ = null; |
this.proxy_ = null; |
- // |router_| and |interfaceEndpointClient_| are lazily initialized. |
- // |handle_| is valid between bind() and |
- // the initialization of |router_| and |interfaceEndpointClient_|. |
+ // |router_| is lazily initialized. |handle_| is valid between bind() and |
+ // the initialization of |router_|. |
this.handle_ = null; |
+ this.controlMessageProxy_ = null; |
if (ptrInfoOrHandle) |
this.bind(ptrInfoOrHandle); |
@@ -60,10 +57,6 @@ |
// immediately. |
InterfacePtrController.prototype.reset = function() { |
this.version = 0; |
- if (this.interfaceEndpointClient_) { |
- this.interfaceEndpointClient_.close(); |
- this.interfaceEndpointClient_ = null; |
- } |
if (this.router_) { |
this.router_.close(); |
this.router_ = null; |
@@ -76,20 +69,13 @@ |
} |
}; |
- InterfacePtrController.prototype.resetWithReason = function(reason) { |
- this.configureProxyIfNecessary_(); |
- this.interfaceEndpointClient_.close(reason); |
- this.interfaceEndpointClient_ = null; |
- this.reset(); |
- }; |
- |
- InterfacePtrController.prototype.setConnectionErrorHandler = function( |
- callback) { |
+ InterfacePtrController.prototype.setConnectionErrorHandler |
+ = function(callback) { |
if (!this.isBound()) |
throw new Error("Cannot set connection error handler if not bound."); |
this.configureProxyIfNecessary_(); |
- this.interfaceEndpointClient_.setConnectionErrorHandler(callback); |
+ this.router_.setErrorHandler(callback); |
}; |
InterfacePtrController.prototype.passInterface = function() { |
@@ -114,9 +100,9 @@ |
return this.proxy_; |
}; |
- InterfacePtrController.prototype.waitForNextMessageForTesting = function() { |
- this.configureProxyIfNecessary_(); |
- this.router_.waitForNextMessageForTesting(); |
+ InterfacePtrController.prototype.enableTestingMode = function() { |
+ this.configureProxyIfNecessary_(); |
+ return this.router_.enableTestingMode(); |
}; |
InterfacePtrController.prototype.configureProxyIfNecessary_ = function() { |
@@ -125,15 +111,12 @@ |
this.router_ = new router.Router(this.handle_); |
this.handle_ = null; |
- |
- this.interfaceEndpointClient_ = new InterfaceEndpointClient( |
- this.router_.createLocalEndpointHandle(types.kMasterInterfaceId), |
- this.router_); |
- |
- this.interfaceEndpointClient_ .setPayloadValidators([ |
- this.interfaceType_.validateResponse]); |
- this.proxy_ = new this.interfaceType_.proxyClass( |
- this.interfaceEndpointClient_); |
+ this.router_ .setPayloadValidators([this.interfaceType_.validateResponse]); |
+ |
+ this.controlMessageProxy_ = new |
+ controlMessageProxy.ControlMessageProxy(this.router_); |
+ |
+ this.proxy_ = new this.interfaceType_.proxyClass(this.router_); |
}; |
InterfacePtrController.prototype.queryVersion = function() { |
@@ -143,7 +126,7 @@ |
} |
this.configureProxyIfNecessary_(); |
- return this.interfaceEndpointClient_.queryVersion().then( |
+ return this.controlMessageProxy_.queryVersion().then( |
onQueryVersion.bind(this)); |
}; |
@@ -154,7 +137,7 @@ |
return; |
} |
this.version = version; |
- this.interfaceEndpointClient_.requireVersion(version); |
+ this.controlMessageProxy_.requireVersion(version); |
}; |
// --------------------------------------------------------------------------- |
@@ -176,7 +159,6 @@ |
this.interfaceType_ = interfaceType; |
this.impl_ = impl; |
this.router_ = null; |
- this.interfaceEndpointClient_ = null; |
this.stub_ = null; |
if (requestOrHandle) |
@@ -192,7 +174,7 @@ |
// TODO(yzshen): Set the version of the interface pointer. |
this.bind(makeRequest(ptr)); |
return ptr; |
- }; |
+ } |
Binding.prototype.bind = function(requestOrHandle) { |
this.close(); |
@@ -202,45 +184,26 @@ |
if (!core.isHandle(handle)) |
return; |
- this.router_ = new router.Router(handle); |
- |
this.stub_ = new this.interfaceType_.stubClass(this.impl_); |
- 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]); |
+ this.router_ = new router.Router(handle, this.interfaceType_.kVersion); |
+ this.router_.setIncomingReceiver(this.stub_); |
+ this.router_ .setPayloadValidators([this.interfaceType_.validateRequest]); |
}; |
Binding.prototype.close = function() { |
if (!this.isBound()) |
return; |
- |
- if (this.interfaceEndpointClient_) { |
- this.interfaceEndpointClient_.close(); |
- this.interfaceEndpointClient_ = null; |
- } |
this.router_.close(); |
this.router_ = null; |
this.stub_ = null; |
}; |
- Binding.prototype.closeWithReason = function(reason) { |
- if (this.interfaceEndpointClient_) { |
- this.interfaceEndpointClient_.close(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.interfaceEndpointClient_.setConnectionErrorHandler(callback); |
+ this.router_.setErrorHandler(callback); |
}; |
Binding.prototype.unbind = function() { |
@@ -253,8 +216,8 @@ |
return result; |
}; |
- Binding.prototype.waitForNextMessageForTesting = function() { |
- this.router_.waitForNextMessageForTesting(); |
+ Binding.prototype.enableTestingMode = function() { |
+ return this.router_.enableTestingMode(); |
}; |
// --------------------------------------------------------------------------- |