9233aa560c3696bd288439377e390820cd8ee1f4
[gssweb.git] / chrome / app / gssweb_background.js
1 console.log("gssweb_background.js loading: #4");
2
3
4
5
6 var gssNativePort = null;
7 var applicationPort = null;
8
9 /* What to do with the output of the GSS command line */
10 function onGSSResponse(msg) {
11   console.info('Response from GSS command line: [' + 
12                JSON.stringify(msg) + ']'
13               );
14   
15   // Send the message on to the content script
16   applicationPort.postMessage(msg);
17   console.info('Response sent to the content script.');
18 }
19
20 function connectToNativeHost() {
21   console.info('Connecting to json_gssapi command line.');
22   // var host = 'com.google.chrome.example.echo';
23   var host = 'com.painlesssecurity.jsongss';
24   gssNativePort = chrome.runtime.connectNative( host );
25   gssNativePort.onMessage.addListener( onGSSResponse );
26 }
27
28
29 connectToNativeHost();
30
31 // When we receive a connection from a page through the content script...
32 chrome.runtime.onConnect.addListener(
33   function(thePort) 
34   {
35     // ... First, make sure that we're talking to the right people
36     console.assert(thePort.name == "com.painlesssecurity.gssweb");
37
38     // ... Second, save out the port
39     applicationPort = thePort;
40     
41     applicationPort.onMessage.addListener(
42       // Now, when we receive a message
43       function(msg)
44       {
45         console.info(
46           'About to send message to Native Port: [' +
47           JSON.stringify(msg) + ']'
48         );
49         gssNativePort.postMessage(msg);
50         console.info('... message sent to Native Port.')
51         
52       }
53     );
54   }
55 );
56