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

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

Issue 15623002: Don't serialize config dictionary in Native Messaging interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 7 years, 7 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
« no previous file with comments | « remoting/webapp/host_controller.js ('k') | remoting/webapp/host_native_messaging.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 * This class provides an interface between the HostController and either the 7 * This class provides an interface between the HostController and either the
8 * NativeMessaging Host or the Host NPAPI plugin, depending on whether 8 * NativeMessaging Host or the Host NPAPI plugin, depending on whether
9 * NativeMessaging is supported. Since the test for NativeMessaging support is 9 * NativeMessaging is supported. Since the test for NativeMessaging support is
10 * asynchronous, this class stores any requests on a queue, pending the result 10 * asynchronous, this class stores any requests on a queue, pending the result
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 case remoting.HostDispatcher.State.NATIVE_MESSAGING: 121 case remoting.HostDispatcher.State.NATIVE_MESSAGING:
122 this.nativeMessagingHost_.generateKeyPair(callback); 122 this.nativeMessagingHost_.generateKeyPair(callback);
123 break; 123 break;
124 case remoting.HostDispatcher.State.NPAPI: 124 case remoting.HostDispatcher.State.NPAPI:
125 this.npapiHost_.generateKeyPair(callback); 125 this.npapiHost_.generateKeyPair(callback);
126 break; 126 break;
127 } 127 }
128 }; 128 };
129 129
130 /** 130 /**
131 * @param {string} config 131 * @param {Object} config
132 * @param {function(remoting.HostController.AsyncResult):void} callback 132 * @param {function(remoting.HostController.AsyncResult):void} callback
133 * @return {void} 133 * @return {void}
134 */ 134 */
135 remoting.HostDispatcher.prototype.updateDaemonConfig = function(config, 135 remoting.HostDispatcher.prototype.updateDaemonConfig = function(config,
136 callback) { 136 callback) {
137 switch (this.state_) { 137 switch (this.state_) {
138 case remoting.HostDispatcher.State.UNKNOWN: 138 case remoting.HostDispatcher.State.UNKNOWN:
139 this.pendingRequests_.push(this.updateDaemonConfig.bind(this, callback)); 139 this.pendingRequests_.push(this.updateDaemonConfig.bind(this, callback));
140 break; 140 break;
141 case remoting.HostDispatcher.State.NATIVE_MESSAGING: 141 case remoting.HostDispatcher.State.NATIVE_MESSAGING:
142 this.nativeMessagingHost_.updateDaemonConfig(config, callback); 142 this.nativeMessagingHost_.updateDaemonConfig(config, callback);
143 break; 143 break;
144 case remoting.HostDispatcher.State.NPAPI: 144 case remoting.HostDispatcher.State.NPAPI:
145 this.npapiHost_.updateDaemonConfig(config, callback); 145 this.npapiHost_.updateDaemonConfig(JSON.stringify(config), callback);
146 break; 146 break;
147 } 147 }
148
149 }; 148 };
150 149
151 /** 150 /**
152 * @param {function(string):void} callback 151 * @param {function(Object):void} callback
153 * @return {void} 152 * @return {void}
154 */ 153 */
155 remoting.HostDispatcher.prototype.getDaemonConfig = function(callback) { 154 remoting.HostDispatcher.prototype.getDaemonConfig = function(callback) {
155 /**
156 * Converts the config string from the NPAPI plugin to an Object, to pass to
157 * |callback|.
158 * @param {string} configStr
159 * @return {void}
160 */
161 function callbackForNpapi(configStr) {
162 var config = null;
163 try {
164 config = JSON.parse(configStr);
165 } catch (err) {}
166 if (typeof(config) != 'object') {
167 // TODO(lambroslambrou): Call error handler here when that's implemented.
168 config = null;
169 }
170 callback(/** @type {Object} */ (config));
171 }
172
156 switch (this.state_) { 173 switch (this.state_) {
157 case remoting.HostDispatcher.State.UNKNOWN: 174 case remoting.HostDispatcher.State.UNKNOWN:
158 this.pendingRequests_.push(this.getDaemonConfig.bind(this, callback)); 175 this.pendingRequests_.push(this.getDaemonConfig.bind(this, callback));
159 break; 176 break;
160 case remoting.HostDispatcher.State.NATIVE_MESSAGING: 177 case remoting.HostDispatcher.State.NATIVE_MESSAGING:
161 this.nativeMessagingHost_.getDaemonConfig(callback); 178 this.nativeMessagingHost_.getDaemonConfig(callback);
162 break; 179 break;
163 case remoting.HostDispatcher.State.NPAPI: 180 case remoting.HostDispatcher.State.NPAPI:
164 this.npapiHost_.getDaemonConfig(callback); 181 this.npapiHost_.getDaemonConfig(callbackForNpapi);
165 break; 182 break;
166 } 183 }
167 }; 184 };
168 185
169 /** 186 /**
170 * @param {function(string):void} callback 187 * @param {function(string):void} callback
171 * @return {void} 188 * @return {void}
172 */ 189 */
173 remoting.HostDispatcher.prototype.getDaemonVersion = function(callback) { 190 remoting.HostDispatcher.prototype.getDaemonVersion = function(callback) {
174 switch (this.state_) { 191 switch (this.state_) {
(...skipping 22 matching lines...) Expand all
197 case remoting.HostDispatcher.State.NATIVE_MESSAGING: 214 case remoting.HostDispatcher.State.NATIVE_MESSAGING:
198 this.nativeMessagingHost_.getUsageStatsConsent(callback); 215 this.nativeMessagingHost_.getUsageStatsConsent(callback);
199 break; 216 break;
200 case remoting.HostDispatcher.State.NPAPI: 217 case remoting.HostDispatcher.State.NPAPI:
201 this.npapiHost_.getUsageStatsConsent(callback); 218 this.npapiHost_.getUsageStatsConsent(callback);
202 break; 219 break;
203 } 220 }
204 }; 221 };
205 222
206 /** 223 /**
207 * @param {string} config 224 * @param {Object} config
208 * @param {boolean} consent 225 * @param {boolean} consent
209 * @param {function(remoting.HostController.AsyncResult):void} callback 226 * @param {function(remoting.HostController.AsyncResult):void} callback
210 * @return {void} 227 * @return {void}
211 */ 228 */
212 remoting.HostDispatcher.prototype.startDaemon = function(config, consent, 229 remoting.HostDispatcher.prototype.startDaemon = function(config, consent,
213 callback) { 230 callback) {
214 switch (this.state_) { 231 switch (this.state_) {
215 case remoting.HostDispatcher.State.UNKNOWN: 232 case remoting.HostDispatcher.State.UNKNOWN:
216 this.pendingRequests_.push(this.startDaemon.bind(this, config, consent, 233 this.pendingRequests_.push(this.startDaemon.bind(this, config, consent,
217 callback)); 234 callback));
218 break; 235 break;
219 case remoting.HostDispatcher.State.NATIVE_MESSAGING: 236 case remoting.HostDispatcher.State.NATIVE_MESSAGING:
220 this.nativeMessagingHost_.startDaemon(config, consent, callback); 237 this.nativeMessagingHost_.startDaemon(config, consent, callback);
221 break; 238 break;
222 case remoting.HostDispatcher.State.NPAPI: 239 case remoting.HostDispatcher.State.NPAPI:
223 this.npapiHost_.startDaemon(config, consent, callback); 240 this.npapiHost_.startDaemon(JSON.stringify(config), consent, callback);
224 break; 241 break;
225 } 242 }
226 }; 243 };
227 244
228 /** 245 /**
229 * @param {function(remoting.HostController.AsyncResult):void} callback 246 * @param {function(remoting.HostController.AsyncResult):void} callback
230 * @return {void} 247 * @return {void}
231 */ 248 */
232 remoting.HostDispatcher.prototype.stopDaemon = function(callback) { 249 remoting.HostDispatcher.prototype.stopDaemon = function(callback) {
233 switch (this.state_) { 250 switch (this.state_) {
(...skipping 27 matching lines...) Expand all
261 var state = this.npapiHost_.daemonState; 278 var state = this.npapiHost_.daemonState;
262 if (state === undefined) { 279 if (state === undefined) {
263 // If the plug-in can't be instantiated, for example on ChromeOS, then 280 // If the plug-in can't be instantiated, for example on ChromeOS, then
264 // return something sensible. 281 // return something sensible.
265 state = remoting.HostController.State.NOT_IMPLEMENTED; 282 state = remoting.HostController.State.NOT_IMPLEMENTED;
266 } 283 }
267 callback(state); 284 callback(state);
268 break; 285 break;
269 } 286 }
270 } 287 }
OLDNEW
« no previous file with comments | « remoting/webapp/host_controller.js ('k') | remoting/webapp/host_native_messaging.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698