1 var tabs = require("sdk/tabs");
2 const {Cu} = require("chrome");
4 Cu.import("resource://gre/modules/ctypes.jsm");
7 // TODO: detect which OS we're running, and proactively search for the
8 // correct library name.
11 json_gssapi = ctypes.open("libjsongssapi.so");
15 json_gssapi = ctypes.open("jsongssapi.dll");
18 console.log("Error loading the JSON GSS-API library: " + e);
22 var gss_request = function(msg) { return "{\"error_message\":\"JSON GSS-API library was not loaded properly\"}"; }
24 gss_request = json_gssapi.declare("gss_request",
30 console.log("Could not find the function 'gss_request' in the JSON GSS-API library: " + e);
33 var self = require("sdk/self");
34 var data = require("sdk/self").data;
35 var pageMod = require("sdk/page-mod");
39 contentScriptFile: [data.url("gssweb.contentscript.js")],
40 contentScriptWhen: "ready"
45 function invokeNativeGSS(msg)
51 // Deal with the cookies in the message
52 if ( typeof(msg.cookies) == 'undefined')
56 appTag = msg.cookies.app_tag;
58 // Send the message to the NativePort / command line
60 '[' + appTag + '] About to invoke native function: [' +
61 JSON.stringify(msg) + ']'
63 reply = gss_request( JSON.stringify(msg) );
64 response = JSON.parse(reply.readString() );
65 console.info('[' + appTag + '] ... native function invoked.');
66 console.info('[' + appTag + '] ... returned: ' + response);
71 tabs.on("ready", function(tab) {
72 app = tab.attach({ contentScriptFile: data.url("gssweb.contentscript.js") });
73 app.port.on("gss_request", function(message) {
74 var response = invokeNativeGSS(message);
75 app.port.emit("gss_response", response);