| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * Class to communicate with the Host components via Native Messaging. | 7 * Class to communicate with the Host components via Native Messaging. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 'use strict'; | 10 'use strict'; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 } | 102 } |
| 103 | 103 |
| 104 /** | 104 /** |
| 105 * Returns |result| as an AsyncResult. If |result| is not valid, returns null | 105 * Returns |result| as an AsyncResult. If |result| is not valid, returns null |
| 106 * and logs an error. | 106 * and logs an error. |
| 107 * | 107 * |
| 108 * @param {*} result | 108 * @param {*} result |
| 109 * @return {remoting.HostController.AsyncResult?} Converted result. | 109 * @return {remoting.HostController.AsyncResult?} Converted result. |
| 110 */ | 110 */ |
| 111 function asAsyncResult_(result) { | 111 function asAsyncResult_(result) { |
| 112 if (!checkType_('result', result, 'number')) { | 112 if (!checkType_('result', result, 'string')) { |
| 113 return null; | 113 return null; |
| 114 } | 114 } |
| 115 for (var i in remoting.HostController.AsyncResult) { | 115 if (!remoting.HostController.AsyncResult.hasOwnProperty(result)) { |
| 116 if (remoting.HostController.AsyncResult[i] == result) { | 116 console.error('NativeMessaging: unexpected result code: ', result); |
| 117 return remoting.HostController.AsyncResult[i]; | 117 return null; |
| 118 } | |
| 119 } | 118 } |
| 120 console.error('NativeMessaging: unexpected result code: ', result); | 119 return remoting.HostController.AsyncResult[result]; |
| 121 return null; | |
| 122 } | 120 } |
| 123 | 121 |
| 124 /** | 122 /** |
| 125 * Returns |result| as a HostController.State. If |result| is not valid, | 123 * Returns |result| as a HostController.State. If |result| is not valid, |
| 126 * returns null and logs an error. | 124 * returns null and logs an error. |
| 127 * | 125 * |
| 128 * @param {*} result | 126 * @param {*} result |
| 129 * @return {remoting.HostController.State?} Converted result. | 127 * @return {remoting.HostController.State?} Converted result. |
| 130 */ | 128 */ |
| 131 function asHostState_(result) { | 129 function asHostState_(result) { |
| 132 if (!checkType_('result', result, 'number')) { | 130 if (!checkType_('result', result, 'string')) { |
| 133 return null; | 131 return null; |
| 134 } | 132 } |
| 135 for (var i in remoting.HostController.State) { | 133 if (!remoting.HostController.State.hasOwnProperty(result)) { |
| 136 if (remoting.HostController.State[i] == result) { | 134 console.error('NativeMessaging: unexpected result code: ', result); |
| 137 return remoting.HostController.State[i]; | 135 return null; |
| 138 } | |
| 139 } | 136 } |
| 140 console.error('NativeMessaging: unexpected result code: ', result); | 137 return remoting.HostController.State[result]; |
| 141 return null; | |
| 142 } | 138 } |
| 143 | 139 |
| 144 /** | 140 /** |
| 145 * Attaches a new ID to the supplied message, and posts it to the Native | 141 * Attaches a new ID to the supplied message, and posts it to the Native |
| 146 * Messaging port, adding |callback| to the list of pending replies. | 142 * Messaging port, adding |callback| to the list of pending replies. |
| 147 * |message| should have its 'type' field set, and any other fields set | 143 * |message| should have its 'type' field set, and any other fields set |
| 148 * depending on the message type. | 144 * depending on the message type. |
| 149 * | 145 * |
| 150 * @param {{type: string}} message The message to post. | 146 * @param {{type: string}} message The message to post. |
| 151 * @param {?function(...):void} callback The callback, if any, to be triggered | 147 * @param {?function(...):void} callback The callback, if any, to be triggered |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 | 449 |
| 454 /** | 450 /** |
| 455 * Gets the installed/running state of the Host process. | 451 * Gets the installed/running state of the Host process. |
| 456 * | 452 * |
| 457 * @param {function(remoting.HostController.State):void} callback Callback. | 453 * @param {function(remoting.HostController.State):void} callback Callback. |
| 458 * @return {void} Nothing. | 454 * @return {void} Nothing. |
| 459 */ | 455 */ |
| 460 remoting.HostNativeMessaging.prototype.getDaemonState = function(callback) { | 456 remoting.HostNativeMessaging.prototype.getDaemonState = function(callback) { |
| 461 this.postMessage_({type: 'getDaemonState'}, callback); | 457 this.postMessage_({type: 'getDaemonState'}, callback); |
| 462 } | 458 } |
| OLD | NEW |