From 5c62f99fee6bad235d80d337ede1a3620c031652 Mon Sep 17 00:00:00 2001 From: Artur Adib Date: Tue, 24 Jan 2012 10:08:18 -0500 Subject: [PATCH 1/2] Fix localStorage feature detection. Close #1099 --- web/viewer.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/web/viewer.js b/web/viewer.js index b6b62af83..87f1c4b37 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -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; } }; From 843830cea0be94083f66bf65f525d66fe097fa61 Mon Sep 17 00:00:00 2001 From: Artur Adib Date: Tue, 24 Jan 2012 10:39:57 -0500 Subject: [PATCH 2/2] Workaround for FF bug --- web/viewer.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/web/viewer.js b/web/viewer.js index 87f1c4b37..11c0769a3 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -62,13 +62,16 @@ var RenderingQueue = (function RenderingQueueClosure() { })(); // Settings Manager - This is a utility for saving settings -// First we see if localStorage is available, FF bug #495747 +// First we see if localStorage is available // If not, we use FUEL in FF var Settings = (function SettingsClosure() { var isLocalStorageEnabled = (function localStorageEnabledTest() { // Feature test as per http://diveintohtml5.info/storage.html + // The additional localStorage call is to get around a FF quirk, see + // bug #495747 in bugzilla try { - return 'localStorage' in window && window['localStorage'] !== null; + return 'localStorage' in window && window['localStorage'] !== null && + localStorage; } catch (e) { return false; }