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

Side by Side Diff: remoting/webapp/crd/js/it2me_host_facade.js

Issue 1015553003: Added more typechecking functions and unit tests for existing code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « remoting/webapp/crd/js/host_list_api_impl.js ('k') | remoting/webapp/crd/js/typecheck.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 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 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * Class to communicate with the It2me Host component via Native Messaging. 7 * Class to communicate with the It2me Host component via Native Messaging.
8 */ 8 */
9 9
10 /** @suppress {duplicate} */ 10 /** @suppress {duplicate} */
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 201
202 /** 202 /**
203 * Handler for incoming messages. 203 * Handler for incoming messages.
204 * 204 *
205 * @param {Object} message The received message. 205 * @param {Object} message The received message.
206 * @return {void} 206 * @return {void}
207 * @private 207 * @private
208 */ 208 */
209 remoting.It2MeHostFacade.prototype.onIncomingMessage_ = 209 remoting.It2MeHostFacade.prototype.onIncomingMessage_ =
210 function(message) { 210 function(message) {
211 var type = getStringAttr(message, 'type'); 211 var type = base.getStringAttr(message, 'type');
212 212
213 switch (type) { 213 switch (type) {
214 case 'helloResponse': 214 case 'helloResponse':
215 var version = getStringAttr(message, 'version'); 215 var version = base.getStringAttr(message, 'version');
216 console.log('Host version: ', version); 216 console.log('Host version: ', version);
217 this.initialized_ = true; 217 this.initialized_ = true;
218 // A "hello" request is sent immediately after the native messaging host 218 // A "hello" request is sent immediately after the native messaging host
219 // is started. We can proceed to the next task once we receive the 219 // is started. We can proceed to the next task once we receive the
220 // "helloReponse". 220 // "helloReponse".
221 if (this.onInitialized_) { 221 if (this.onInitialized_) {
222 this.onInitialized_(); 222 this.onInitialized_();
223 } 223 }
224 break; 224 break;
225 225
226 case 'connectResponse': 226 case 'connectResponse':
227 console.log('connectResponse received'); 227 console.log('connectResponse received');
228 // Response to the "connect" request. No action is needed until we 228 // Response to the "connect" request. No action is needed until we
229 // receive the corresponding "hostStateChanged" message. 229 // receive the corresponding "hostStateChanged" message.
230 break; 230 break;
231 231
232 case 'disconnectResponse': 232 case 'disconnectResponse':
233 console.log('disconnectResponse received'); 233 console.log('disconnectResponse received');
234 // Response to the "disconnect" request. No action is needed until we 234 // Response to the "disconnect" request. No action is needed until we
235 // receive the corresponding "hostStateChanged" message. 235 // receive the corresponding "hostStateChanged" message.
236 break; 236 break;
237 237
238 case 'hostStateChanged': 238 case 'hostStateChanged':
239 var stateString = getStringAttr(message, 'state'); 239 var stateString = base.getStringAttr(message, 'state');
240 console.log('hostStateChanged received: ', stateString); 240 console.log('hostStateChanged received: ', stateString);
241 var state = remoting.HostSession.State.fromString(stateString); 241 var state = remoting.HostSession.State.fromString(stateString);
242 242
243 switch (state) { 243 switch (state) {
244 case remoting.HostSession.State.RECEIVED_ACCESS_CODE: 244 case remoting.HostSession.State.RECEIVED_ACCESS_CODE:
245 var accessCode = getStringAttr(message, 'accessCode'); 245 var accessCode = base.getStringAttr(message, 'accessCode');
246 var accessCodeLifetime = getNumberAttr(message, 'accessCodeLifetime'); 246 var accessCodeLifetime =
247 base.getNumberAttr(message, 'accessCodeLifetime');
247 this.onReceivedAccessCode_(accessCode, accessCodeLifetime); 248 this.onReceivedAccessCode_(accessCode, accessCodeLifetime);
248 break; 249 break;
249 250
250 case remoting.HostSession.State.CONNECTED: 251 case remoting.HostSession.State.CONNECTED:
251 var client = getStringAttr(message, 'client'); 252 var client = base.getStringAttr(message, 'client');
252 this.onConnected_(client); 253 this.onConnected_(client);
253 break; 254 break;
254 } 255 }
255 if (this.onStateChanged_) { 256 if (this.onStateChanged_) {
256 this.onStateChanged_(state); 257 this.onStateChanged_(state);
257 } 258 }
258 break; 259 break;
259 260
260 case 'natPolicyChanged': 261 case 'natPolicyChanged':
261 if (this.onNatPolicyChanged_) { 262 if (this.onNatPolicyChanged_) {
262 var natTraversalEnabled = 263 var natTraversalEnabled =
263 getBooleanAttr(message, 'natTraversalEnabled'); 264 base.getBooleanAttr(message, 'natTraversalEnabled');
264 this.onNatPolicyChanged_(natTraversalEnabled); 265 this.onNatPolicyChanged_(natTraversalEnabled);
265 } 266 }
266 break; 267 break;
267 268
268 case 'error': 269 case 'error':
269 console.error(getStringAttr(message, 'description')); 270 console.error(base.getStringAttr(message, 'description'));
270 if (this.onError_) { 271 if (this.onError_) {
271 this.onError_(remoting.Error.unexpected()); 272 this.onError_(remoting.Error.unexpected());
272 } 273 }
273 break; 274 break;
274 275
275 default: 276 default:
276 throw 'Unexpected native message: ' + message; 277 throw 'Unexpected native message: ' + message;
277 } 278 }
278 }; 279 };
279 280
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 chrome.runtime.lastError.message); 315 chrome.runtime.lastError.message);
315 this.onInitializationFailed_(); 316 this.onInitializationFailed_();
316 } else { 317 } else {
317 console.error('Native Messaging port disconnected.'); 318 console.error('Native Messaging port disconnected.');
318 this.port_ = null; 319 this.port_ = null;
319 this.onError_(remoting.Error.unexpected()); 320 this.onError_(remoting.Error.unexpected());
320 } 321 }
321 }; 322 };
322 323
323 })(); 324 })();
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/host_list_api_impl.js ('k') | remoting/webapp/crd/js/typecheck.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698