| 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 /** |    5 /** | 
|    6  * @fileoverview |    6  * @fileoverview | 
|    7  * Class to communicate with the host daemon via Native Messaging. |    7  * Class to communicate with the host daemon via Native Messaging. | 
|    8  */ |    8  */ | 
|    9  |    9  | 
|   10 'use strict'; |   10 'use strict'; | 
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  192     return; |  192     return; | 
|  193   } |  193   } | 
|  194   var reply = this.pendingReplies_[id]; |  194   var reply = this.pendingReplies_[id]; | 
|  195   if (!reply) { |  195   if (!reply) { | 
|  196     console.error('NativeMessaging: unexpected id: ', id); |  196     console.error('NativeMessaging: unexpected id: ', id); | 
|  197     return; |  197     return; | 
|  198   } |  198   } | 
|  199   delete this.pendingReplies_[id]; |  199   delete this.pendingReplies_[id]; | 
|  200  |  200  | 
|  201   try { |  201   try { | 
|  202     var type = getStringAttr(message, 'type'); |  202     var type = base.getStringAttr(message, 'type'); | 
|  203     if (type != reply.type) { |  203     if (type != reply.type) { | 
|  204       throw 'Expected reply type: ' + reply.type + ', got: ' + type; |  204       throw 'Expected reply type: ' + reply.type + ', got: ' + type; | 
|  205     } |  205     } | 
|  206  |  206  | 
|  207     this.handleIncomingMessage_(message, reply.onDone); |  207     this.handleIncomingMessage_(message, reply.onDone); | 
|  208   } catch (/** @type {*} */ e) { |  208   } catch (/** @type {*} */ e) { | 
|  209     console.error('Error while processing native message', e); |  209     console.error('Error while processing native message', e); | 
|  210     reply.onError(remoting.Error.unexpected()); |  210     reply.onError(remoting.Error.unexpected()); | 
|  211   } |  211   } | 
|  212 } |  212 } | 
|  213  |  213  | 
|  214 /** |  214 /** | 
|  215  * Handler for incoming Native Messages. |  215  * Handler for incoming Native Messages. | 
|  216  * |  216  * | 
|  217  * @param {Object} message The received message. |  217  * @param {Object} message The received message. | 
|  218  * @param {function(...):void} onDone Function to call when we're done |  218  * @param {function(...):void} onDone Function to call when we're done | 
|  219  *     processing the message. |  219  *     processing the message. | 
|  220  * @return {void} Nothing. |  220  * @return {void} Nothing. | 
|  221  * @private |  221  * @private | 
|  222  */ |  222  */ | 
|  223 remoting.HostDaemonFacade.prototype.handleIncomingMessage_ = |  223 remoting.HostDaemonFacade.prototype.handleIncomingMessage_ = | 
|  224     function(message, onDone) { |  224     function(message, onDone) { | 
|  225   var type = getStringAttr(message, 'type'); |  225   var type = base.getStringAttr(message, 'type'); | 
|  226  |  226  | 
|  227   switch (type) { |  227   switch (type) { | 
|  228     case 'helloResponse': |  228     case 'helloResponse': | 
|  229       this.version_ = getStringAttr(message, 'version'); |  229       this.version_ = base.getStringAttr(message, 'version'); | 
|  230       // Old versions of the native messaging host do not return this list. |  230       // Old versions of the native messaging host do not return this list. | 
|  231       // Those versions default to the empty list of supported features. |  231       // Those versions default to the empty list of supported features. | 
|  232       this.supportedFeatures_ = getArrayAttr(message, 'supportedFeatures', []); |  232       this.supportedFeatures_ = | 
 |  233           base.getArrayAttr(message, 'supportedFeatures', []); | 
|  233       onDone(); |  234       onDone(); | 
|  234       break; |  235       break; | 
|  235  |  236  | 
|  236     case 'getHostNameResponse': |  237     case 'getHostNameResponse': | 
|  237       onDone(getStringAttr(message, 'hostname')); |  238       onDone(base.getStringAttr(message, 'hostname')); | 
|  238       break; |  239       break; | 
|  239  |  240  | 
|  240     case 'getPinHashResponse': |  241     case 'getPinHashResponse': | 
|  241       onDone(getStringAttr(message, 'hash')); |  242       onDone(base.getStringAttr(message, 'hash')); | 
|  242       break; |  243       break; | 
|  243  |  244  | 
|  244     case 'generateKeyPairResponse': |  245     case 'generateKeyPairResponse': | 
|  245       var privateKey = getStringAttr(message, 'privateKey'); |  246       var privateKey = base.getStringAttr(message, 'privateKey'); | 
|  246       var publicKey = getStringAttr(message, 'publicKey'); |  247       var publicKey = base.getStringAttr(message, 'publicKey'); | 
|  247       onDone(privateKey, publicKey); |  248       onDone(privateKey, publicKey); | 
|  248       break; |  249       break; | 
|  249  |  250  | 
|  250     case 'updateDaemonConfigResponse': |  251     case 'updateDaemonConfigResponse': | 
|  251       var result = remoting.HostController.AsyncResult.fromString( |  252       var result = remoting.HostController.AsyncResult.fromString( | 
|  252           getStringAttr(message, 'result')); |  253           base.getStringAttr(message, 'result')); | 
|  253       onDone(result); |  254       onDone(result); | 
|  254       break; |  255       break; | 
|  255  |  256  | 
|  256     case 'getDaemonConfigResponse': |  257     case 'getDaemonConfigResponse': | 
|  257       onDone(getObjectAttr(message, 'config')); |  258       onDone(base.getObjectAttr(message, 'config')); | 
|  258       break; |  259       break; | 
|  259  |  260  | 
|  260     case 'getUsageStatsConsentResponse': |  261     case 'getUsageStatsConsentResponse': | 
|  261       var supported = getBooleanAttr(message, 'supported'); |  262       var supported = base.getBooleanAttr(message, 'supported'); | 
|  262       var allowed = getBooleanAttr(message, 'allowed'); |  263       var allowed = base.getBooleanAttr(message, 'allowed'); | 
|  263       var setByPolicy = getBooleanAttr(message, 'setByPolicy'); |  264       var setByPolicy = base.getBooleanAttr(message, 'setByPolicy'); | 
|  264       onDone(supported, allowed, setByPolicy); |  265       onDone(supported, allowed, setByPolicy); | 
|  265       break; |  266       break; | 
|  266  |  267  | 
|  267     case 'startDaemonResponse': |  268     case 'startDaemonResponse': | 
|  268     case 'stopDaemonResponse': |  269     case 'stopDaemonResponse': | 
|  269       var result = remoting.HostController.AsyncResult.fromString( |  270       var result = remoting.HostController.AsyncResult.fromString( | 
|  270           getStringAttr(message, 'result')); |  271           base.getStringAttr(message, 'result')); | 
|  271       onDone(result); |  272       onDone(result); | 
|  272       break; |  273       break; | 
|  273  |  274  | 
|  274     case 'getDaemonStateResponse': |  275     case 'getDaemonStateResponse': | 
|  275       var state = remoting.HostController.State.fromString( |  276       var state = remoting.HostController.State.fromString( | 
|  276         getStringAttr(message, 'state')); |  277         base.getStringAttr(message, 'state')); | 
|  277       onDone(state); |  278       onDone(state); | 
|  278       break; |  279       break; | 
|  279  |  280  | 
|  280     case 'getPairedClientsResponse': |  281     case 'getPairedClientsResponse': | 
|  281       var pairedClients = remoting.PairedClient.convertToPairedClientArray( |  282       var pairedClients = remoting.PairedClient.convertToPairedClientArray( | 
|  282           message['pairedClients']); |  283           message['pairedClients']); | 
|  283       if (pairedClients != null) { |  284       if (pairedClients != null) { | 
|  284         onDone(pairedClients); |  285         onDone(pairedClients); | 
|  285       } else { |  286       } else { | 
|  286         throw 'No paired clients!'; |  287         throw 'No paired clients!'; | 
|  287       } |  288       } | 
|  288       break; |  289       break; | 
|  289  |  290  | 
|  290     case 'clearPairedClientsResponse': |  291     case 'clearPairedClientsResponse': | 
|  291     case 'deletePairedClientResponse': |  292     case 'deletePairedClientResponse': | 
|  292       onDone(getBooleanAttr(message, 'result')); |  293       onDone(base.getBooleanAttr(message, 'result')); | 
|  293       break; |  294       break; | 
|  294  |  295  | 
|  295     case 'getHostClientIdResponse': |  296     case 'getHostClientIdResponse': | 
|  296       onDone(getStringAttr(message, 'clientId')); |  297       onDone(base.getStringAttr(message, 'clientId')); | 
|  297       break; |  298       break; | 
|  298  |  299  | 
|  299     case 'getCredentialsFromAuthCodeResponse': |  300     case 'getCredentialsFromAuthCodeResponse': | 
|  300       var userEmail = getStringAttr(message, 'userEmail'); |  301       var userEmail = base.getStringAttr(message, 'userEmail'); | 
|  301       var refreshToken = getStringAttr(message, 'refreshToken'); |  302       var refreshToken = base.getStringAttr(message, 'refreshToken'); | 
|  302       if (userEmail && refreshToken) { |  303       if (userEmail && refreshToken) { | 
|  303         onDone(userEmail, refreshToken); |  304         onDone(userEmail, refreshToken); | 
|  304       } else { |  305       } else { | 
|  305         throw 'Missing userEmail or refreshToken'; |  306         throw 'Missing userEmail or refreshToken'; | 
|  306       } |  307       } | 
|  307       break; |  308       break; | 
|  308  |  309  | 
|  309     default: |  310     default: | 
|  310       throw 'Unexpected native message: ' + message; |  311       throw 'Unexpected native message: ' + message; | 
|  311   } |  312   } | 
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  552  * @param {function(!remoting.Error):void} onError Callback to call on error. |  553  * @param {function(!remoting.Error):void} onError Callback to call on error. | 
|  553  * @return {void} Nothing. |  554  * @return {void} Nothing. | 
|  554  */ |  555  */ | 
|  555 remoting.HostDaemonFacade.prototype.getCredentialsFromAuthCode = |  556 remoting.HostDaemonFacade.prototype.getCredentialsFromAuthCode = | 
|  556     function(authorizationCode, onDone, onError) { |  557     function(authorizationCode, onDone, onError) { | 
|  557   this.postMessage_({ |  558   this.postMessage_({ | 
|  558     type: 'getCredentialsFromAuthCode', |  559     type: 'getCredentialsFromAuthCode', | 
|  559     authorizationCode: authorizationCode |  560     authorizationCode: authorizationCode | 
|  560   }, onDone, onError); |  561   }, onDone, onError); | 
|  561 }; |  562 }; | 
| OLD | NEW |