diff --git a/resources/static/communication_iframe/start.js b/resources/static/communication_iframe/start.js index 57ce36dcaca52ba1d78fc3db41208e89371444ec..fa26648aef2caed72eeb18c9a81b2259cee266c5 100644 --- a/resources/static/communication_iframe/start.js +++ b/resources/static/communication_iframe/start.js @@ -9,6 +9,11 @@ user = bid.User, storage = bid.Storage; + // Initialize all localstorage values to default values. Neccesary for + // proper sync of IE8 localStorage across multiple simultaneous + // browser sessions. + storage.setDefaultValues(); + network.init(); var chan = Channel.build({ diff --git a/resources/static/shared/storage.js b/resources/static/shared/storage.js index c4f7b0f741b4b9dbc450396f3c90147f882edd39..4163e0e6bf73f420ca776d9ea5c8f6cb3b180479 100644 --- a/resources/static/shared/storage.js +++ b/resources/static/shared/storage.js @@ -49,11 +49,34 @@ BrowserID.Storage = (function() { function clear() { storage.removeItem("emails"); - storage.removeItem("tempKeypair"); storage.removeItem("siteInfo"); storage.removeItem("managePage"); } + // initialize all localStorage values to default if they are unset. + // this function is only neccesary on IE8 where there are localStorage + // synchronization issues between different browsing contexts, however + // it's intended to avoid IE8 specific bugs from being introduced. + // see issue #1637 + function setDefaultValues() { + _.each({ + emailToUserID: {}, + emails: {}, + interaction_data: {}, + loggedIn: {}, + main_site: {}, + managePage: {}, + returnTo: null, + siteInfo: {}, + stagedOnBehalfOf: null, + usersComputer: {} + }, function(defaultVal, key) { + if (!storage[key]) { + storage[key] = JSON.stringify(defaultVal); + } + }); + } + function getEmails() { try { var emails = JSON.parse(storage.emails || "{}"); @@ -567,6 +590,13 @@ BrowserID.Storage = (function() { */ clear: clear, setReturnTo: setReturnTo, - getReturnTo: getReturnTo + getReturnTo: getReturnTo, + /** + * Set all used storage values to default if they are unset. This function + * is required for proper localStorage sync between different browsing contexts, + * see issue #1637 for full details. + * @method setDefaultValues + */ + setDefaultValues: setDefaultValues }; }());