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/lib/interface_endpoint_client", | 8 "mojo/public/js/lib/interface_endpoint_client", |
9 "mojo/public/js/router", | 9 "mojo/public/js/router", |
10 ], function(core, types, interfaceEndpointClient, router) { | 10 ], function(core, types, interfaceEndpointClient, router) { |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 Binding.prototype.waitForNextMessageForTesting = function() { | 256 Binding.prototype.waitForNextMessageForTesting = function() { |
257 this.router_.waitForNextMessageForTesting(); | 257 this.router_.waitForNextMessageForTesting(); |
258 }; | 258 }; |
259 | 259 |
260 // --------------------------------------------------------------------------- | 260 // --------------------------------------------------------------------------- |
261 | 261 |
262 function BindingSetEntry(bindingSet, interfaceType, impl, requestOrHandle, | 262 function BindingSetEntry(bindingSet, interfaceType, impl, requestOrHandle, |
263 bindingId) { | 263 bindingId) { |
264 this.bindingSet_ = bindingSet; | 264 this.bindingSet_ = bindingSet; |
265 this.bindingId_ = bindingId; | 265 this.bindingId_ = bindingId; |
266 this.binding_ = new Binding(interfaceType, impl, requestOrHandle); | 266 this.binding_ = new bindingSet.bindingType(interfaceType, impl, |
| 267 requestOrHandle); |
267 | 268 |
268 this.binding_.setConnectionErrorHandler(function() { | 269 this.binding_.setConnectionErrorHandler(function(reason) { |
269 this.bindingSet_.onConnectionError(bindingId); | 270 this.bindingSet_.onConnectionError(bindingId, reason); |
270 }.bind(this)); | 271 }.bind(this)); |
271 } | 272 } |
272 | 273 |
273 BindingSetEntry.prototype.close = function() { | 274 BindingSetEntry.prototype.close = function() { |
274 this.binding_.close(); | 275 this.binding_.close(); |
275 }; | 276 }; |
276 | 277 |
277 function BindingSet(interfaceType) { | 278 function BindingSet(interfaceType) { |
278 this.interfaceType_ = interfaceType; | 279 this.interfaceType_ = interfaceType; |
279 this.nextBindingId_ = 0; | 280 this.nextBindingId_ = 0; |
280 this.bindings_ = new Map(); | 281 this.bindings_ = new Map(); |
281 this.errorHandler_ = null; | 282 this.errorHandler_ = null; |
| 283 this.bindingType = Binding; |
282 } | 284 } |
283 | 285 |
284 BindingSet.prototype.isEmpty = function() { | 286 BindingSet.prototype.isEmpty = function() { |
285 return this.bindings_.size == 0; | 287 return this.bindings_.size == 0; |
286 }; | 288 }; |
287 | 289 |
288 BindingSet.prototype.addBinding = function(impl, requestOrHandle) { | 290 BindingSet.prototype.addBinding = function(impl, requestOrHandle) { |
289 this.bindings_.set( | 291 this.bindings_.set( |
290 this.nextBindingId_, | 292 this.nextBindingId_, |
291 new BindingSetEntry(this, this.interfaceType_, impl, requestOrHandle, | 293 new BindingSetEntry(this, this.interfaceType_, impl, requestOrHandle, |
292 this.nextBindingId_)); | 294 this.nextBindingId_)); |
293 ++this.nextBindingId_; | 295 ++this.nextBindingId_; |
294 }; | 296 }; |
295 | 297 |
296 BindingSet.prototype.closeAllBindings = function() { | 298 BindingSet.prototype.closeAllBindings = function() { |
297 for (var entry of this.bindings_.values()) | 299 for (var entry of this.bindings_.values()) |
298 entry.close(); | 300 entry.close(); |
299 this.bindings_.clear(); | 301 this.bindings_.clear(); |
300 }; | 302 }; |
301 | 303 |
302 BindingSet.prototype.setConnectionErrorHandler = function(callback) { | 304 BindingSet.prototype.setConnectionErrorHandler = function(callback) { |
303 this.errorHandler_ = callback; | 305 this.errorHandler_ = callback; |
304 }; | 306 }; |
305 | 307 |
306 BindingSet.prototype.onConnectionError = function(bindingId) { | 308 BindingSet.prototype.onConnectionError = function(bindingId, reason) { |
307 this.bindings_.delete(bindingId); | 309 this.bindings_.delete(bindingId); |
308 | 310 |
309 if (this.errorHandler_) | 311 if (this.errorHandler_) |
310 this.errorHandler_(); | 312 this.errorHandler_(reason); |
311 }; | 313 }; |
312 | 314 |
313 var exports = {}; | 315 var exports = {}; |
314 exports.InterfacePtrInfo = types.InterfacePtrInfo; | 316 exports.InterfacePtrInfo = types.InterfacePtrInfo; |
315 exports.InterfaceRequest = types.InterfaceRequest; | 317 exports.InterfaceRequest = types.InterfaceRequest; |
316 exports.makeRequest = makeRequest; | 318 exports.makeRequest = makeRequest; |
317 exports.InterfacePtrController = InterfacePtrController; | 319 exports.InterfacePtrController = InterfacePtrController; |
318 exports.Binding = Binding; | 320 exports.Binding = Binding; |
319 exports.BindingSet = BindingSet; | 321 exports.BindingSet = BindingSet; |
320 | 322 |
321 return exports; | 323 return exports; |
322 }); | 324 }); |
OLD | NEW |