Merge pull request #15555 from Snuffleupagus/improve-GetDocRequest

Clean-up the data that we're sending with "GetDocRequest"
This commit is contained in:
Tim van der Meij 2022-10-09 14:10:44 +02:00 committed by GitHub
commit dff444d441
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 50 deletions

View File

@ -97,7 +97,7 @@ class WorkerMessageHandler {
const WorkerTasks = []; const WorkerTasks = [];
const verbosity = getVerbosityLevel(); const verbosity = getVerbosityLevel();
const apiVersion = docParams.apiVersion; const { docId, apiVersion } = docParams;
const workerVersion = const workerVersion =
typeof PDFJSDev !== "undefined" && !PDFJSDev.test("TESTING") typeof PDFJSDev !== "undefined" && !PDFJSDev.test("TESTING")
? PDFJSDev.eval("BUNDLE_VERSION") ? PDFJSDev.eval("BUNDLE_VERSION")
@ -142,10 +142,7 @@ class WorkerMessageHandler {
throw new Error(partialMsg + "please update to a supported browser."); throw new Error(partialMsg + "please update to a supported browser.");
} }
} }
const workerHandlerName = docId + "_worker";
const docId = docParams.docId;
const docBaseUrl = docParams.docBaseUrl;
const workerHandlerName = docParams.docId + "_worker";
let handler = new MessageHandler(workerHandlerName, docId, port); let handler = new MessageHandler(workerHandlerName, docId, port);
function ensureNotTerminated() { function ensureNotTerminated() {
@ -204,17 +201,25 @@ class WorkerMessageHandler {
return { numPages, fingerprints, htmlForXfa }; return { numPages, fingerprints, htmlForXfa };
} }
function getPdfManager(data, evaluatorOptions, enableXfa) { function getPdfManager({
data,
password,
disableAutoFetch,
rangeChunkSize,
length,
docBaseUrl,
enableXfa,
evaluatorOptions,
}) {
const pdfManagerCapability = createPromiseCapability(); const pdfManagerCapability = createPromiseCapability();
let newPdfManager; let newPdfManager;
const source = data.source; if (data) {
if (source.data) {
try { try {
newPdfManager = new LocalPdfManager( newPdfManager = new LocalPdfManager(
docId, docId,
source.data, data,
source.password, password,
handler, handler,
evaluatorOptions, evaluatorOptions,
enableXfa, enableXfa,
@ -242,19 +247,19 @@ class WorkerMessageHandler {
if (!fullRequest.isRangeSupported) { if (!fullRequest.isRangeSupported) {
return; return;
} }
// We don't need auto-fetch when streaming is enabled. // We don't need auto-fetch when streaming is enabled.
const disableAutoFetch = disableAutoFetch =
source.disableAutoFetch || fullRequest.isStreamingSupported; disableAutoFetch || fullRequest.isStreamingSupported;
newPdfManager = new NetworkPdfManager( newPdfManager = new NetworkPdfManager(
docId, docId,
pdfStream, pdfStream,
{ {
msgHandler: handler, msgHandler: handler,
password: source.password, password,
length: fullRequest.contentLength, length: fullRequest.contentLength,
disableAutoFetch, disableAutoFetch,
rangeChunkSize: source.rangeChunkSize, rangeChunkSize,
}, },
evaluatorOptions, evaluatorOptions,
enableXfa, enableXfa,
@ -279,7 +284,7 @@ class WorkerMessageHandler {
let loaded = 0; let loaded = 0;
const flushChunks = function () { const flushChunks = function () {
const pdfFile = arraysToBytes(cachedChunks); const pdfFile = arraysToBytes(cachedChunks);
if (source.length && pdfFile.length !== source.length) { if (length && pdfFile.length !== length) {
warn("reported HTTP length is different from actual"); warn("reported HTTP length is different from actual");
} }
// the data is array, instantiating directly from it // the data is array, instantiating directly from it
@ -287,7 +292,7 @@ class WorkerMessageHandler {
newPdfManager = new LocalPdfManager( newPdfManager = new LocalPdfManager(
docId, docId,
pdfFile, pdfFile,
source.password, password,
handler, handler,
evaluatorOptions, evaluatorOptions,
enableXfa, enableXfa,
@ -405,19 +410,7 @@ class WorkerMessageHandler {
ensureNotTerminated(); ensureNotTerminated();
const evaluatorOptions = { getPdfManager(data)
maxImageSize: data.maxImageSize,
disableFontFace: data.disableFontFace,
ignoreErrors: data.ignoreErrors,
isEvalSupported: data.isEvalSupported,
isOffscreenCanvasSupported: data.isOffscreenCanvasSupported,
fontExtraProperties: data.fontExtraProperties,
useSystemFonts: data.useSystemFonts,
cMapUrl: data.cMapUrl,
standardFontDataUrl: data.standardFontDataUrl,
};
getPdfManager(data, evaluatorOptions, data.enableXfa)
.then(function (newPdfManager) { .then(function (newPdfManager) {
if (terminated) { if (terminated) {
// We were in a process of setting up the manager, but it got // We were in a process of setting up the manager, but it got

View File

@ -503,34 +503,33 @@ async function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
} }
const workerId = await worker.messageHandler.sendWithPromise( const workerId = await worker.messageHandler.sendWithPromise(
"GetDocRequest", "GetDocRequest",
// Only send the required properties, and *not* the entire `source` object.
{ {
docId, docId,
apiVersion: apiVersion:
typeof PDFJSDev !== "undefined" && !PDFJSDev.test("TESTING") typeof PDFJSDev !== "undefined" && !PDFJSDev.test("TESTING")
? PDFJSDev.eval("BUNDLE_VERSION") ? PDFJSDev.eval("BUNDLE_VERSION")
: null, : null,
// Only send the required properties, and *not* the entire object. data: source.data,
source: { password: source.password,
data: source.data, disableAutoFetch: source.disableAutoFetch,
url: source.url, rangeChunkSize: source.rangeChunkSize,
password: source.password, length: source.length,
disableAutoFetch: source.disableAutoFetch,
rangeChunkSize: source.rangeChunkSize,
length: source.length,
},
maxImageSize: source.maxImageSize,
disableFontFace: source.disableFontFace,
docBaseUrl: source.docBaseUrl, docBaseUrl: source.docBaseUrl,
ignoreErrors: source.ignoreErrors,
isEvalSupported: source.isEvalSupported,
isOffscreenCanvasSupported: source.isOffscreenCanvasSupported,
fontExtraProperties: source.fontExtraProperties,
enableXfa: source.enableXfa, enableXfa: source.enableXfa,
useSystemFonts: source.useSystemFonts, evaluatorOptions: {
cMapUrl: source.useWorkerFetch ? source.cMapUrl : null, maxImageSize: source.maxImageSize,
standardFontDataUrl: source.useWorkerFetch disableFontFace: source.disableFontFace,
? source.standardFontDataUrl ignoreErrors: source.ignoreErrors,
: null, isEvalSupported: source.isEvalSupported,
isOffscreenCanvasSupported: source.isOffscreenCanvasSupported,
fontExtraProperties: source.fontExtraProperties,
useSystemFonts: source.useSystemFonts,
cMapUrl: source.useWorkerFetch ? source.cMapUrl : null,
standardFontDataUrl: source.useWorkerFetch
? source.standardFontDataUrl
: null,
},
} }
); );