1 console.log("gssweb_background.js loading: #4");
5 var gssNativePort = null;
6 var applicationPorts = {};
8 /* What to do with the output of the GSS command line */
9 function onGSSResponse(msg) {
14 // Read the cookies out of the response
15 if ( typeof(msg.cookies) == 'undefined' ||
16 typeof(msg.cookies.gssweb_bg_tag) == 'undefined' )
19 "gssweb_background.js received a response from the command-line NativeHost with no gssweb_bg_tag cookie."
23 appTag = msg.cookies.app_tag;
24 nonce = msg.cookies.gssweb_bg_tag;
25 msg.cookies.gssweb_bg_tag = undefined;
27 // Informationally log
28 console.info('[' + appTag + '] Response from GSS command line: [' +
29 JSON.stringify(msg) + ']'
32 // Find the content script's port that should receive this message
33 appPort = applicationPorts[nonce]
34 applicationPorts[nonce] = undefined;
35 if ( typeof(appPort) == "undefined")
38 "[" + appTag + "] gssweb_background.js received a response from the command-line NativeHost with no associated application port."
42 // appPort is now guaranteed to exist.
45 // Send the message on to the content script
46 appPort.postMessage(msg);
48 console.info('[' + appTag + '] Response sent to the content script.');
51 function connectToNativeHost() {
52 console.info('Connecting to json_gssapi command line.');
53 // var host = 'com.google.chrome.example.echo';
54 var host = 'com.painlesssecurity.jsongss';
55 gssNativePort = chrome.runtime.connectNative( host );
56 gssNativePort.onMessage.addListener( onGSSResponse );
60 connectToNativeHost();
62 // When we receive a connection from a page through the content script...
63 chrome.runtime.onConnect.addListener(
66 // ... First, make sure that we're talking to the right people
67 console.assert(appPort.name == "com.painlesssecurity.gssweb");
69 appPort.onMessage.addListener(
70 // Now, when we receive a message
76 // Deal with the cookies in the message
77 if ( typeof(msg.cookies) == 'undefined')
81 appTag = msg.cookies.app_tag;
84 nonce = navigator.generateNonce();
85 applicationPorts[nonce] = appPort;
86 msg.cookies.gssweb_bg_tag = nonce;
88 // Send the message to the NativePort / command line
90 '[' + appTag + '] About to send message to Native Port: [' +
91 JSON.stringify(msg) + ']'
93 gssNativePort.postMessage(msg);
94 console.info('[' + appTag + '] ... message sent to Native Port.')