From d46715210ae3172b6a7ff5dc7ad61c395b949729 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 6 Jan 2019 16:39:43 +0100 Subject: [PATCH] Accept non-matching document fingerprints, in `PDFHistory`, when the viewer is reloaded (issue 6847) This should hopefully be sufficient to address issue 6847, and given the limited impact of the code changes I'm not completely sure if this would need to be controlled by a preference!? Initially my intention was to try and provide some (slightly more detailed) implementation suggestions in the issue, but having looked briefly at doing that it would essentially have amounted to actually writing the code anyway. (Especially considering that the recent questions seemed to more-or-less ignore the information already provided in the first post.) Finally, note that since `performance.navigation.type` is marked as deprecated, a slightly different approach was choosen instead. --- web/pdf_history.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/web/pdf_history.js b/web/pdf_history.js index cbf8f3869..f33a9f2f2 100644 --- a/web/pdf_history.js +++ b/web/pdf_history.js @@ -112,7 +112,7 @@ class PDFHistory { this._destination = null; this._position = null; - if (!this._isValidState(state) || resetHistory) { + if (!this._isValidState(state, /* checkReload = */ true) || resetHistory) { let { hash, page, rotation, } = parseCurrentHash(this.linkService); if (!hash || reInitialized || resetHistory) { @@ -359,14 +359,27 @@ class PDFHistory { /** * @private */ - _isValidState(state) { + _isValidState(state, checkReload = false) { if (!state) { return false; } if (state.fingerprint !== this.fingerprint) { - // This should only occur in viewers with support for opening more than - // one PDF document, e.g. the GENERIC viewer. - return false; + if (checkReload) { + // Potentially accept the history entry, even if the fingerprints don't + // match, when the viewer was reloaded (see issue 6847). + if (typeof state.fingerprint !== 'string' || + state.fingerprint.length !== this.fingerprint.length) { + return false; + } + const [perfEntry] = performance.getEntriesByType('navigation'); + if (!perfEntry || perfEntry.type !== 'reload') { + return false; + } + } else { + // This should only occur in viewers with support for opening more than + // one PDF document, e.g. the GENERIC viewer. + return false; + } } if (!Number.isInteger(state.uid) || state.uid < 0) { return false;