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 12 matching lines...) Expand all Loading... |
23 }; | 23 }; |
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 this.callback_.bind(this, getNumberAttr(message, 'connectionId'))); | 35 'data': getArrayAttr(message, 'data') |
| 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 }); |
| 56 } catch (err) { |
| 57 console.error('gnubby callback failed: ', /** @type {*} */ (err)); |
| 58 this.clientSession_.sendGnubbyAuthMessage({ |
| 59 'type': 'error', |
| 60 'connectionId': connectionId |
| 61 }); |
| 62 return; |
| 63 } |
53 }; | 64 }; |
54 | 65 |
55 /** | 66 /** |
56 * Send data to the gnubbyd extension. | 67 * Send data to the gnubbyd extension. |
57 * @param {Object} jsonObject The JSON object to send to the gnubbyd extension. | 68 * @param {Object} jsonObject The JSON object to send to the gnubbyd extension. |
58 * @param {function(Object)} callback The callback to invoke with reply data. | 69 * @param {function(Object)} callback The callback to invoke with reply data. |
59 * @private | 70 * @private |
60 */ | 71 */ |
61 remoting.GnubbyAuthHandler.prototype.sendMessageToGnubbyd_ = | 72 remoting.GnubbyAuthHandler.prototype.sendMessageToGnubbyd_ = |
62 function(jsonObject, callback) { | 73 function(jsonObject, callback) { |
(...skipping 16 matching lines...) Expand all Loading... |
79 * @private | 90 * @private |
80 */ | 91 */ |
81 function onGnubbydDevReply_(jsonObject, callback, reply) { | 92 function onGnubbydDevReply_(jsonObject, callback, reply) { |
82 var kGnubbydStableExtensionId = 'beknehfpfkghjoafdifaflglpjkojoco'; | 93 var kGnubbydStableExtensionId = 'beknehfpfkghjoafdifaflglpjkojoco'; |
83 | 94 |
84 if (reply) { | 95 if (reply) { |
85 callback(reply); | 96 callback(reply); |
86 } else { | 97 } else { |
87 chrome.runtime.sendMessage(kGnubbydStableExtensionId, jsonObject, callback); | 98 chrome.runtime.sendMessage(kGnubbydStableExtensionId, jsonObject, callback); |
88 } | 99 } |
89 }; | 100 } |
OLD | NEW |