mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Ensure that onProgress
is always called when the entire PDF file has been loaded, regardless of how it was fetched (issue 10160)
*Please note:* I'm totally fine with this patch being rejected, and the issue closed as WONTFIX; however these changes should address the issue if that's desired. From a conceptual point of view, reporting loading progress doesn't really make a lot of sense for PDF files opened by passing raw binary data directly to `getDocument` (since obviously *all* data was loaded). This is compared to PDF files loaded via e.g. `XMLHttpRequest` or the Fetch API, where the entire PDF file isn't available from the start and knowing the loading progress makes total sense. However I can certainly see why the current API could be considered inconsistent, which isn't great, since a registered `onProgress` callback will never be called for certain `getDocument` calls. The simplest solution to this inconsistency thus seem to be to ensure that `onProgress` is always called when handling the `DataLoaded` message, since that will *always* be dispatched[1] from the worker-thread. --- [1] Note that this isn't guaranteed to happen, since setting `disableAutoFetch = true` often prevents the *entire* file from ever loading. However, this isn't relevant for the issue at hand, and is a well-known consequence of using `disableAutoFetch = true`; note how the default viewer even has a specialized code-path for hiding the loadingBar.
This commit is contained in:
parent
ecbdc508f7
commit
327f2eb588
2 changed files with 25 additions and 9 deletions
|
@ -1763,12 +1763,9 @@ class WorkerTransport {
|
|||
fullReader.headersReady.then(() => {
|
||||
// If stream or range are disabled, it's our only way to report
|
||||
// loading progress.
|
||||
if (!fullReader.isStreamingSupported ||
|
||||
!fullReader.isRangeSupported) {
|
||||
if (this._lastProgress) {
|
||||
if (loadingTask.onProgress) {
|
||||
loadingTask.onProgress(this._lastProgress);
|
||||
}
|
||||
if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
|
||||
if (this._lastProgress && loadingTask.onProgress) {
|
||||
loadingTask.onProgress(this._lastProgress);
|
||||
}
|
||||
fullReader.onProgress = (evt) => {
|
||||
if (loadingTask.onProgress) {
|
||||
|
@ -1866,6 +1863,14 @@ class WorkerTransport {
|
|||
}, this);
|
||||
|
||||
messageHandler.on('DataLoaded', function(data) {
|
||||
// For consistency: Ensure that progress is always reported when the
|
||||
// entire PDF file has been loaded, regardless of how it was fetched.
|
||||
if (loadingTask.onProgress) {
|
||||
loadingTask.onProgress({
|
||||
loaded: data.length,
|
||||
total: data.length,
|
||||
});
|
||||
}
|
||||
this.downloadInfoCapability.resolve(data);
|
||||
}, this);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue