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 |
11 'use strict'; | 11 'use strict'; |
12 | 12 |
13 /** @suppress {duplicate} */ | 13 /** @suppress {duplicate} */ |
14 var remoting = remoting || {}; | 14 var remoting = remoting || {}; |
15 | 15 |
16 /** | 16 /** |
17 * @constructor | 17 * @constructor |
18 * @implements {remoting.ProtocolExtension} | 18 * @implements {remoting.ProtocolExtension} |
19 */ | 19 */ |
20 remoting.GnubbyAuthHandler = function() { | 20 remoting.GnubbyAuthHandler = function() { |
21 /** @private {?function(string,string)} */ | 21 /** @private {?function(string,string)} */ |
22 this.sendMessageToHostCallback_ = null; | 22 this.sendMessageToHostCallback_ = null; |
23 }; | 23 }; |
24 | 24 |
25 /** @return {string} */ | 25 /** @private {string} */ |
26 remoting.GnubbyAuthHandler.prototype.getType = function() { | 26 remoting.GnubbyAuthHandler.EXTENSION_TYPE = 'gnubby-auth'; |
27 return 'gnubby-auth'; | 27 |
| 28 /** @return {Array<string>} */ |
| 29 remoting.GnubbyAuthHandler.prototype.getExtensionTypes = function() { |
| 30 return [remoting.GnubbyAuthHandler.EXTENSION_TYPE]; |
28 }; | 31 }; |
29 | 32 |
30 /** | 33 /** |
31 * @param {function(string,string)} sendMessageToHost Callback to send a message | 34 * @param {function(string,string)} sendMessageToHost Callback to send a message |
32 * to the host. | 35 * to the host. |
33 */ | 36 */ |
34 remoting.GnubbyAuthHandler.prototype.start = function(sendMessageToHost) { | 37 remoting.GnubbyAuthHandler.prototype.startExtension = |
| 38 function(sendMessageToHost) { |
35 this.sendMessageToHostCallback_ = sendMessageToHost; | 39 this.sendMessageToHostCallback_ = sendMessageToHost; |
36 | 40 |
37 this.sendMessageToHost_({ | 41 this.sendMessageToHost_({ |
38 'type': 'control', | 42 'type': 'control', |
39 'option': 'auth-v1' | 43 'option': 'auth-v1' |
40 }); | 44 }); |
41 }; | 45 }; |
42 | 46 |
43 /** | 47 /** |
44 * @param {Object} data The data to send. | 48 * @param {Object} data The data to send. |
45 * @private | 49 * @private |
46 */ | 50 */ |
47 remoting.GnubbyAuthHandler.prototype.sendMessageToHost_ = function(data) { | 51 remoting.GnubbyAuthHandler.prototype.sendMessageToHost_ = function(data) { |
48 this.sendMessageToHostCallback_(this.getType(), JSON.stringify(data)); | 52 this.sendMessageToHostCallback_(remoting.GnubbyAuthHandler.EXTENSION_TYPE, |
| 53 JSON.stringify(data)); |
49 } | 54 } |
50 | 55 |
51 /** | 56 /** |
52 * Processes gnubby-auth messages. | 57 * Processes gnubby-auth messages. |
53 * @param {string} data The gnubby-auth message data. | 58 * |
| 59 * @param {string} type The message type. |
| 60 * @param {Object} message The parsed extension message data. |
| 61 * @return {boolean} True if the extension message was handled. |
54 */ | 62 */ |
55 remoting.GnubbyAuthHandler.prototype.onMessage = function(data) { | 63 remoting.GnubbyAuthHandler.prototype.onExtensionMessage = |
56 var message = getJsonObjectFromString(data); | 64 function(type, message) { |
57 var messageType = getStringAttr(message, 'type'); | 65 var messageType = getStringAttr(message, 'type'); |
58 if (messageType == 'data') { | 66 if (messageType == 'data') { |
59 this.sendMessageToGnubbyd_({ | 67 this.sendMessageToGnubbyd_({ |
60 'type': 'auth-agent@openssh.com', | 68 'type': 'auth-agent@openssh.com', |
61 'data': getArrayAttr(message, 'data') | 69 'data': getArrayAttr(message, 'data') |
62 }, this.callback_.bind(this, getNumberAttr(message, 'connectionId'))); | 70 }, this.callback_.bind(this, getNumberAttr(message, 'connectionId'))); |
63 } else { | 71 } else { |
64 console.error('Invalid gnubby-auth message: ' + messageType); | 72 console.error('Invalid gnubby-auth message: ' + messageType); |
| 73 return false; |
65 } | 74 } |
| 75 return true; |
66 }; | 76 }; |
67 | 77 |
68 /** | 78 /** |
69 * Callback invoked with data to be returned to the host. | 79 * Callback invoked with data to be returned to the host. |
70 * @param {number} connectionId The connection id. | 80 * @param {number} connectionId The connection id. |
71 * @param {Object} response The JSON response with the data to send to the host. | 81 * @param {Object} response The JSON response with the data to send to the host. |
72 * @private | 82 * @private |
73 */ | 83 */ |
74 remoting.GnubbyAuthHandler.prototype.callback_ = | 84 remoting.GnubbyAuthHandler.prototype.callback_ = |
75 function(connectionId, response) { | 85 function(connectionId, response) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 */ | 127 */ |
118 function onGnubbydDevReply_(jsonObject, callback, reply) { | 128 function onGnubbydDevReply_(jsonObject, callback, reply) { |
119 var kGnubbydStableExtensionId = 'beknehfpfkghjoafdifaflglpjkojoco'; | 129 var kGnubbydStableExtensionId = 'beknehfpfkghjoafdifaflglpjkojoco'; |
120 | 130 |
121 if (reply) { | 131 if (reply) { |
122 callback(reply); | 132 callback(reply); |
123 } else { | 133 } else { |
124 chrome.runtime.sendMessage(kGnubbydStableExtensionId, jsonObject, callback); | 134 chrome.runtime.sendMessage(kGnubbydStableExtensionId, jsonObject, callback); |
125 } | 135 } |
126 } | 136 } |
OLD | NEW |