1 if(!dojo._hasResource["openils.XUL"]) {
3 dojo.provide("openils.XUL");
4 dojo.require('dojo.cookie');
5 dojo.declare('openils.XUL', null, {});
7 openils.XUL.isXUL = function() {
8 return Boolean(dojo.cookie('xul')) || Boolean(window.IAMXUL);
11 openils.XUL.buildId = function() {
12 return window.XUL_BUILD_ID || '';
15 openils.XUL.getStash = function() {
16 if(openils.XUL.isXUL()) {
18 if(openils.XUL.enableXPConnect()) {
19 var CacheClass = new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
20 return new CacheClass().wrappedJSObject.OpenILS.prototype.data;
23 console.log("Error loading XUL stash: " + e);
30 openils.XUL.newTab = function(path, tabInfo, options) {
32 throw new Error('xulG is not defined. Cannot open tab');
33 xulG.new_tab(path, tabInfo, options);
37 * This can be used by privileged Firefox in addition to XUL.
38 * To use use in Firefox directly, set signed.applets.codebase_principal_support to true in about:config
40 openils.XUL.enableXPConnect = function() {
42 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
45 console.error("Unable to enable UniversalXPConnect privileges. " +
46 "Try setting 'signed.applets.codebase_principal_support' to true in about:config");
53 /* This class cuts down on the obscenely long incantations needed to
54 * use XPCOM components. */
55 openils.XUL.SimpleXPCOM = function() {};
56 openils.XUL.SimpleXPCOM.prototype = {
58 "iface": Components.interfaces.nsIFilePicker,
59 "cls": "@mozilla.org/filepicker;1"
62 "iface": Components.interfaces.nsIFileInputStream,
63 "cls": "@mozilla.org/network/file-input-stream;1"
66 "iface": Components.interfaces.nsIScriptableInputStream,
67 "cls": "@mozilla.org/scriptableinputstream;1"
69 "create": function(key) {
70 return Components.classes[this[key].cls].
71 createInstance(this[key].iface);
73 "getPrivilegeManager": function() {
74 return netscape.security.PrivilegeManager;
78 openils.XUL.contentFromFileOpenDialog = function(windowTitle) {
80 var api = new openils.XUL.SimpleXPCOM();
82 /* The following enablePrivilege() call must happen at this exact
83 * level of scope -- not wrapped in another function -- otherwise
85 api.getPrivilegeManager().enablePrivilege("UniversalXPConnect");
87 var picker = api.create("FP");
89 window, windowTitle || "Upload File", api.FP.iface.modeOpen
91 if (picker.show() == api.FP.iface.returnOK && picker.file) {
92 var fis = api.create("FIS");
93 var sis = api.create("SIS");
95 fis.init(picker.file, 1 /* MODE_RDONLY */, 0, 0);