From 05c05bdef5ec5125ba6d5810140e2d50715e1958 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 17 Feb 2018 22:28:08 +0100 Subject: [PATCH] Move the `disableStream` option from the global `PDFJS` object and into `getDocument` instead --- src/display/api.js | 8 +++++++- src/display/dom_utils.js | 2 -- src/display/global.js | 8 -------- web/app.js | 6 +++--- web/app_options.js | 5 +++++ 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/display/api.js b/src/display/api.js index bd36c6efe..cc15f1444 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -169,6 +169,9 @@ function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) { * of PDF files. When enabled, and if the server supports partial content * requests, then the PDF will be fetched in chunks. * The default value is `false`. + * @property {boolean} disableStream - (optional) Disable streaming of PDF file + * data. By default PDF.js attempts to load PDFs in chunks. + * 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. @@ -280,6 +283,9 @@ function getDocument(src) { if (typeof params.disableRange !== 'boolean') { params.disableRange = apiCompatibilityParams.disableRange || false; } + if (typeof params.disableStream !== 'boolean') { + params.disableStream = apiCompatibilityParams.disableStream || false; + } if (typeof params.disableAutoFetch !== 'boolean') { params.disableAutoFetch = false; } @@ -350,7 +356,6 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) { let apiVersion = typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('BUNDLE_VERSION') : null; - source.disableStream = getDefaultSetting('disableStream'); if (pdfDataRangeTransport) { source.length = pdfDataRangeTransport.length; source.initialData = pdfDataRangeTransport.initialData; @@ -2141,6 +2146,7 @@ var WorkerTransport = (function WorkerTransportClosure() { let params = this._params; return shadow(this, 'loadingParams', { disableRange: params.disableRange, + disableStream: params.disableStream, disableAutoFetch: params.disableAutoFetch, }); }, diff --git a/src/display/dom_utils.js b/src/display/dom_utils.js index b364e7291..e5d7e27d8 100644 --- a/src/display/dom_utils.js +++ b/src/display/dom_utils.js @@ -336,8 +336,6 @@ function getDefaultSetting(id) { switch (id) { case 'pdfBug': return globalSettings ? globalSettings.pdfBug : false; - case 'disableStream': - return globalSettings ? globalSettings.disableStream : false; case 'disableCreateObjectURL': return globalSettings ? globalSettings.disableCreateObjectURL : false; default: diff --git a/src/display/global.js b/src/display/global.js index 296955bdf..5c406407c 100644 --- a/src/display/global.js +++ b/src/display/global.js @@ -65,14 +65,6 @@ PDFJS.Util = Util; PDFJS.PageViewport = PageViewport; PDFJS.createPromiseCapability = createPromiseCapability; -/** - * Disable streaming of PDF file data. By default PDF.js attempts to load PDF - * in chunks. This default behavior can be disabled. - * @var {boolean} - */ -PDFJS.disableStream = (PDFJS.disableStream === undefined ? - false : PDFJS.disableStream); - /** * Enables special hooks for debugging PDF.js. * @var {boolean} diff --git a/web/app.js b/web/app.js index e164e9518..7cb21656a 100644 --- a/web/app.js +++ b/web/app.js @@ -201,10 +201,10 @@ let PDFViewerApplication = { AppOptions.set('disableRange', value); }), preferences.get('disableStream').then(function resolved(value) { - if (PDFJS.disableStream === true) { + if (AppOptions.get('disableStream') === true) { return; } - PDFJS.disableStream = value; + AppOptions.set('disableStream', value); }), preferences.get('disableAutoFetch').then(function resolved(value) { AppOptions.set('disableAutoFetch', value); @@ -263,7 +263,7 @@ let PDFViewerApplication = { AppOptions.set('disableRange', hashParams['disablerange'] === 'true'); } if ('disablestream' in hashParams) { - PDFJS.disableStream = (hashParams['disablestream'] === 'true'); + AppOptions.set('disableStream', hashParams['disablestream'] === 'true'); } if ('disableautofetch' in hashParams) { AppOptions.set('disableAutoFetch', diff --git a/web/app_options.js b/web/app_options.js index b00a8b114..49a63ac3d 100644 --- a/web/app_options.js +++ b/web/app_options.js @@ -155,6 +155,11 @@ const defaultOptions = { value: apiCompatibilityParams.disableRange || false, kind: OptionKind.API, }, + disableStream: { + /** @type {boolean} */ + value: apiCompatibilityParams.disableStream || false, + kind: OptionKind.API, + }, isEvalSupported: { /** @type {boolean} */ value: true,