| 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", | 6 "mojo/public/js/core", |
| 7 "mojo/public/js/interface_types", | 7 "mojo/public/js/interface_types", |
| 8 "mojo/public/js/router", | 8 "mojo/public/js/router", |
| 9 ], function(core, types, router) { | 9 "mojo/public/js/lib/control_message_proxy", |
| 10 ], function(core, types, router, controlMessageProxy) { |
| 10 | 11 |
| 11 // --------------------------------------------------------------------------- | 12 // --------------------------------------------------------------------------- |
| 12 | 13 |
| 13 function makeRequest(interfacePtr) { | 14 function makeRequest(interfacePtr) { |
| 14 var pipe = core.createMessagePipe(); | 15 var pipe = core.createMessagePipe(); |
| 15 interfacePtr.ptr.bind(new types.InterfacePtrInfo(pipe.handle0, 0)); | 16 interfacePtr.ptr.bind(new types.InterfacePtrInfo(pipe.handle0, 0)); |
| 16 return new types.InterfaceRequest(pipe.handle1); | 17 return new types.InterfaceRequest(pipe.handle1); |
| 17 } | 18 } |
| 18 | 19 |
| 19 // --------------------------------------------------------------------------- | 20 // --------------------------------------------------------------------------- |
| 20 | 21 |
| 21 // Operations used to setup/configure an interface pointer. Exposed as the | 22 // Operations used to setup/configure an interface pointer. Exposed as the |
| 22 // |ptr| field of generated interface pointer classes. | 23 // |ptr| field of generated interface pointer classes. |
| 23 // |ptrInfoOrHandle| could be omitted and passed into bind() later. | 24 // |ptrInfoOrHandle| could be omitted and passed into bind() later. |
| 24 function InterfacePtrController(interfaceType, ptrInfoOrHandle) { | 25 function InterfacePtrController(interfaceType, ptrInfoOrHandle) { |
| 25 this.version = 0; | 26 this.version = 0; |
| 26 | 27 |
| 27 this.interfaceType_ = interfaceType; | 28 this.interfaceType_ = interfaceType; |
| 28 this.router_ = null; | 29 this.router_ = null; |
| 29 this.proxy_ = null; | 30 this.proxy_ = null; |
| 30 | 31 |
| 31 // |router_| is lazily initialized. |handle_| is valid between bind() and | 32 // |router_| is lazily initialized. |handle_| is valid between bind() and |
| 32 // the initialization of |router_|. | 33 // the initialization of |router_|. |
| 33 this.handle_ = null; | 34 this.handle_ = null; |
| 35 this.controlMessageProxy_ = new controlMessageProxy.ControlMessageProxy(); |
| 34 | 36 |
| 35 if (ptrInfoOrHandle) | 37 if (ptrInfoOrHandle) |
| 36 this.bind(ptrInfoOrHandle); | 38 this.bind(ptrInfoOrHandle); |
| 37 } | 39 } |
| 38 | 40 |
| 39 InterfacePtrController.prototype.bind = function(ptrInfoOrHandle) { | 41 InterfacePtrController.prototype.bind = function(ptrInfoOrHandle) { |
| 40 this.reset(); | 42 this.reset(); |
| 41 | 43 |
| 42 if (ptrInfoOrHandle instanceof types.InterfacePtrInfo) { | 44 if (ptrInfoOrHandle instanceof types.InterfacePtrInfo) { |
| 43 this.version = ptrInfoOrHandle.version; | 45 this.version = ptrInfoOrHandle.version; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 return this.router_.enableTestingMode(); | 105 return this.router_.enableTestingMode(); |
| 104 }; | 106 }; |
| 105 | 107 |
| 106 InterfacePtrController.prototype.configureProxyIfNecessary_ = function() { | 108 InterfacePtrController.prototype.configureProxyIfNecessary_ = function() { |
| 107 if (!this.handle_) | 109 if (!this.handle_) |
| 108 return; | 110 return; |
| 109 | 111 |
| 110 this.router_ = new router.Router(this.handle_); | 112 this.router_ = new router.Router(this.handle_); |
| 111 this.handle_ = null; | 113 this.handle_ = null; |
| 112 this.router_ .setPayloadValidators([this.interfaceType_.validateResponse]); | 114 this.router_ .setPayloadValidators([this.interfaceType_.validateResponse]); |
| 115 this.controlMessageProxy_.receiver = this.router_; |
| 113 | 116 |
| 114 this.proxy_ = new this.interfaceType_.proxyClass(this.router_); | 117 this.proxy_ = new this.interfaceType_.proxyClass(this.router_); |
| 115 }; | 118 }; |
| 116 | 119 |
| 117 // TODO(yzshen): Implement the following methods. | 120 InterfacePtrController.prototype.queryVersion = function() { |
| 118 // InterfacePtrController.prototype.queryVersion | 121 this.configureProxyIfNecessary_(); |
| 119 // InterfacePtrController.prototype.requireVersion | 122 return this.controlMessageProxy_.queryVersion().then(function(version) { |
| 123 this.version = version; |
| 124 return version; |
| 125 }); |
| 126 }; |
| 127 |
| 128 InterfacePtrController.prototype.requireVersion = function(version) { |
| 129 this.configureProxyIfNecessary_(); |
| 130 |
| 131 if (this.version >= version) { |
| 132 return; |
| 133 } |
| 134 this.version = version; |
| 135 this.controlMessageProxy_.requireVersion(version); |
| 136 }; |
| 120 | 137 |
| 121 // --------------------------------------------------------------------------- | 138 // --------------------------------------------------------------------------- |
| 122 | 139 |
| 123 // |request| could be omitted and passed into bind() later. | 140 // |request| could be omitted and passed into bind() later. |
| 124 // | 141 // |
| 125 // Example: | 142 // Example: |
| 126 // | 143 // |
| 127 // // FooImpl implements mojom.Foo. | 144 // // FooImpl implements mojom.Foo. |
| 128 // function FooImpl() { ... } | 145 // function FooImpl() { ... } |
| 129 // FooImpl.prototype.fooMethod1 = function() { ... } | 146 // FooImpl.prototype.fooMethod1 = function() { ... } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 var exports = {}; | 271 var exports = {}; |
| 255 exports.InterfacePtrInfo = types.InterfacePtrInfo; | 272 exports.InterfacePtrInfo = types.InterfacePtrInfo; |
| 256 exports.InterfaceRequest = types.InterfaceRequest; | 273 exports.InterfaceRequest = types.InterfaceRequest; |
| 257 exports.makeRequest = makeRequest; | 274 exports.makeRequest = makeRequest; |
| 258 exports.InterfacePtrController = InterfacePtrController; | 275 exports.InterfacePtrController = InterfacePtrController; |
| 259 exports.Binding = Binding; | 276 exports.Binding = Binding; |
| 260 exports.BindingSet = BindingSet; | 277 exports.BindingSet = BindingSet; |
| 261 | 278 |
| 262 return exports; | 279 return exports; |
| 263 }); | 280 }); |
| OLD | NEW |