mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Refactors history and how the database is stored
This commit is contained in:
parent
9c59437ac3
commit
b39f0c311c
7 changed files with 37 additions and 55 deletions
|
@ -537,3 +537,23 @@ if (typeof PDFJS === 'undefined') {
|
|||
}
|
||||
}
|
||||
})();
|
||||
|
||||
(function checkStorages() {
|
||||
// Feature test as per http://diveintohtml5.info/storage.html
|
||||
// The additional localStorage call is to get around a FF quirk, see
|
||||
// bug #495747 in bugzilla
|
||||
try {
|
||||
if ('localStorage' in window && window['localStorage'] !== null) {
|
||||
return;
|
||||
}
|
||||
} catch (e) { }
|
||||
window.localStorage = {
|
||||
data: Object.create(null),
|
||||
getItem: function (key) {
|
||||
return this.data[key];
|
||||
},
|
||||
setItem: function (key, value) {
|
||||
this.data[key] = value;
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* globals DEFAULT_PREFERENCES, isLocalStorageEnabled, Promise */
|
||||
/* globals DEFAULT_PREFERENCES, Promise */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
@ -174,19 +174,14 @@ var Preferences = {
|
|||
//#if !(FIREFOX || MOZCENTRAL || B2G)
|
||||
Preferences._writeToStorage = function (prefObj) {
|
||||
return new Promise(function (resolve) {
|
||||
if (isLocalStorageEnabled) {
|
||||
localStorage.setItem('pdfjs.preferences', JSON.stringify(prefObj));
|
||||
}
|
||||
localStorage.setItem('pdfjs.preferences', JSON.stringify(prefObj));
|
||||
resolve();
|
||||
});
|
||||
};
|
||||
|
||||
Preferences._readFromStorage = function (prefObj) {
|
||||
return new Promise(function (resolve) {
|
||||
var readPrefs;
|
||||
if (isLocalStorageEnabled) {
|
||||
readPrefs = JSON.parse(localStorage.getItem('pdfjs.preferences'));
|
||||
}
|
||||
var readPrefs = JSON.parse(localStorage.getItem('pdfjs.preferences'));
|
||||
resolve(readPrefs);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -257,16 +257,3 @@ var Cache = function cacheCache(size) {
|
|||
};
|
||||
};
|
||||
|
||||
//#if !(FIREFOX || MOZCENTRAL || B2G)
|
||||
var isLocalStorageEnabled = (function isLocalStorageEnabledClosure() {
|
||||
// Feature test as per http://diveintohtml5.info/storage.html
|
||||
// The additional localStorage call is to get around a FF quirk, see
|
||||
// bug #495747 in bugzilla
|
||||
try {
|
||||
return ('localStorage' in window && window['localStorage'] !== null &&
|
||||
localStorage);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
})();
|
||||
//#endif
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* globals PDFJS, VIEW_HISTORY_MEMORY, isLocalStorageEnabled, Promise */
|
||||
/* globals PDFJS, VIEW_HISTORY_MEMORY, Promise */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
|||
*
|
||||
* The way that the view parameters are stored depends on how PDF.js is built,
|
||||
* for 'node make <flag>' the following cases exist:
|
||||
* - FIREFOX or MOZCENTRAL - uses about:config.
|
||||
* - FIREFOX or MOZCENTRAL - uses sessionStorage.
|
||||
* - B2G - uses asyncStorage.
|
||||
* - GENERIC or CHROME - uses localStorage, if it is available.
|
||||
*/
|
||||
|
@ -48,13 +48,11 @@ var ViewHistory = (function ViewHistoryClosure() {
|
|||
//#endif
|
||||
|
||||
//#if FIREFOX || MOZCENTRAL
|
||||
// resolvePromise(FirefoxCom.requestSync('getDatabase', null));
|
||||
// resolvePromise(sessionStorage.getItem('pdfjsHistory'));
|
||||
//#endif
|
||||
|
||||
//#if !(FIREFOX || MOZCENTRAL || B2G)
|
||||
if (isLocalStorageEnabled) {
|
||||
resolvePromise(localStorage.getItem('database'));
|
||||
}
|
||||
resolvePromise(localStorage.getItem('database'));
|
||||
//#endif
|
||||
}
|
||||
|
||||
|
@ -95,13 +93,11 @@ var ViewHistory = (function ViewHistoryClosure() {
|
|||
//#endif
|
||||
|
||||
//#if FIREFOX || MOZCENTRAL
|
||||
// FirefoxCom.requestSync('setDatabase', database);
|
||||
// sessionStorage.setItem('pdfjsHistory',database);
|
||||
//#endif
|
||||
|
||||
//#if !(FIREFOX || MOZCENTRAL || B2G)
|
||||
if (isLocalStorageEnabled) {
|
||||
localStorage.setItem('database', database);
|
||||
}
|
||||
localStorage.setItem('database', database);
|
||||
//#endif
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue