]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/dojo/openils/XUL.js
read xul cookie as well
[working/Evergreen.git] / Open-ILS / web / js / dojo / openils / XUL.js
1 if(!dojo._hasResource["openils.XUL"]) {
2
3     dojo.provide("openils.XUL");
4     dojo.require('dojo.cookie');
5     dojo.declare('openils.XUL', null, {});
6
7     openils.XUL.isXUL = function() {
8         return Boolean(dojo.cookie('xul')) || Boolean(window.IAMXUL);
9     }
10
11     openils.XUL.buildId = function() {
12         return window.XUL_BUILD_ID || '';
13     }
14     
15     openils.XUL.getStash = function() {
16         if(openils.XUL.isXUL()) {
17             try {
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;
21                 }
22             } catch(e) {
23                 console.log("Error loading XUL stash: " + e);
24             }
25         }
26
27         return {};
28     }
29
30     /** 
31      * This can be used by privileged Firefox in addition to XUL.
32      * To use use in Firefox directly, set signed.applets.codebase_principal_support to true in about:config
33      */ 
34     openils.XUL.enableXPConnect = function() {
35         try {
36             netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
37         } catch (E) {
38             if(dojo.isFF) {
39                 console.error("Unable to enable UniversalXPConnect privileges.  " +
40                     "Try setting 'signed.applets.codebase_principal_support' to true in about:config");
41             }
42             return false;
43         }
44         return true;
45     }
46 }
47
48