| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 define("mojo/public/js/bindings", [ | 5 define("mojo/public/js/bindings", [ |
| 6 "mojo/public/js/core", | |
| 7 "mojo/public/js/lib/control_message_proxy", | 6 "mojo/public/js/lib/control_message_proxy", |
| 8 "mojo/public/js/interface_types", | 7 "mojo/public/js/interface_types", |
| 9 "mojo/public/js/router", | 8 "mojo/public/js/router", |
| 10 ], function(core, controlMessageProxy, types, router) { | 9 ], function(controlMessageProxy, types, router) { |
| 11 | 10 |
| 12 // --------------------------------------------------------------------------- | 11 // --------------------------------------------------------------------------- |
| 13 | 12 |
| 14 function makeRequest(interfacePtr) { | 13 function makeRequest(interfacePtr) { |
| 15 var pipe = core.createMessagePipe(); | 14 var pipe = Mojo.createMessagePipe(); |
| 16 interfacePtr.ptr.bind(new types.InterfacePtrInfo(pipe.handle0, 0)); | 15 interfacePtr.ptr.bind(new types.InterfacePtrInfo(pipe.handle0, 0)); |
| 17 return new types.InterfaceRequest(pipe.handle1); | 16 return new types.InterfaceRequest(pipe.handle1); |
| 18 } | 17 } |
| 19 | 18 |
| 20 // --------------------------------------------------------------------------- | 19 // --------------------------------------------------------------------------- |
| 21 | 20 |
| 22 // Operations used to setup/configure an interface pointer. Exposed as the | 21 // Operations used to setup/configure an interface pointer. Exposed as the |
| 23 // |ptr| field of generated interface pointer classes. | 22 // |ptr| field of generated interface pointer classes. |
| 24 // |ptrInfoOrHandle| could be omitted and passed into bind() later. | 23 // |ptrInfoOrHandle| could be omitted and passed into bind() later. |
| 25 function InterfacePtrController(interfaceType, ptrInfoOrHandle) { | 24 function InterfacePtrController(interfaceType, ptrInfoOrHandle) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // immediately. | 56 // immediately. |
| 58 InterfacePtrController.prototype.reset = function() { | 57 InterfacePtrController.prototype.reset = function() { |
| 59 this.version = 0; | 58 this.version = 0; |
| 60 if (this.router_) { | 59 if (this.router_) { |
| 61 this.router_.close(); | 60 this.router_.close(); |
| 62 this.router_ = null; | 61 this.router_ = null; |
| 63 | 62 |
| 64 this.proxy_ = null; | 63 this.proxy_ = null; |
| 65 } | 64 } |
| 66 if (this.handle_) { | 65 if (this.handle_) { |
| 67 core.close(this.handle_); | 66 this.handle_.close(); |
| 68 this.handle_ = null; | 67 this.handle_ = null; |
| 69 } | 68 } |
| 70 }; | 69 }; |
| 71 | 70 |
| 72 InterfacePtrController.prototype.setConnectionErrorHandler | 71 InterfacePtrController.prototype.setConnectionErrorHandler |
| 73 = function(callback) { | 72 = function(callback) { |
| 74 if (!this.isBound()) | 73 if (!this.isBound()) |
| 75 throw new Error("Cannot set connection error handler if not bound."); | 74 throw new Error("Cannot set connection error handler if not bound."); |
| 76 | 75 |
| 77 this.configureProxyIfNecessary_(); | 76 this.configureProxyIfNecessary_(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 // TODO(yzshen): Set the version of the interface pointer. | 173 // TODO(yzshen): Set the version of the interface pointer. |
| 175 this.bind(makeRequest(ptr)); | 174 this.bind(makeRequest(ptr)); |
| 176 return ptr; | 175 return ptr; |
| 177 } | 176 } |
| 178 | 177 |
| 179 Binding.prototype.bind = function(requestOrHandle) { | 178 Binding.prototype.bind = function(requestOrHandle) { |
| 180 this.close(); | 179 this.close(); |
| 181 | 180 |
| 182 var handle = requestOrHandle instanceof types.InterfaceRequest ? | 181 var handle = requestOrHandle instanceof types.InterfaceRequest ? |
| 183 requestOrHandle.handle : requestOrHandle; | 182 requestOrHandle.handle : requestOrHandle; |
| 184 if (!core.isHandle(handle)) | 183 if (!(handle instanceof MojoHandle)) |
| 185 return; | 184 return; |
| 186 | 185 |
| 187 this.stub_ = new this.interfaceType_.stubClass(this.impl_); | 186 this.stub_ = new this.interfaceType_.stubClass(this.impl_); |
| 188 this.router_ = new router.Router(handle, this.interfaceType_.kVersion); | 187 this.router_ = new router.Router(handle, this.interfaceType_.kVersion); |
| 189 this.router_.setIncomingReceiver(this.stub_); | 188 this.router_.setIncomingReceiver(this.stub_); |
| 190 this.router_ .setPayloadValidators([this.interfaceType_.validateRequest]); | 189 this.router_ .setPayloadValidators([this.interfaceType_.validateRequest]); |
| 191 }; | 190 }; |
| 192 | 191 |
| 193 Binding.prototype.close = function() { | 192 Binding.prototype.close = function() { |
| 194 if (!this.isBound()) | 193 if (!this.isBound()) |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 var exports = {}; | 275 var exports = {}; |
| 277 exports.InterfacePtrInfo = types.InterfacePtrInfo; | 276 exports.InterfacePtrInfo = types.InterfacePtrInfo; |
| 278 exports.InterfaceRequest = types.InterfaceRequest; | 277 exports.InterfaceRequest = types.InterfaceRequest; |
| 279 exports.makeRequest = makeRequest; | 278 exports.makeRequest = makeRequest; |
| 280 exports.InterfacePtrController = InterfacePtrController; | 279 exports.InterfacePtrController = InterfacePtrController; |
| 281 exports.Binding = Binding; | 280 exports.Binding = Binding; |
| 282 exports.BindingSet = BindingSet; | 281 exports.BindingSet = BindingSet; |
| 283 | 282 |
| 284 return exports; | 283 return exports; |
| 285 }); | 284 }); |
| OLD | NEW |