]> git.parisson.com Git - pdf.js.git/commitdiff
Fix localStorage feature detection. Close #1099
authorArtur Adib <arturadib@gmail.com>
Tue, 24 Jan 2012 15:08:18 +0000 (10:08 -0500)
committerArtur Adib <arturadib@gmail.com>
Tue, 24 Jan 2012 15:08:18 +0000 (10:08 -0500)
web/viewer.js

index b6b62af8332a891ed3610f2266e9dbe613420679..87f1c4b379709834581cad5b9461a2b2cd7292aa 100644 (file)
@@ -66,12 +66,12 @@ var RenderingQueue = (function RenderingQueueClosure() {
 // If not, we use FUEL in FF
 var Settings = (function SettingsClosure() {
   var isLocalStorageEnabled = (function localStorageEnabledTest() {
+    // Feature test as per http://diveintohtml5.info/storage.html
     try {
-      localStorage;
+      return 'localStorage' in window && window['localStorage'] !== null;
     } catch (e) {
       return false;
     }
-    return true;
   })();
   var extPrefix = 'extensions.uriloader@pdf.js';
   var isExtension = location.protocol == 'chrome:' && !isLocalStorageEnabled;
@@ -119,8 +119,9 @@ var Settings = (function SettingsClosure() {
 
   Settings.prototype = {
     set: function settingsSet(name, val) {
-      if (inPrivateBrowsing)
+      if (inPrivateBrowsing || !('file' in this))
         return false;
+
       var file = this.file;
       file[name] = val;
       if (isExtension)
@@ -131,10 +132,10 @@ var Settings = (function SettingsClosure() {
     },
 
     get: function settingsGet(name, defaultValue) {
-      if (inPrivateBrowsing)
+      if (inPrivateBrowsing || !('file' in this))
         return defaultValue;
-      else
-        return this.file[name] || defaultValue;
+
+      return this.file[name] || defaultValue;
     }
   };