Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Firefox] Ensure that loading progress is reported, and the loadingBar updated, when disableRange=true is set #10714

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ const PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
* Abstract class to support range requests file loading.
* @param {number} length
* @param {Uint8Array} initialData
* @param {boolean} progressiveDone
*/
class PDFDataRangeTransport {
constructor(length, initialData, progressiveDone = false) {
Expand Down Expand Up @@ -551,10 +552,10 @@ class PDFDataRangeTransport {
}
}

onDataProgress(loaded) {
onDataProgress(loaded, total) {
this._readyCapability.promise.then(() => {
for (const listener of this._progressListeners) {
listener(loaded);
listener(loaded, total);
}
});
}
Expand Down
11 changes: 8 additions & 3 deletions src/display/transport_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ var PDFDataTransportStream = (function PDFDataTransportStreamClosure() {
this._onReceiveData({ begin, chunk, });
});

this._pdfDataRangeTransport.addProgressListener((loaded) => {
this._onProgress({ loaded, });
this._pdfDataRangeTransport.addProgressListener((loaded, total) => {
this._onProgress({ loaded, total, });
});

this._pdfDataRangeTransport.addProgressiveReadListener((chunk) => {
Expand Down Expand Up @@ -77,13 +77,18 @@ var PDFDataTransportStream = (function PDFDataTransportStreamClosure() {
},

_onProgress: function PDFDataTransportStream_onDataProgress(evt) {
if (this._rangeReaders.length > 0) {
if (evt.total === undefined && this._rangeReaders.length > 0) {
// Reporting to first range reader.
var firstReader = this._rangeReaders[0];
if (firstReader.onProgress) {
firstReader.onProgress({ loaded: evt.loaded, });
return;
}
}
let fullReader = this._fullRequestReader;
if (fullReader && fullReader.onProgress) {
fullReader.onProgress({ loaded: evt.loaded, total: evt.total, });
}
},

_onProgressiveDone() {
Expand Down
4 changes: 4 additions & 0 deletions web/firefoxcom.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ PDFViewerApplication.externalServices = {
break;
case 'progressiveRead':
pdfDataRangeTransport.onDataProgressiveRead(args.chunk);

// Don't forget to report loading progress as well, since otherwise
// the loadingBar won't update when `disableRange=true` is set.
pdfDataRangeTransport.onDataProgress(args.loaded, args.total);
break;
case 'progressiveDone':
if (pdfDataRangeTransport) {
Expand Down