Re-factor PDFDocumentProperties such that it's properly reset when a new PDF file is opened (issue 8371)

This patch contains the following improvements:
 - Only fetch the various document properties *once* per PDF file opened, and cache the result (in a frozen object).
 - Always update the *entire* dialog at once, to prevent inconsistent UI state (issue 8371).
 - Ensure that the dialog, and all its internal properties, are reset when `PDFViewerApplication.close` is called.
 - Inline, and re-factor, the `getProperties` method in `open`, since that's the only call-site.
 - Always overwrite the fileSize with the value obtained from `pdfDocument.getDownloadInfo`, to ensure that it's correct.
 - ES6-ify the code that's touched in this patch.

Fixes 8371.
This commit is contained in:
Jonas Jenwald 2017-05-05 14:04:08 +02:00
parent 50d026fbda
commit 7780fd5b98
4 changed files with 125 additions and 89 deletions

View file

@ -13,6 +13,8 @@
* limitations under the License.
*/
import { cloneObj } from './ui_utils';
var defaultPreferences = null;
function getDefaultPreferences() {
if (!defaultPreferences) {
@ -38,16 +40,6 @@ function getDefaultPreferences() {
return defaultPreferences;
}
function cloneObj(obj) {
var result = {};
for (var i in obj) {
if (Object.prototype.hasOwnProperty.call(obj, i)) {
result[i] = obj[i];
}
}
return result;
}
/**
* BasePreferences - Abstract base class for storing persistent settings.
* Used for settings that should be applied to all opened documents,