Fix localStorage feature detection. Close #1099

This commit is contained in:
Artur Adib 2012-01-24 10:08:18 -05:00
parent 36cf14b08c
commit 5c62f99fee

View File

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