mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 17:55:37 +02:00
[Firefox regression] Fix disableRange=true
bug in PDFDataTransportStream
Currently if trying to set `disableRange=true` in the built-in PDF Viewer in Firefox, either through `about:config` or via the URL hash, the PDF document will never load. It appears that this has been broken for a couple of years, without anyone noticing. Obviously it's not a good idea to set `disableRange=true`, however it seems that this bug affects the PDF Viewer in Firefox even with default settings: - In the case where `initialData` already contains the *entire* file, we're forced to dispatch a range request to re-fetch already available data just so that file loading may complete. - (In the case where the data arrives, via streaming, before being specifically requested through `requestDataRange`, we're also forced to re-fetch data unnecessarily.) *This part was removed, to reduce the scope/risk of the patch somewhat.* In the cases outlined above, we're having to re-fetch already available data thus potentially delaying loading/rendering of PDF files in Firefox (and wasting resources in the process).
This commit is contained in:
parent
9b5a937f78
commit
bb384dd5ed
4 changed files with 74 additions and 6 deletions
|
@ -344,6 +344,7 @@ function getDocument(src) {
|
|||
networkStream = new PDFDataTransportStream({
|
||||
length: params.length,
|
||||
initialData: params.initialData,
|
||||
progressiveDone: params.progressiveDone,
|
||||
disableRange: params.disableRange,
|
||||
disableStream: params.disableStream,
|
||||
}, rangeTransport);
|
||||
|
@ -389,6 +390,7 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
|
|||
if (pdfDataRangeTransport) {
|
||||
source.length = pdfDataRangeTransport.length;
|
||||
source.initialData = pdfDataRangeTransport.initialData;
|
||||
source.progressiveDone = pdfDataRangeTransport.progressiveDone;
|
||||
}
|
||||
return worker.messageHandler.sendWithPromise('GetDocRequest', {
|
||||
docId,
|
||||
|
@ -515,13 +517,15 @@ const PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
|
|||
* @param {Uint8Array} initialData
|
||||
*/
|
||||
class PDFDataRangeTransport {
|
||||
constructor(length, initialData) {
|
||||
constructor(length, initialData, progressiveDone = false) {
|
||||
this.length = length;
|
||||
this.initialData = initialData;
|
||||
this.progressiveDone = progressiveDone;
|
||||
|
||||
this._rangeListeners = [];
|
||||
this._progressListeners = [];
|
||||
this._progressiveReadListeners = [];
|
||||
this._progressiveDoneListeners = [];
|
||||
this._readyCapability = createPromiseCapability();
|
||||
}
|
||||
|
||||
|
@ -537,6 +541,10 @@ class PDFDataRangeTransport {
|
|||
this._progressiveReadListeners.push(listener);
|
||||
}
|
||||
|
||||
addProgressiveDoneListener(listener) {
|
||||
this._progressiveDoneListeners.push(listener);
|
||||
}
|
||||
|
||||
onDataRange(begin, chunk) {
|
||||
for (const listener of this._rangeListeners) {
|
||||
listener(begin, chunk);
|
||||
|
@ -559,6 +567,14 @@ class PDFDataRangeTransport {
|
|||
});
|
||||
}
|
||||
|
||||
onDataProgressiveDone() {
|
||||
this._readyCapability.promise.then(() => {
|
||||
for (const listener of this._progressiveDoneListeners) {
|
||||
listener();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
transportReady() {
|
||||
this._readyCapability.resolve();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue