| 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/connector", [ | 5 define("mojo/public/js/connector", [ |
| 6 "mojo/public/js/buffer", | 6 "mojo/public/js/buffer", |
| 7 "mojo/public/js/codec", | 7 "mojo/public/js/codec", |
| 8 "mojo/public/js/core", | 8 "mojo/public/js/core", |
| 9 "mojo/public/js/support", | 9 "mojo/public/js/support", |
| 10 ], function(buffer, codec, core, support) { | 10 ], function(buffer, codec, core, support) { |
| 11 | 11 |
| 12 // Putting the handles somewhere causes them to not get lost. |
| 13 var allHandles = []; |
| 14 |
| 12 function Connector(handle) { | 15 function Connector(handle) { |
| 13 if (!core.isHandle(handle)) | 16 if (!core.isHandle(handle)) |
| 14 throw new Error("Connector: not a handle " + handle); | 17 throw new Error("Connector: not a handle " + handle); |
| 15 this.handle_ = handle; | 18 this.handle_ = handle; |
| 16 this.dropWrites_ = false; | 19 this.dropWrites_ = false; |
| 17 this.error_ = false; | 20 this.error_ = false; |
| 18 this.incomingReceiver_ = null; | 21 this.incomingReceiver_ = null; |
| 19 this.readWatcher_ = null; | 22 this.readWatcher_ = null; |
| 20 this.errorHandler_ = null; | 23 this.errorHandler_ = null; |
| 21 | 24 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 37 } | 40 } |
| 38 }; | 41 }; |
| 39 | 42 |
| 40 Connector.prototype.accept = function(message) { | 43 Connector.prototype.accept = function(message) { |
| 41 if (this.error_) | 44 if (this.error_) |
| 42 return false; | 45 return false; |
| 43 | 46 |
| 44 if (this.dropWrites_) | 47 if (this.dropWrites_) |
| 45 return true; | 48 return true; |
| 46 | 49 |
| 50 allHandles = allHandles.concat(message.handles); |
| 47 var result = core.writeMessage(this.handle_, | 51 var result = core.writeMessage(this.handle_, |
| 48 new Uint8Array(message.buffer.arrayBuffer), | 52 new Uint8Array(message.buffer.arrayBuffer), |
| 49 message.handles, | 53 message.handles, |
| 50 core.WRITE_MESSAGE_FLAG_NONE); | 54 core.WRITE_MESSAGE_FLAG_NONE); |
| 51 switch (result) { | 55 switch (result) { |
| 52 case core.RESULT_OK: | 56 case core.RESULT_OK: |
| 53 // The handles were successfully transferred, so we don't own them | 57 // The handles were successfully transferred, so we don't own them |
| 54 // anymore. | 58 // anymore. |
| 55 message.handles = []; | 59 message.handles = []; |
| 56 break; | 60 break; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 var wait = core.wait(this.handle_, core.HANDLE_SIGNAL_READABLE, | 121 var wait = core.wait(this.handle_, core.HANDLE_SIGNAL_READABLE, |
| 118 core.DEADLINE_INDEFINITE); | 122 core.DEADLINE_INDEFINITE); |
| 119 this.readMore_(wait.result); | 123 this.readMore_(wait.result); |
| 120 } | 124 } |
| 121 | 125 |
| 122 var exports = {}; | 126 var exports = {}; |
| 123 exports.Connector = Connector; | 127 exports.Connector = Connector; |
| 124 exports.TestConnector = TestConnector; | 128 exports.TestConnector = TestConnector; |
| 125 return exports; | 129 return exports; |
| 126 }); | 130 }); |
| OLD | NEW |