Skip to content

Commit

Permalink
Fixes nickbaum#35; avoids namespace conflicts in localStorage keys
Browse files Browse the repository at this point in the history
  • Loading branch information
cspotcode committed Apr 13, 2017
1 parent 956625a commit dc58cdf
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ _gaq.push(['_setCustomVar', 1, 'windowCount', savedWindowNames.length, 1]);
chrome.windows.getAll({populate:true}, function(browserWindows) {
for (var i in savedWindowNames) {
var name = savedWindowNames[i];
var savedWindow = restoreFromLocalStorage(name);
var savedWindow = restoreFromLocalStorage(savedWindowStorageKey(name));
if (!savedWindow) {
console.error("Window " + name + " was not found in localStorage.");
savedWindowNames.splice(savedWindowNames.indexOf(name), 1);
Expand Down Expand Up @@ -146,7 +146,7 @@ function storeWindow(browserWindow, name, displayName) {
browserWindow.displayName = displayName;

savedWindows[name] = browserWindow;
localStorage[name] = JSON.stringify(browserWindow);
localStorage[savedWindowStorageKey(name)] = JSON.stringify(browserWindow);

return browserWindow;
}
Expand Down Expand Up @@ -225,8 +225,12 @@ function deleteSavedWindow(name) {
}

delete closedWindows[savedWindow.name];
delete localStorage[name];
delete localStorage[savedWindowStorageKey(name)];
delete savedWindows[name];
savedWindowNames.splice(savedWindowNames.indexOf(name), 1);
localStorage.savedWindowNames = JSON.stringify(savedWindowNames);
}

function savedWindowStorageKey(name) {
return 'savedWindow:' + name;
}

0 comments on commit dc58cdf

Please sign in to comment.