});
+var msg = {
+ 'method': 'gss_import_name',
+ 'arguments': {
+ 'input_name': 'HTTP@localhost',
+ 'input_name_type': "{1 2 840 113554 1 2 1 4 }"
+ },
+ 'cookies': {
+ 'app_tag': 'Test request'
+ }
+};
+self.port.on('gss_response', function(message) {
+ console.log("Content script received a reply from gss_import_name: " + JSON.stringify(message) );
+});
+self.port.emit("gss_request", msg);
console.log(" ... loaded.");
console.log("Declaring the call_gss function:");
-const call_gss = json_gssapi.declare("gss_request",
+const gss_request = json_gssapi.declare("gss_request",
ctypes.default_abi,
ctypes.char.ptr,
ctypes.char.ptr);
console.log(" ... declared.");
+/*
console.log("Calling import_name");
var reply;
reply = call_gss("{\"method\":\"gss_import_name\",\"arguments\":{\"input_name\":\"HTTP@localhost\",\"input_name_type\":\"{1 2 840 113554 1 2 1 4 }\"}}");
console.log(" ... Reply: " + reply.readString());
+*/
var self = require("sdk/self");
contentScriptWhen: "ready"
});
-tabs.on("ready", function(tab) {
- worker = tab.attach({ contentScriptFile: data.url("navigator.gss.js") });
- worker.port.on("gss_request", function(message) {
- console.log("main.js received message: " + message);
- });
- worker.port.emit("alert", "Message from the add-on");
-});
-/*var gssweb = {
- myListener: function(evt) {
- alert("Received from web page: " +
- evt.target.getAttribute("attribute1") + "/" +
- evt.target.getAttribute("attribute2"));
+function invokeNativeGSS(msg)
+{
+ var appTag;
+ var reply;
+ var response;
+
+ // Deal with the cookies in the message
+ if ( typeof(msg.cookies) == 'undefined')
+ {
+ msg.cookies = {};
}
-}*/
-//document.addEventListener("GsswebEvent", function(e) { gssweb.myListener(e); }, false, true);
-// The last value is a Mozilla-specific value to indicate untrusted content is allowed to trigger the event.
+ appTag = msg.cookies.app_tag;
+
+ // Send the message to the NativePort / command line
+ console.info(
+ '[' + appTag + '] About to invoke native function: [' +
+ JSON.stringify(msg) + ']'
+ );
+ reply = gss_request( JSON.stringify(msg) );
+ response = JSON.parse(reply.readString() );
+ console.info('[' + appTag + '] ... native function invoked.');
+ console.info('[' + appTag + '] ... returned: ' + response);
+
+ return(response);
+}
+tabs.on("ready", function(tab) {
+ app = tab.attach({ contentScriptFile: data.url("navigator.gss.js") });
+ app.port.on("gss_request", function(message) {
+ var response = invokeNativeGSS(message);
+ app.port.emit("gss_response", response);
+ });
+});