Skip to content

Commit

Permalink
Merge pull request #7793 from Snuffleupagus/ViewHistory-storage-key-name
Browse files Browse the repository at this point in the history
Rename the `ViewHistory` localStorage (and sessionStorage) key from `database` to `pdfjs.history`, and migrate existing data on read (issue 7760)
  • Loading branch information
timvandermeij authored Nov 21, 2016
2 parents 8a1ed8a + 0af42f1 commit 787d887
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions web/view_history.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ var ViewHistory = (function ViewHistoryClosure() {

if (typeof PDFJSDev !== 'undefined' &&
PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
sessionStorage.setItem('pdfjsHistory', databaseStr);
sessionStorage.setItem('pdfjs.history', databaseStr);
} else {
localStorage.setItem('database', databaseStr);
localStorage.setItem('pdfjs.history', databaseStr);
}
resolve();
}.bind(this));
Expand All @@ -87,9 +87,28 @@ var ViewHistory = (function ViewHistoryClosure() {
return new Promise(function (resolve) {
if (typeof PDFJSDev !== 'undefined' &&
PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
resolve(sessionStorage.getItem('pdfjsHistory'));
resolve(sessionStorage.getItem('pdfjs.history'));
} else {
resolve(localStorage.getItem('database'));
var value = localStorage.getItem('pdfjs.history');

// TODO: Remove this key-name conversion after a suitable time-frame.
// Note that we only remove the old 'database' entry if it looks like
// it was created by PDF.js. to avoid removing someone else's data.
if (!value) {
var databaseStr = localStorage.getItem('database');
if (databaseStr) {
try {
var database = JSON.parse(databaseStr);
if (typeof database.files[0].fingerprint === 'string') {
localStorage.setItem('pdfjs.history', databaseStr);
localStorage.removeItem('database');
value = databaseStr;
}
} catch (ex) { }
}
}

resolve(value);
}
});
},
Expand Down

0 comments on commit 787d887

Please sign in to comment.