| 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/connector", [ | 5 define("mojo/public/js/bindings/connector", [ |
| 6 "mojo/public/js/bindings/codec", | 6 "mojo/public/js/bindings/codec", |
| 7 "mojo/public/js/bindings/core", | 7 "mojo/public/js/bindings/core", |
| 8 "mojo/public/js/bindings/support", | 8 "mojo/public/js/bindings/support", |
| 9 ], function(codec, core, support) { | 9 ], function(codec, core, support) { |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 if (this.readWaitCookie_) { | 23 if (this.readWaitCookie_) { |
| 24 support.cancelWait(this.readWaitCookie_); | 24 support.cancelWait(this.readWaitCookie_); |
| 25 this.readWaitCookie_ = null; | 25 this.readWaitCookie_ = null; |
| 26 } | 26 } |
| 27 if (this.handle_ != core.kInvalidHandle) { | 27 if (this.handle_ != core.kInvalidHandle) { |
| 28 core.close(this.handle_); | 28 core.close(this.handle_); |
| 29 this.handle_ = core.kInvalidHandle; | 29 this.handle_ = core.kInvalidHandle; |
| 30 } | 30 } |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 // For IPC fuzzing/testing. |
| 34 Connector.prototype.setFuzzer = function(fuzzer) { |
| 35 this.fuzzer_ = fuzzer; |
| 36 } |
| 37 |
| 33 Connector.prototype.accept = function(message) { | 38 Connector.prototype.accept = function(message) { |
| 34 if (this.error_) | 39 if (this.error_) |
| 35 return false; | 40 return false; |
| 36 | 41 |
| 37 if (this.dropWrites_) | 42 if (this.dropWrites_) |
| 38 return true; | 43 return true; |
| 39 | 44 |
| 45 if (this.fuzzer_) { |
| 46 this.fuzzer_(message); |
| 47 } |
| 48 |
| 40 var result = core.writeMessage(this.handle_, | 49 var result = core.writeMessage(this.handle_, |
| 41 new Uint8Array(message.buffer.arrayBuffer), | 50 new Uint8Array(message.buffer.arrayBuffer), |
| 42 message.handles, | 51 message.handles, |
| 43 core.WRITE_MESSAGE_FLAG_NONE); | 52 core.WRITE_MESSAGE_FLAG_NONE); |
| 44 switch (result) { | 53 switch (result) { |
| 45 case core.RESULT_OK: | 54 case core.RESULT_OK: |
| 46 // The handles were successfully transferred, so we don't own them | 55 // The handles were successfully transferred, so we don't own them |
| 47 // anymore. | 56 // anymore. |
| 48 message.handles = []; | 57 message.handles = []; |
| 49 break; | 58 break; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 if (this.incomingReceiver_) { | 109 if (this.incomingReceiver_) { |
| 101 this.incomingReceiver_.accept(message); | 110 this.incomingReceiver_.accept(message); |
| 102 } | 111 } |
| 103 } | 112 } |
| 104 }; | 113 }; |
| 105 | 114 |
| 106 var exports = {}; | 115 var exports = {}; |
| 107 exports.Connector = Connector; | 116 exports.Connector = Connector; |
| 108 return exports; | 117 return exports; |
| 109 }); | 118 }); |
| OLD | NEW |