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
3 // found in the LICENSE file.
7 * Class that routes gnubby-auth extension messages to and from the gnubbyd
13 /** @suppress {duplicate} */
14 var remoting
= remoting
|| {};
18 * @param {!remoting.ClientSession} clientSession The client session to send
19 * gnubby-auth response messages to.
21 remoting
.GnubbyAuthHandler = function(clientSession
) {
22 this.clientSession_
= clientSession
;
26 * Processes gnubby-auth messages.
27 * @param {string} data The gnubby-auth message data.
29 remoting
.GnubbyAuthHandler
.prototype.onMessage = function(data
) {
30 var message
= getJsonObjectFromString(data
);
31 var messageType
= getStringAttr(message
, 'type');
32 if (messageType
== 'data') {
33 this.sendMessageToGnubbyd_({
34 'type': 'auth-agent@openssh.com',
35 'data': getArrayAttr(message
, 'data')
36 }, this.callback_
.bind(this, getNumberAttr(message
, 'connectionId')));
38 console
.error('Invalid gnubby-auth message: ' + messageType
);
43 * Callback invoked with data to be returned to the host.
44 * @param {number} connectionId The connection id.
45 * @param {Object} response The JSON response with the data to send to the host.
48 remoting
.GnubbyAuthHandler
.prototype.callback_
=
49 function(connectionId
, response
) {
51 this.clientSession_
.sendGnubbyAuthMessage({
53 'connectionId': connectionId
,
54 'data': getArrayAttr(response
, 'data')
57 console
.error('gnubby callback failed: ', /** @type {*} */ (err
));
58 this.clientSession_
.sendGnubbyAuthMessage({
60 'connectionId': connectionId
67 * Send data to the gnubbyd extension.
68 * @param {Object} jsonObject The JSON object to send to the gnubbyd extension.
69 * @param {function(Object)} callback The callback to invoke with reply data.
72 remoting
.GnubbyAuthHandler
.prototype.sendMessageToGnubbyd_
=
73 function(jsonObject
, callback
) {
74 var kGnubbydDevExtensionId
= 'dlfcjilkjfhdnfiecknlnddkmmiofjbg';
76 chrome
.runtime
.sendMessage(
77 kGnubbydDevExtensionId
,
79 onGnubbydDevReply_
.bind(this, jsonObject
, callback
));
83 * Callback invoked as a result of sending a message to the gnubbyd-dev
84 * extension. If that extension is not installed, reply will be undefined;
85 * otherwise it will be the JSON response object.
86 * @param {Object} jsonObject The JSON object to send to the gnubbyd extension.
87 * @param {function(Object)} callback The callback to invoke with reply data.
88 * @param {Object} reply The reply from the extension (or Chrome, if the
89 * extension does not exist.
92 function onGnubbydDevReply_(jsonObject
, callback
, reply
) {
93 var kGnubbydStableExtensionId
= 'beknehfpfkghjoafdifaflglpjkojoco';
98 chrome
.runtime
.sendMessage(kGnubbydStableExtensionId
, jsonObject
, callback
);