Skip to content

Commit dabb2b9

Browse files
authored
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
2 parents 2c58120 + 652822b commit dabb2b9

4 files changed

Lines changed: 32 additions & 20 deletions

File tree

src/core/evaluator.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ class PartialEvaluator {
408408
isCompressed: true,
409409
};
410410
} else {
411+
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
412+
throw new Error("Only worker-thread fetching supported.");
413+
}
411414
// Get the data on the main-thread instead.
412415
data = await this.handler.sendWithPromise("FetchBinaryData", {
413416
type: "cMapReaderFactory",
@@ -446,6 +449,9 @@ class PartialEvaluator {
446449
`${this.options.standardFontDataUrl}${filename}`
447450
);
448451
} else {
452+
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
453+
throw new Error("Only worker-thread fetching supported.");
454+
}
449455
// Get the data on the main-thread instead.
450456
data = await this.handler.sendWithPromise("FetchBinaryData", {
451457
type: "standardFontDataFactory",

src/core/jbig2_ccittFax_wasm.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class JBig2CCITTFaxWasmImage {
4848
if (this.#useWorkerFetch) {
4949
this.#buffer = await fetchBinaryData(`${this.#wasmUrl}${filename}`);
5050
} else {
51+
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
52+
throw new Error("Only worker-thread fetching supported.");
53+
}
5154
this.#buffer = await this.#handler.sendWithPromise(
5255
"FetchBinaryData",
5356
{ type: "wasmFactory", filename }

src/core/jpx.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class JpxImage {
7272
if (this.#useWorkerFetch) {
7373
this.#buffer = await fetchBinaryData(`${this.#wasmUrl}${filename}`);
7474
} else {
75+
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
76+
throw new Error("Only worker-thread fetching supported.");
77+
}
7578
this.#buffer = await this.#handler.sendWithPromise(
7679
"FetchBinaryData",
7780
{ type: "wasmFactory", filename }

src/display/api.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,17 +2468,18 @@ class WorkerTransport {
24682468

24692469
this.canvasFactory = factory.canvasFactory;
24702470
this.filterFactory = factory.filterFactory;
2471-
this.cMapReaderFactory = factory.cMapReaderFactory;
2472-
this.standardFontDataFactory = factory.standardFontDataFactory;
2473-
this.wasmFactory = factory.wasmFactory;
2471+
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
2472+
this.cMapReaderFactory = factory.cMapReaderFactory;
2473+
this.standardFontDataFactory = factory.standardFontDataFactory;
2474+
this.wasmFactory = factory.wasmFactory;
2475+
}
2476+
this.pagesMapper = pagesMapper;
24742477

24752478
this.destroyed = false;
24762479
this.destroyCapability = null;
24772480

24782481
this.setupMessageHandler();
24792482

2480-
this.pagesMapper = pagesMapper;
2481-
24822483
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
24832484
// For testing purposes.
24842485
Object.defineProperty(this, "getNetworkStreamName", {
@@ -2925,22 +2926,21 @@ class WorkerTransport {
29252926
this.#onProgress(data);
29262927
});
29272928

2928-
messageHandler.on("FetchBinaryData", async data => {
2929-
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
2930-
throw new Error("Not implemented: FetchBinaryData");
2931-
}
2932-
if (this.destroyed) {
2933-
throw new Error("Worker was destroyed.");
2934-
}
2935-
const factory = this[data.type];
2929+
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
2930+
messageHandler.on("FetchBinaryData", async data => {
2931+
if (this.destroyed) {
2932+
throw new Error("Worker was destroyed.");
2933+
}
2934+
const factory = this[data.type];
29362935

2937-
if (!factory) {
2938-
throw new Error(
2939-
`${data.type} not initialized, see the \`useWorkerFetch\` parameter.`
2940-
);
2941-
}
2942-
return factory.fetch(data);
2943-
});
2936+
if (!factory) {
2937+
throw new Error(
2938+
`${data.type} not initialized, see the \`useWorkerFetch\` parameter.`
2939+
);
2940+
}
2941+
return factory.fetch(data);
2942+
});
2943+
}
29442944
}
29452945

29462946
getData() {

0 commit comments

Comments
 (0)