Version and install for library
[gssweb.git] / chrome / app / gssweb.js
1
2
3 var gssAppPort = null;
4
5 function report(msg) {
6   var response = document.getElementById('response');
7   response.innerHTML = '<p>' + msg + '</p>' + response.innerHTML;
8 }
9
10 function onGSSResponse(msg) {
11   report('Response from GSS: ' + JSON.stringify(msg) );
12 }
13
14 function connectToNativeHost() {
15   report('Connecting to json_gssapi command line.');
16   // var host = 'com.google.chrome.example.echo';
17   var host = 'com.painlesssecurity.jsongss'
18   gssAppPort = chrome.runtime.connectNative( host );
19   if (gssAppPort) {report("Connected.");};
20   gssAppPort.onMessage.addListener( onGSSResponse );
21 }
22
23 function sendNativeMessage() {
24   var msg = JSON.parse( document.getElementById('gss_command').value );
25   gssAppPort.postMessage(msg);
26   report('Sent message: ' + msg);
27 }
28
29
30 document.addEventListener('DOMContentLoaded', function () {
31   document.getElementById('connect').addEventListener(
32       'click', connectToNativeHost);
33   document.getElementById('send-message').addEventListener(
34       'click', sendNativeMessage);
35 });