| 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 that routes gnubby-auth extension messages to and from the gnubbyd | 7 * Class that routes gnubby-auth extension messages to and from the gnubbyd |
| 8 * extension. | 8 * extension. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * Processes gnubby-auth messages. | 26 * Processes gnubby-auth messages. |
| 27 * @param {string} data The gnubby-auth message data. | 27 * @param {string} data The gnubby-auth message data. |
| 28 */ | 28 */ |
| 29 remoting.GnubbyAuthHandler.prototype.onMessage = function(data) { | 29 remoting.GnubbyAuthHandler.prototype.onMessage = function(data) { |
| 30 var message = getJsonObjectFromString(data); | 30 var message = getJsonObjectFromString(data); |
| 31 var messageType = getStringAttr(message, 'type'); | 31 var messageType = getStringAttr(message, 'type'); |
| 32 if (messageType == 'data') { | 32 if (messageType == 'data') { |
| 33 this.sendMessageToGnubbyd_( | 33 this.sendMessageToGnubbyd_( |
| 34 getJsonObjectFromString(getStringAttr(message, 'jsonMessage')), | 34 {'type': 'auth-agent@openssh.com', |
| 35 'data': getArrayAttr(message, 'data')}, |
| 35 this.callback_.bind(this, getNumberAttr(message, 'connectionId'))); | 36 this.callback_.bind(this, getNumberAttr(message, 'connectionId'))); |
| 36 } else { | 37 } else { |
| 37 console.error('Invalid gnubby-auth message: ' + messageType); | 38 console.error('Invalid gnubby-auth message: ' + messageType); |
| 38 } | 39 } |
| 39 }; | 40 }; |
| 40 | 41 |
| 41 /** | 42 /** |
| 42 * Callback invoked with data to be returned to the host. | 43 * Callback invoked with data to be returned to the host. |
| 43 * @param {number} connectionId The connection id. | 44 * @param {number} connectionId The connection id. |
| 44 * @param {Object} data The JSON object to send to the host. | 45 * @param {Object} response The JSON response with the data to send to the host. |
| 45 * @private | 46 * @private |
| 46 */ | 47 */ |
| 47 remoting.GnubbyAuthHandler.prototype.callback_ = | 48 remoting.GnubbyAuthHandler.prototype.callback_ = |
| 48 function(connectionId, data) { | 49 function(connectionId, response) { |
| 49 var json_data = JSON.stringify(data); | 50 try { |
| 50 this.clientSession_.sendGnubbyAuthMessage({'type': 'data', | 51 this.clientSession_.sendGnubbyAuthMessage({ |
| 51 'connectionId': connectionId, | 52 'type': 'data', |
| 52 'jsonMessage': json_data}); | 53 'connectionId': connectionId, |
| 54 'data': getArrayAttr(response, 'data')}); |
| 55 } catch (err) { |
| 56 console.error('gnubby callback failed: ', /** @type {*} */ (err)); |
| 57 this.clientSession_.sendGnubbyAuthMessage({'type': 'error', |
| 58 'connectionId': connectionId}); |
| 59 return; |
| 60 } |
| 53 }; | 61 }; |
| 54 | 62 |
| 55 /** | 63 /** |
| 56 * Send data to the gnubbyd extension. | 64 * Send data to the gnubbyd extension. |
| 57 * @param {Object} jsonObject The JSON object to send to the gnubbyd extension. | 65 * @param {Object} jsonObject The JSON object to send to the gnubbyd extension. |
| 58 * @param {function(Object)} callback The callback to invoke with reply data. | 66 * @param {function(Object)} callback The callback to invoke with reply data. |
| 59 * @private | 67 * @private |
| 60 */ | 68 */ |
| 61 remoting.GnubbyAuthHandler.prototype.sendMessageToGnubbyd_ = | 69 remoting.GnubbyAuthHandler.prototype.sendMessageToGnubbyd_ = |
| 62 function(jsonObject, callback) { | 70 function(jsonObject, callback) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 79 * @private | 87 * @private |
| 80 */ | 88 */ |
| 81 function onGnubbydDevReply_(jsonObject, callback, reply) { | 89 function onGnubbydDevReply_(jsonObject, callback, reply) { |
| 82 var kGnubbydStableExtensionId = 'beknehfpfkghjoafdifaflglpjkojoco'; | 90 var kGnubbydStableExtensionId = 'beknehfpfkghjoafdifaflglpjkojoco'; |
| 83 | 91 |
| 84 if (reply) { | 92 if (reply) { |
| 85 callback(reply); | 93 callback(reply); |
| 86 } else { | 94 } else { |
| 87 chrome.runtime.sendMessage(kGnubbydStableExtensionId, jsonObject, callback); | 95 chrome.runtime.sendMessage(kGnubbydStableExtensionId, jsonObject, callback); |
| 88 } | 96 } |
| 89 }; | 97 } |
| OLD | NEW |