Tweak the "filesize" handling in PDFViewerApplication._initializeJavaScript
Another possible option here could be to use the `contentLength`, when it exists, and then using e.g. a custom event to always update the "filesize" in the sandbox "after the fact" with the result of the `getDownloadInfo`-call.
This commit is contained in:
parent
bfdb39a1e6
commit
1f2f8c907b
34
web/app.js
34
web/app.js
@ -251,7 +251,8 @@ const PDFViewerApplication = {
|
|||||||
_boundEvents: Object.create(null),
|
_boundEvents: Object.create(null),
|
||||||
documentInfo: null,
|
documentInfo: null,
|
||||||
metadata: null,
|
metadata: null,
|
||||||
contentDispositionFilename: null,
|
_contentDispositionFilename: null,
|
||||||
|
_contentLength: null,
|
||||||
triggerDelayedFallback: null,
|
triggerDelayedFallback: null,
|
||||||
_saveInProgress: false,
|
_saveInProgress: false,
|
||||||
_wheelUnusedTicks: 0,
|
_wheelUnusedTicks: 0,
|
||||||
@ -793,7 +794,8 @@ const PDFViewerApplication = {
|
|||||||
this.baseUrl = "";
|
this.baseUrl = "";
|
||||||
this.documentInfo = null;
|
this.documentInfo = null;
|
||||||
this.metadata = null;
|
this.metadata = null;
|
||||||
this.contentDispositionFilename = null;
|
this._contentDispositionFilename = null;
|
||||||
|
this._contentLength = null;
|
||||||
this.triggerDelayedFallback = null;
|
this.triggerDelayedFallback = null;
|
||||||
this._saveInProgress = false;
|
this._saveInProgress = false;
|
||||||
for (const callback of this._idleCallbacks) {
|
for (const callback of this._idleCallbacks) {
|
||||||
@ -946,7 +948,7 @@ const PDFViewerApplication = {
|
|||||||
// Use this.url instead of this.baseUrl to perform filename detection based
|
// Use this.url instead of this.baseUrl to perform filename detection based
|
||||||
// on the reference fragment as ultimate fallback if needed.
|
// on the reference fragment as ultimate fallback if needed.
|
||||||
const filename =
|
const filename =
|
||||||
this.contentDispositionFilename || getPDFFileNameFromURL(this.url);
|
this._contentDispositionFilename || getPDFFileNameFromURL(this.url);
|
||||||
const downloadManager = this.downloadManager;
|
const downloadManager = this.downloadManager;
|
||||||
downloadManager.onerror = err => {
|
downloadManager.onerror = err => {
|
||||||
// This error won't really be helpful because it's likely the
|
// This error won't really be helpful because it's likely the
|
||||||
@ -979,7 +981,7 @@ const PDFViewerApplication = {
|
|||||||
// Use this.url instead of this.baseUrl to perform filename detection based
|
// Use this.url instead of this.baseUrl to perform filename detection based
|
||||||
// on the reference fragment as ultimate fallback if needed.
|
// on the reference fragment as ultimate fallback if needed.
|
||||||
const filename =
|
const filename =
|
||||||
this.contentDispositionFilename || getPDFFileNameFromURL(this.url);
|
this._contentDispositionFilename || getPDFFileNameFromURL(this.url);
|
||||||
const downloadManager = this.downloadManager;
|
const downloadManager = this.downloadManager;
|
||||||
downloadManager.onerror = err => {
|
downloadManager.onerror = err => {
|
||||||
// This error won't really be helpful because it's likely the
|
// This error won't really be helpful because it's likely the
|
||||||
@ -1488,9 +1490,23 @@ const PDFViewerApplication = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const dispatchEventName = generateRandomStringForSandbox(objects);
|
const dispatchEventName = generateRandomStringForSandbox(objects);
|
||||||
const { length } = await pdfDocument.getDownloadInfo();
|
|
||||||
|
if (!this._contentLength) {
|
||||||
|
// Always waiting for the entire PDF document to be loaded will, most
|
||||||
|
// likely, delay sandbox-creation too much in the general case for all
|
||||||
|
// PDF documents which are not provided as binary data to the API.
|
||||||
|
// Hence we'll simply have to trust that the `contentLength` (as provided
|
||||||
|
// by the server), when it exists, is accurate enough here.
|
||||||
|
const { length } = await pdfDocument.getDownloadInfo();
|
||||||
|
|
||||||
|
if (pdfDocument !== this.pdfDocument) {
|
||||||
|
return; // The document was closed while the download info resolved.
|
||||||
|
}
|
||||||
|
this._contentLength = length;
|
||||||
|
}
|
||||||
const filename =
|
const filename =
|
||||||
this.contentDispositionFilename || getPDFFileNameFromURL(this.url);
|
this._contentDispositionFilename || getPDFFileNameFromURL(this.url);
|
||||||
|
|
||||||
scripting.createSandbox({
|
scripting.createSandbox({
|
||||||
objects,
|
objects,
|
||||||
dispatchEventName,
|
dispatchEventName,
|
||||||
@ -1502,7 +1518,7 @@ const PDFViewerApplication = {
|
|||||||
docInfo: {
|
docInfo: {
|
||||||
...this.documentInfo,
|
...this.documentInfo,
|
||||||
baseURL: this.baseUrl,
|
baseURL: this.baseUrl,
|
||||||
filesize: length,
|
filesize: this._contentLength,
|
||||||
filename,
|
filename,
|
||||||
metadata: this.metadata,
|
metadata: this.metadata,
|
||||||
numPages: pdfDocument.numPages,
|
numPages: pdfDocument.numPages,
|
||||||
@ -1582,6 +1598,7 @@ const PDFViewerApplication = {
|
|||||||
info,
|
info,
|
||||||
metadata,
|
metadata,
|
||||||
contentDispositionFilename,
|
contentDispositionFilename,
|
||||||
|
contentLength,
|
||||||
} = await pdfDocument.getMetadata();
|
} = await pdfDocument.getMetadata();
|
||||||
|
|
||||||
if (pdfDocument !== this.pdfDocument) {
|
if (pdfDocument !== this.pdfDocument) {
|
||||||
@ -1589,7 +1606,8 @@ const PDFViewerApplication = {
|
|||||||
}
|
}
|
||||||
this.documentInfo = info;
|
this.documentInfo = info;
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
this.contentDispositionFilename = contentDispositionFilename;
|
this._contentDispositionFilename = contentDispositionFilename;
|
||||||
|
this._contentLength = contentLength;
|
||||||
|
|
||||||
// Provides some basic debug information
|
// Provides some basic debug information
|
||||||
console.log(
|
console.log(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user