Skip to content

Commit a0102ab

Browse files
committed
Move the NetworkStream choice from src/display/api.js and into a separate file
This code already isn't used (or even bundled) in the Firefox PDF Viewer, and it also slightly reduces the number of import maps that need to be maintained.
1 parent 2643125 commit a0102ab

File tree

10 files changed

+45
-46
lines changed

10 files changed

+45
-46
lines changed

gulpfile.mjs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,7 @@ function createWebpackAlias(defines) {
196196
};
197197
const libraryAlias = {
198198
"display-binary_data_factory": "src/display/stubs.js",
199-
"display-fetch_stream": "src/display/stubs.js",
200-
"display-network": "src/display/stubs.js",
201-
"display-node_stream": "src/display/stubs.js",
199+
"display-network_stream": "src/display/stubs.js",
202200
"display-node_utils": "src/display/stubs.js",
203201
};
204202
const viewerAlias = {
@@ -227,8 +225,7 @@ function createWebpackAlias(defines) {
227225
if (defines.CHROME) {
228226
libraryAlias["display-binary_data_factory"] =
229227
"src/display/binary_data_factory.js";
230-
libraryAlias["display-fetch_stream"] = "src/display/fetch_stream.js";
231-
libraryAlias["display-network"] = "src/display/network.js";
228+
libraryAlias["display-network_stream"] = "src/display/network_stream.js";
232229

233230
viewerAlias["web-download_manager"] = "web/chromecom.js";
234231
viewerAlias["web-external_services"] = "web/chromecom.js";
@@ -241,9 +238,7 @@ function createWebpackAlias(defines) {
241238
// In the tsconfig.json files, the .js extension must be omitted.
242239
libraryAlias["display-binary_data_factory"] =
243240
"src/display/binary_data_factory.js";
244-
libraryAlias["display-fetch_stream"] = "src/display/fetch_stream.js";
245-
libraryAlias["display-network"] = "src/display/network.js";
246-
libraryAlias["display-node_stream"] = "src/display/node_stream.js";
241+
libraryAlias["display-network_stream"] = "src/display/network_stream.js";
247242
libraryAlias["display-node_utils"] = "src/display/node_utils.js";
248243

249244
viewerAlias["web-download_manager"] = "web/download_manager.js";
@@ -1540,9 +1535,7 @@ function buildLibHelper(bundleDefines, inputStream, outputDir) {
15401535
map: {
15411536
"pdfjs-lib": "../pdf.js",
15421537
"display-binary_data_factory": "./binary_data_factory.js",
1543-
"display-fetch_stream": "./fetch_stream.js",
1544-
"display-network": "./network.js",
1545-
"display-node_stream": "./node_stream.js",
1538+
"display-network_stream": "./network_stream.js",
15461539
"display-node_utils": "./node_utils.js",
15471540
"fluent-bundle": "../../../node_modules/@fluent/bundle/esm/index.js",
15481541
"fluent-dom": "../../../node_modules/@fluent/dom/esm/index.js",

src/display/api.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,13 @@ import { CanvasGraphics } from "./canvas.js";
7474
import { DOMBinaryDataFactory } from "display-binary_data_factory";
7575
import { DOMCanvasFactory } from "./canvas_factory.js";
7676
import { DOMFilterFactory } from "./filter_factory.js";
77+
import { getNetworkStream } from "display-network_stream";
7778
import { GlobalWorkerOptions } from "./worker_options.js";
7879
import { initWebGPUMesh } from "./webgpu_mesh.js";
7980
import { Metadata } from "./metadata.js";
8081
import { OptionalContentConfig } from "./optional_content_config.js";
8182
import { PagesMapper } from "./pages_mapper.js";
8283
import { PDFDataTransportStream } from "./transport_stream.js";
83-
import { PDFFetchStream } from "display-fetch_stream";
84-
import { PDFNetworkStream } from "display-network";
85-
import { PDFNodeStream } from "display-node_stream";
8684
import { PDFObjects } from "./pdf_objects.js";
8785
import { TextLayer } from "./text_layer.js";
8886
import { XfaText } from "./xfa_text.js";
@@ -454,14 +452,7 @@ function getDocument(src = {}) {
454452
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
455453
throw new Error("Not implemented: NetworkStream");
456454
}
457-
// eslint-disable-next-line no-nested-ternary
458-
const NetworkStream = isValidFetchUrl(url)
459-
? PDFFetchStream
460-
: typeof PDFJSDev !== "undefined" &&
461-
PDFJSDev.test("GENERIC") &&
462-
isNodeJS
463-
? PDFNodeStream
464-
: PDFNetworkStream;
455+
const NetworkStream = getNetworkStream(url);
465456

466457
networkStream = new NetworkStream({
467458
url,

src/display/network_stream.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* Copyright 2026 Mozilla Foundation
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
import { isNodeJS } from "../shared/util.js";
17+
import { isValidFetchUrl } from "./display_utils.js";
18+
import { PDFFetchStream } from "./fetch_stream.js";
19+
import { PDFNetworkStream } from "./network.js";
20+
import { PDFNodeStream } from "./node_stream.js";
21+
22+
function getNetworkStream(url) {
23+
// eslint-disable-next-line no-nested-ternary
24+
return isValidFetchUrl(url)
25+
? PDFFetchStream
26+
: typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC") && isNodeJS
27+
? PDFNodeStream
28+
: PDFNetworkStream;
29+
}
30+
31+
export { getNetworkStream };

src/display/stubs.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,15 @@
1414
*/
1515

1616
const DOMBinaryDataFactory = null;
17+
const getNetworkStream = null;
1718
const NodeBinaryDataFactory = null;
1819
const NodeCanvasFactory = null;
1920
const NodeFilterFactory = null;
20-
const PDFFetchStream = null;
21-
const PDFNetworkStream = null;
22-
const PDFNodeStream = null;
2321

2422
export {
2523
DOMBinaryDataFactory,
24+
getNetworkStream,
2625
NodeBinaryDataFactory,
2726
NodeCanvasFactory,
2827
NodeFilterFactory,
29-
PDFFetchStream,
30-
PDFNetworkStream,
31-
PDFNodeStream,
3228
};

test/components/simple-viewer.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@
4444
"pdfjs-lib": "../../src/pdf.js",
4545

4646
"display-binary_data_factory": "../../src/display/binary_data_factory.js",
47-
"display-fetch_stream": "../../src/display/fetch_stream.js",
48-
"display-network": "../../src/display/network.js",
49-
"display-node_stream": "../../src/display/stubs.js",
47+
"display-network_stream": "../../src/display/network_stream.js",
5048
"display-node_utils": "../../src/display/stubs.js",
5149

5250
"fluent-bundle": "../../node_modules/@fluent/bundle/esm/index.js",

test/unit/unit_test.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
"cached-iterable": "../../node_modules/cached-iterable/src/index.mjs",
2222

2323
"display-binary_data_factory": "../../src/display/binary_data_factory.js",
24-
"display-fetch_stream": "../../src/display/fetch_stream.js",
25-
"display-network": "../../src/display/network.js",
26-
"display-node_stream": "../../src/display/stubs.js",
24+
"display-network_stream": "../../src/display/network_stream.js",
2725
"display-node_utils": "../../src/display/stubs.js",
2826

2927
"web-alt_text_manager": "../../web/alt_text_manager.js",

tsconfig.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
"paths": {
1212
"pdfjs-lib": ["./src/pdf"],
1313
"display-binary_data_factory": ["./src/display/binary_data_factory"],
14-
"display-fetch_stream": ["./src/display/fetch_stream"],
15-
"display-network": ["./src/display/network"],
16-
"display-node_stream": ["./src/display/node_stream"],
14+
"display-network_stream": ["./src/display/network_stream.js"],
1715
"display-node_utils": ["./src/display/node_utils"],
1816
"fluent-bundle": ["./node_modules/@fluent/bundle/esm/index.js"],
1917
"fluent-dom": ["./node_modules/@fluent/dom/esm/index.js"],

web/internal/debugger.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ <h1>PDF.js — Debugging tools</h1>
127127
"pdfjs-lib": "../../src/pdf.js",
128128

129129
"display-binary_data_factory": "../../src/display/binary_data_factory.js",
130-
"display-fetch_stream": "../../src/display/fetch_stream.js",
131-
"display-network": "../../src/display/network.js",
132-
"display-node_stream": "../../src/display/stubs.js",
130+
"display-network_stream": "../../src/display/network_stream.js",
133131
"display-node_utils": "../../src/display/stubs.js"
134132
}
135133
}

web/viewer-geckoview.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@
6060
"cached-iterable": "../node_modules/cached-iterable/src/index.mjs",
6161

6262
"display-binary_data_factory": "../src/display/binary_data_factory.js",
63-
"display-fetch_stream": "../src/display/fetch_stream.js",
64-
"display-network": "../src/display/network.js",
65-
"display-node_stream": "../src/display/stubs.js",
63+
"display-network_stream": "../src/display/network_stream.js",
6664
"display-node_utils": "../src/display/stubs.js",
6765

6866
"web-alt_text_manager": "./stubs-geckoview.js",

web/viewer.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@
6363
"cached-iterable": "../node_modules/cached-iterable/src/index.mjs",
6464

6565
"display-binary_data_factory": "../src/display/binary_data_factory.js",
66-
"display-fetch_stream": "../src/display/fetch_stream.js",
67-
"display-network": "../src/display/network.js",
68-
"display-node_stream": "../src/display/stubs.js",
66+
"display-network_stream": "../src/display/network_stream.js",
6967
"display-node_utils": "../src/display/stubs.js",
7068

7169
"web-alt_text_manager": "./alt_text_manager.js",

0 commit comments

Comments
 (0)