From e58f2f513a07ded9ebb9f77d34231d3f202cc843 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 21 Dec 2017 12:03:59 +0100 Subject: [PATCH] [api-major] Remove the unused `encrypted` property from the `pdfInfo` object sent from the worker via the `GetDoc` message I recall being confused as to the purpose of the `encrypted` property all the way back when working on PR 4750. Looking at the history, this property was added in PR 1698 when password support was added to the API/viewer. However, its only purpose seem to have been to facilitate the addition of a `isEncrypted` function in the API. That function never, as far as I can tell, saw any use and was unceremoniously removed in PR 4144. Since we want to avoid sending all non-essential data early during initial document loading (e.g. PR 4750), it seems correct to get rid of the `encrypted` property. Especially since it hasn't even been exposed in the API for over three years, with no complaints that I'm aware of. Finally note that the `encrypt` property on the `XRef` instance isn't tied to the code that's being removed here. Given that we're calling `PDFDocument.parse` during `createDocumentHandler` in the worker which, via `PDFDocument.setup`, calls `XRef.parse` where the `Encrypt` data (if it exists) is always parsed. --- src/core/worker.js | 22 +++++++++------------- src/display/api.js | 5 ++--- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/core/worker.js b/src/core/worker.js index a905efe27..dda90c8bf 100644 --- a/src/core/worker.js +++ b/src/core/worker.js @@ -402,19 +402,15 @@ var WorkerMessageHandler = { var loadDocumentCapability = createPromiseCapability(); var parseSuccess = function parseSuccess() { - var numPagesPromise = pdfManager.ensureDoc('numPages'); - var fingerprintPromise = pdfManager.ensureDoc('fingerprint'); - var encryptedPromise = pdfManager.ensureXRef('encrypt'); - Promise.all([numPagesPromise, fingerprintPromise, - encryptedPromise]).then(function onDocReady(results) { - var doc = { - numPages: results[0], - fingerprint: results[1], - encrypted: !!results[2], - }; - loadDocumentCapability.resolve(doc); - }, - parseFailure); + Promise.all([ + pdfManager.ensureDoc('numPages'), + pdfManager.ensureDoc('fingerprint'), + ]).then(function([numPages, fingerprint]) { + loadDocumentCapability.resolve({ + numPages, + fingerprint, + }); + }, parseFailure); }; var parseFailure = function parseFailure(e) { diff --git a/src/display/api.js b/src/display/api.js index 785745015..35e5b584c 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -1649,9 +1649,8 @@ var WorkerTransport = (function WorkerTransportClosure() { }; }, this); - messageHandler.on('GetDoc', function transportDoc(data) { - var pdfInfo = data.pdfInfo; - this.numPages = data.pdfInfo.numPages; + messageHandler.on('GetDoc', function transportDoc({ pdfInfo, }) { + this.numPages = pdfInfo.numPages; var loadingTask = this.loadingTask; var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask); this.pdfDocument = pdfDocument;