added func to turn on UniversalXPConnect and offer a friendly error when it fails
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 21 Apr 2009 15:22:43 +0000 (15:22 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 21 Apr 2009 15:22:43 +0000 (15:22 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@12937 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/openils/XUL.js

index 80f4c09..4ad26b8 100644 (file)
@@ -4,22 +4,40 @@ if(!dojo._hasResource["openils.XUL"]) {
     dojo.declare('openils.XUL', null, {});
 
     openils.XUL.isXUL = function() {
-        return window.IAMXUL;
+        return Boolean(window.IAMXUL);
     }
     
     openils.XUL.getStash = function() {
         if(openils.XUL.isXUL()) {
             try {
-                           netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-                           var CacheClass = new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
-                           return new CacheClass().wrappedJSObject.OpenILS.prototype.data;
+                if(openils.XUL.enableXPConnect()) {
+                               var CacheClass = new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
+                               return new CacheClass().wrappedJSObject.OpenILS.prototype.data;
+                }
             } catch(e) {
                 console.log("Error loading XUL stash: " + e);
             }
         }
 
         return {};
-    };
+    }
+
+    /** 
+     * This can be used by privileged Firefox in addition to XUL.
+     * To use use in Firefox directly, set signed.applets.codebase_principal_support to true in about:config
+     */ 
+    openils.XUL.enableXPConnect = function() {
+        try {
+            netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+        } catch (E) {
+            if(dojo.isFF) {
+                console.error("Unable to enable UniversalXPConnect privileges.  " +
+                    "Try setting 'signed.applets.codebase_principal_support' to true in about:config");
+            }
+            return false;
+        }
+        return true;
+    }
 }