Handle errors of garbled JSON sent to the native host
[gssweb.git] / firefox / lib / main.js
1 var tabs = require("sdk/tabs");
2 const {Cu} = require("chrome");
3
4 for (i = 0; i < 10; i++) {
5   console.log("");
6 }
7
8 console.log("About to load ctypes");
9 Cu.import("resource://gre/modules/ctypes.jsm");
10 console.log("  ... loaded.");
11
12 var json_gssapi;
13
14
15 // TODO: detect which OS we're running, and proactively search for the
16 //       correct library name.
17 console.log("About to load libjsongssapi");
18 try {
19     json_gssapi = ctypes.open("libjsongssapi.so");
20 }
21 catch (e) {
22     try {
23         json_gssapi = ctypes.open("libjsongssapi.dll");
24     }
25     catch (e) {
26         console.log("  ... " + e);
27     }
28 }
29 console.log("  ... loaded.");
30
31 console.log("Declaring the call_gss function:");
32 const call_gss = json_gssapi.declare("gss_request",
33     ctypes.default_abi,
34     ctypes.char.ptr,
35     ctypes.char.ptr);
36 console.log("  ... declared.");
37
38 console.log("Calling import_name");
39 var reply;
40 reply = call_gss("{\"method\":\"gss_import_name\",\"arguments\":{\"input_name\":\"HTTP@localhost\",\"input_name_type\":\"{1 2 840 113554 1 2 1 4 }\"}}");
41 console.log("  ... Reply: " + reply.readString());
42
43
44
45 var data = require("sdk/self").data;
46 var pageMod = require("sdk/page-mod");
47
48 pageMod.PageMod({
49   include: "*",
50   contentScriptFile: [data.url("navigator.gss.js")],
51   contentScriptWhen: "ready"
52 });