Remove useless message handlers
These handlers are used to initiate the communication between the content thread and the worker and they aren't used once the document is loaded, hence we can remove them.
This commit is contained in:
parent
9d863f5180
commit
37d5f2d2ca
@ -87,8 +87,11 @@ class WorkerMessageHandler {
|
|||||||
setVerbosityLevel(data.verbosity);
|
setVerbosityLevel(data.verbosity);
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetDocRequest", function (data) {
|
handler.on("GetDocRequest", function ({ source, singleUse }) {
|
||||||
return WorkerMessageHandler.createDocumentHandler(data, port);
|
if (singleUse) {
|
||||||
|
handler.destroy();
|
||||||
|
}
|
||||||
|
return WorkerMessageHandler.createDocumentHandler(source, port);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,6 +216,8 @@ const DefaultStandardFontDataFactory =
|
|||||||
* when creating canvases. The default value is {new DOMCanvasFactory()}.
|
* when creating canvases. The default value is {new DOMCanvasFactory()}.
|
||||||
* @property {Object} [filterFactory] - A factory instance that will be used
|
* @property {Object} [filterFactory] - A factory instance that will be used
|
||||||
* to create SVG filters when rendering some images on the main canvas.
|
* to create SVG filters when rendering some images on the main canvas.
|
||||||
|
* @property {boolean} [singleUse] - When true the worker will be able to load
|
||||||
|
* only one PDF document, using the `getDocument` method.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -346,12 +348,13 @@ function getDocument(src) {
|
|||||||
baseUrl: standardFontDataUrl,
|
baseUrl: standardFontDataUrl,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!worker) {
|
if (!worker) {
|
||||||
const workerParams = {
|
const workerParams = {
|
||||||
verbosity,
|
verbosity,
|
||||||
port: GlobalWorkerOptions.workerPort,
|
port: GlobalWorkerOptions.workerPort,
|
||||||
|
singleUse: src.singleUse === true,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Worker was not provided -- creating and owning our own. If message port
|
// Worker was not provided -- creating and owning our own. If message port
|
||||||
// is specified in global worker options, using it.
|
// is specified in global worker options, using it.
|
||||||
worker = workerParams.port
|
worker = workerParams.port
|
||||||
@ -456,6 +459,12 @@ function getDocument(src) {
|
|||||||
throw new Error("Loading aborted");
|
throw new Error("Loading aborted");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (worker._singleUse) {
|
||||||
|
// We don't the messageHandler anymore.
|
||||||
|
worker._messageHandler.destroy();
|
||||||
|
worker._messageHandler = null;
|
||||||
|
}
|
||||||
|
|
||||||
const messageHandler = new MessageHandler(
|
const messageHandler = new MessageHandler(
|
||||||
docId,
|
docId,
|
||||||
workerId,
|
workerId,
|
||||||
@ -493,7 +502,7 @@ async function _fetchDocument(worker, source) {
|
|||||||
}
|
}
|
||||||
const workerId = await worker.messageHandler.sendWithPromise(
|
const workerId = await worker.messageHandler.sendWithPromise(
|
||||||
"GetDocRequest",
|
"GetDocRequest",
|
||||||
source,
|
{ source, singleUse: worker._singleUse },
|
||||||
source.data ? [source.data.buffer] : null
|
source.data ? [source.data.buffer] : null
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -2029,6 +2038,7 @@ class PDFWorker {
|
|||||||
name = null,
|
name = null,
|
||||||
port = null,
|
port = null,
|
||||||
verbosity = getVerbosityLevel(),
|
verbosity = getVerbosityLevel(),
|
||||||
|
singleUse = false,
|
||||||
} = {}) {
|
} = {}) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.destroyed = false;
|
this.destroyed = false;
|
||||||
@ -2038,6 +2048,7 @@ class PDFWorker {
|
|||||||
this._port = null;
|
this._port = null;
|
||||||
this._webWorker = null;
|
this._webWorker = null;
|
||||||
this._messageHandler = null;
|
this._messageHandler = null;
|
||||||
|
this._singleUse = singleUse;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) &&
|
(typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) &&
|
||||||
|
@ -1000,6 +1000,7 @@ const PDFViewerApplication = {
|
|||||||
const loadingTask = getDocument({
|
const loadingTask = getDocument({
|
||||||
...apiParams,
|
...apiParams,
|
||||||
...args,
|
...args,
|
||||||
|
singleUse: true,
|
||||||
});
|
});
|
||||||
this.pdfLoadingTask = loadingTask;
|
this.pdfLoadingTask = loadingTask;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user