]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/dojo/openils/XUL.js
added func to turn on UniversalXPConnect and offer a friendly error when it fails
[Evergreen.git] / Open-ILS / web / js / dojo / openils / XUL.js
1 if(!dojo._hasResource["openils.XUL"]) {
2
3     dojo.provide("openils.XUL");
4     dojo.declare('openils.XUL', null, {});
5
6     openils.XUL.isXUL = function() {
7         return Boolean(window.IAMXUL);
8     }
9     
10     openils.XUL.getStash = function() {
11         if(openils.XUL.isXUL()) {
12             try {
13                 if(openils.XUL.enableXPConnect()) {
14                                 var CacheClass = new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
15                                 return new CacheClass().wrappedJSObject.OpenILS.prototype.data;
16                 }
17             } catch(e) {
18                 console.log("Error loading XUL stash: " + e);
19             }
20         }
21
22         return {};
23     }
24
25     /** 
26      * This can be used by privileged Firefox in addition to XUL.
27      * To use use in Firefox directly, set signed.applets.codebase_principal_support to true in about:config
28      */ 
29     openils.XUL.enableXPConnect = function() {
30         try {
31             netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
32         } catch (E) {
33             if(dojo.isFF) {
34                 console.error("Unable to enable UniversalXPConnect privileges.  " +
35                     "Try setting 'signed.applets.codebase_principal_support' to true in about:config");
36             }
37             return false;
38         }
39         return true;
40     }
41 }
42
43