Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: remoting/webapp/host_native_messaging.js

Issue 16236008: Send enums as strings between Chromoting Native Messaging host and web-app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move constants and fix loops Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 (result in remoting.HostController.AsyncResult) {
116 if (remoting.HostController.AsyncResult[i] == result) { 116 return remoting.HostController.AsyncResult[result];
Sergey Ulanov 2013/05/31 23:01:43 nit: I would swap this block and the error case at
Lambros 2013/06/03 21:28:44 Done.
117 return remoting.HostController.AsyncResult[i];
118 }
119 } 117 }
120 console.error('NativeMessaging: unexpected result code: ', result); 118 console.error('NativeMessaging: unexpected result code: ', result);
121 return null; 119 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 (result in remoting.HostController.State) {
136 if (remoting.HostController.State[i] == result) { 134 return remoting.HostController.State[result];
137 return remoting.HostController.State[i];
138 }
139 } 135 }
140 console.error('NativeMessaging: unexpected result code: ', result); 136 console.error('NativeMessaging: unexpected result code: ', result);
141 return null; 137 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.
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698