Move the disableAutoFetch option from the global PDFJS object and into getDocument instead

One additional complication with removing this option from the global `PDFJS` object, is that the viewer currently needs to check `disableAutoFetch` in a couple of places. To address this I'm thus proposing adding a getter in `PDFDocumentProxy`, to allow checking the *actually* used values for a particular `getDocument` invocation.
This commit is contained in:
Jonas Jenwald 2018-02-17 22:08:45 +01:00
parent c7c583583b
commit 69d7191034
7 changed files with 38 additions and 22 deletions

View file

@ -18,7 +18,7 @@ import {
assert, createPromiseCapability, getVerbosityLevel, info, InvalidPDFException,
isArrayBuffer, isNum, isSameOrigin, MessageHandler, MissingPDFException,
NativeImageDecoding, PageViewport, PasswordException, setVerbosityLevel,
stringToBytes, UnexpectedResponseException, UnknownErrorException,
shadow, stringToBytes, UnexpectedResponseException, UnknownErrorException,
unreachable, Util, warn
} from '../shared/util';
import {
@ -164,6 +164,12 @@ function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
* converted to OpenType fonts and loaded via font face rules. If disabled,
* fonts will be rendered using a built-in font renderer that constructs the
* glyphs with primitive path commands. The default value is `false`.
* @property {boolean} disableAutoFetch - (optional) Disable pre-fetching of PDF
* file data. When range requests are enabled PDF.js will automatically keep
* fetching more data even if it isn't needed to display the current page.
* The default value is `false`.
* NOTE: It is also necessary to disable streaming, see above,
* in order for disabling of pre-fetching to work correctly.
*/
/**
@ -266,6 +272,10 @@ function getDocument(src) {
params.disableFontFace = false;
}
if (typeof params.disableAutoFetch !== 'boolean') {
params.disableAutoFetch = false;
}
// Set the main-thread verbosity level.
setVerbosityLevel(params.verbosity);
@ -333,7 +343,6 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('BUNDLE_VERSION') : null;
source.disableRange = getDefaultSetting('disableRange');
source.disableAutoFetch = getDefaultSetting('disableAutoFetch');
source.disableStream = getDefaultSetting('disableStream');
if (pdfDataRangeTransport) {
source.length = pdfDataRangeTransport.length;
@ -683,6 +692,10 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
destroy: function PDFDocumentProxy_destroy() {
return this.loadingTask.destroy();
},
get loadingParams() {
return this.transport.loadingParams;
},
};
return PDFDocumentProxy;
})();
@ -2116,6 +2129,13 @@ var WorkerTransport = (function WorkerTransportClosure() {
this.fontLoader.clear();
});
},
get loadingParams() {
let params = this._params;
return shadow(this, 'loadingParams', {
disableAutoFetch: params.disableAutoFetch,
});
},
};
return WorkerTransport;