From cd6bcc65112615783d71934730367ab1d5e8d1f8 Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 28 Aug 2017 13:29:56 +0300 Subject: [PATCH] FF: when not dom.storage.enabled use dummies --- background/update.js | 2 +- js/messaging.js | 7 +++++++ js/prefs.js | 7 +++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/background/update.js b/background/update.js index 69f12d3f..04f368f5 100644 --- a/background/update.js +++ b/background/update.js @@ -18,7 +18,7 @@ var updater = { ERROR_MD5: 'error: MD5 is invalid', ERROR_JSON: 'error: JSON is invalid', - lastUpdateTime: parseInt(tryCatch(() => localStorage.lastUpdateTime)) || Date.now(), + lastUpdateTime: parseInt(localStorage.lastUpdateTime) || Date.now(), checkAllStyles({observer = () => {}, save = true, ignoreDigest} = {}) { updater.resetInterval(); diff --git a/js/messaging.js b/js/messaging.js index a55191f1..31d8a5c2 100644 --- a/js/messaging.js +++ b/js/messaging.js @@ -57,6 +57,13 @@ if (!BG || BG !== window) { } } +const FIREFOX_NO_DOM_STORAGE = FIREFOX && !tryCatch(() => localStorage); +if (FIREFOX_NO_DOM_STORAGE) { + // may be disabled via dom.storage.enabled + Object.defineProperty(window, 'localStorage', {value: {}}); + Object.defineProperty(window, 'sessionStorage', {value: {}}); +} + function notifyAllTabs(msg) { const originalMessage = msg; diff --git a/js/prefs.js b/js/prefs.js index 2e47a7bd..7567c787 100644 --- a/js/prefs.js +++ b/js/prefs.js @@ -1,4 +1,4 @@ -/* global prefs: true, contextMenus */ +/* global prefs: true, contextMenus, FIREFOX_NO_DOM_STORAGE */ 'use strict'; // eslint-disable-next-line no-var @@ -75,9 +75,6 @@ var prefs = new function Prefs() { specific: new Map(), }; - // FF may think localStorage is a cookie or that it's not secure - const localStorage = tryCatch(() => window.localStorage) ? window.localStorage : {}; - // coalesce multiple pref changes in broadcast let broadcastPrefs = {}; @@ -184,6 +181,8 @@ var prefs = new function Prefs() { value = tryJSONparse(value) || defaultValue; break; } + } else if (FIREFOX_NO_DOM_STORAGE && BG) { + value = BG.localStorage[key] || defaultValue; } else { value = defaultValue; }