Merge pull request #20927 from Snuffleupagus/Firefox-enforce-worker-binary-fetch

[Firefox] Ensure that worker-thread fetching is used for built-in CMap, standard font, and wasm data
This commit is contained in:
calixteman 2026-03-20 17:45:43 +01:00 committed by GitHub
commit dabb2b960d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 32 additions and 20 deletions

View File

@ -408,6 +408,9 @@ class PartialEvaluator {
isCompressed: true, isCompressed: true,
}; };
} else { } else {
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
throw new Error("Only worker-thread fetching supported.");
}
// Get the data on the main-thread instead. // Get the data on the main-thread instead.
data = await this.handler.sendWithPromise("FetchBinaryData", { data = await this.handler.sendWithPromise("FetchBinaryData", {
type: "cMapReaderFactory", type: "cMapReaderFactory",
@ -446,6 +449,9 @@ class PartialEvaluator {
`${this.options.standardFontDataUrl}${filename}` `${this.options.standardFontDataUrl}${filename}`
); );
} else { } else {
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
throw new Error("Only worker-thread fetching supported.");
}
// Get the data on the main-thread instead. // Get the data on the main-thread instead.
data = await this.handler.sendWithPromise("FetchBinaryData", { data = await this.handler.sendWithPromise("FetchBinaryData", {
type: "standardFontDataFactory", type: "standardFontDataFactory",

View File

@ -48,6 +48,9 @@ class JBig2CCITTFaxWasmImage {
if (this.#useWorkerFetch) { if (this.#useWorkerFetch) {
this.#buffer = await fetchBinaryData(`${this.#wasmUrl}${filename}`); this.#buffer = await fetchBinaryData(`${this.#wasmUrl}${filename}`);
} else { } else {
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
throw new Error("Only worker-thread fetching supported.");
}
this.#buffer = await this.#handler.sendWithPromise( this.#buffer = await this.#handler.sendWithPromise(
"FetchBinaryData", "FetchBinaryData",
{ type: "wasmFactory", filename } { type: "wasmFactory", filename }

View File

@ -72,6 +72,9 @@ class JpxImage {
if (this.#useWorkerFetch) { if (this.#useWorkerFetch) {
this.#buffer = await fetchBinaryData(`${this.#wasmUrl}${filename}`); this.#buffer = await fetchBinaryData(`${this.#wasmUrl}${filename}`);
} else { } else {
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
throw new Error("Only worker-thread fetching supported.");
}
this.#buffer = await this.#handler.sendWithPromise( this.#buffer = await this.#handler.sendWithPromise(
"FetchBinaryData", "FetchBinaryData",
{ type: "wasmFactory", filename } { type: "wasmFactory", filename }

View File

@ -2468,17 +2468,18 @@ class WorkerTransport {
this.canvasFactory = factory.canvasFactory; this.canvasFactory = factory.canvasFactory;
this.filterFactory = factory.filterFactory; this.filterFactory = factory.filterFactory;
this.cMapReaderFactory = factory.cMapReaderFactory; if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
this.standardFontDataFactory = factory.standardFontDataFactory; this.cMapReaderFactory = factory.cMapReaderFactory;
this.wasmFactory = factory.wasmFactory; this.standardFontDataFactory = factory.standardFontDataFactory;
this.wasmFactory = factory.wasmFactory;
}
this.pagesMapper = pagesMapper;
this.destroyed = false; this.destroyed = false;
this.destroyCapability = null; this.destroyCapability = null;
this.setupMessageHandler(); this.setupMessageHandler();
this.pagesMapper = pagesMapper;
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) { if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
// For testing purposes. // For testing purposes.
Object.defineProperty(this, "getNetworkStreamName", { Object.defineProperty(this, "getNetworkStreamName", {
@ -2925,22 +2926,21 @@ class WorkerTransport {
this.#onProgress(data); this.#onProgress(data);
}); });
messageHandler.on("FetchBinaryData", async data => { if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { messageHandler.on("FetchBinaryData", async data => {
throw new Error("Not implemented: FetchBinaryData"); if (this.destroyed) {
} throw new Error("Worker was destroyed.");
if (this.destroyed) { }
throw new Error("Worker was destroyed."); const factory = this[data.type];
}
const factory = this[data.type];
if (!factory) { if (!factory) {
throw new Error( throw new Error(
`${data.type} not initialized, see the \`useWorkerFetch\` parameter.` `${data.type} not initialized, see the \`useWorkerFetch\` parameter.`
); );
} }
return factory.fetch(data); return factory.fetch(data);
}); });
}
} }
getData() { getData() {