2 * Copyright (c) 2015, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of JANET(UK) nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 * OF THE POSSIBILITY OF SUCH DAMAGE.
35 var tabs = require("sdk/tabs");
36 const {Cu} = require("chrome");
38 Cu.import("resource://gre/modules/ctypes.jsm");
41 // TODO: detect which OS we're running, and proactively search for the
42 // correct library name.
45 json_gssapi = ctypes.open("libjsongssapi.so");
49 json_gssapi = ctypes.open("jsongssapi.dll");
52 console.log("Error loading the JSON GSS-API library: " + e);
56 var gss_request = function(msg) { return "{\"error_message\":\"JSON GSS-API library was not loaded properly\"}"; }
58 gss_request = json_gssapi.declare("gss_request",
64 console.log("Could not find the function 'gss_request' in the JSON GSS-API library: " + e);
67 var self = require("sdk/self");
68 var data = require("sdk/self").data;
69 var pageMod = require("sdk/page-mod");
73 contentScriptFile: [data.url("contentscript.js")],
74 contentScriptWhen: "ready"
79 function invokeNativeGSS(msg)
85 // Deal with the cookies in the message
86 if ( typeof(msg.cookies) == 'undefined')
90 appTag = msg.cookies.app_tag;
92 // Send the message to the NativePort / command line
94 '[' + appTag + '] About to invoke native function: [' +
95 JSON.stringify(msg) + ']'
97 reply = gss_request( JSON.stringify(msg) );
98 response = JSON.parse(reply.readString() );
99 console.info('[' + appTag + '] ... native function invoked.');
100 console.info('[' + appTag + '] ... returned: ' + response);
105 tabs.on("ready", function(tab) {
106 app = tab.attach({ contentScriptFile: data.url("contentscript.js") });
107 app.port.on("gss_request", function(message) {
108 var response = invokeNativeGSS(message);
109 app.port.emit("gss_response", response);