From f840149cb9b85ec93cc530da5dac1a098a3a78e3 Mon Sep 17 00:00:00 2001 From: Martin Wendt Date: Sat, 1 Aug 2020 18:26:52 +0200 Subject: [PATCH] Handle 'Access is denied for this document' Update #1022 --- CHANGELOG.md | 3 +- src/jquery.fancytree.persist.js | 63 +++++++++++++++++++-------------- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa6a5934..91047af4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # 2.36.2 / Unreleased + * [Fixed] #1022 ext-persist: Handle 'Access is denied for this document' # 2.36.1 / 2020-07-25 - * [Fixed] #1021 ext-dnd5 Regression in drop marker + * [Fixed] #1021 ext-dnd5 Regression (#1012) in drop marker # 2.36.0 / 2020-07-15 * [Changed] #1005 Cast key to string in getNodeByKey() diff --git a/src/jquery.fancytree.persist.js b/src/jquery.fancytree.persist.js index 88867077..0dcc8cad 100644 --- a/src/jquery.fancytree.persist.js +++ b/src/jquery.fancytree.persist.js @@ -35,38 +35,49 @@ * Private functions and variables */ var cookieStore = null, - localStorageStore = window.localStorage - ? { - get: function(key) { - return window.localStorage.getItem(key); - }, - set: function(key, value) { - window.localStorage.setItem(key, value); - }, - remove: function(key) { - window.localStorage.removeItem(key); - }, - } - : null, - sessionStorageStore = window.sessionStorage - ? { - get: function(key) { - return window.sessionStorage.getItem(key); - }, - set: function(key, value) { - window.sessionStorage.setItem(key, value); - }, - remove: function(key) { - window.sessionStorage.removeItem(key); - }, - } - : null, + localStorageStore = null, + sessionStorageStore = null, _assert = $.ui.fancytree.assert, ACTIVE = "active", EXPANDED = "expanded", FOCUS = "focus", SELECTED = "selected"; + // Accessing window.xxxStorage may raise security exceptions (see #1022) + try { + _assert(window.localStorage && window.localStorage.getItem); + localStorageStore = { + get: function(key) { + return window.localStorage.getItem(key); + }, + set: function(key, value) { + window.localStorage.setItem(key, value); + }, + remove: function(key) { + window.localStorage.removeItem(key); + }, + }; + } catch (e) { + $.ui.fancytree.warn("Could not access window.localStorage", e); + } + + try { + _assert(window.sessionStorage && window.sessionStorage.getItem); + sessionStorageStore = { + get: function(key) { + return window.sessionStorage.getItem(key); + }, + set: function(key, value) { + window.sessionStorage.setItem(key, value); + }, + remove: function(key) { + window.sessionStorage.removeItem(key); + }, + }; + } catch (e) { + $.ui.fancytree.warn("Could not access window.sessionStorage", e); + } + if (typeof Cookies === "function") { // Assume https://github.com/js-cookie/js-cookie cookieStore = {