Skip to content

Commit 4c902eb

Browse files
committed
[api-minor] Remove support for browsers/environments without fully working URL.createObjectURL implementations
This `disableCreateObjectURL` option was originally introduced all the way back in PR 4103 (eight years ago), in order to work-around `URL.createObjectURL()`-bugs specific to Internet Explorer. In PR 8081 (five years ago) the `disableCreateObjectURL` option was extended to cover Google Chrome on iOS-devices as well, since that configuration apparently also suffered from `URL.createObjectURL()`-bugs.[1] At this point in time, I thus think that it makes sense to re-evaluate if we should still keep the `disableCreateObjectURL` option. - For Internet Explorer, support was explicitly removed in PDF.js version `2.7.570` which was released one year ago and all IE-specific compatibility code (and polyfills) have since been removed. - For Google Chrome on iOS-devices, while we still "support" such configurations, it's *not* the focus of any development and platform-specific bugs are thus often closed as WONTFIX. Note here that at this point in time, the `disableCreateObjectURL` option is *only* being used in the viewer and browser/platform bugs will thus not affect the main PDF.js library. Furthermore, given where the `disableCreateObjectURL` option is being used in the viewer the basic functionality should also remain unaffected by these changes.[2] Furthermore, it's also possible that the `URL.createObjectURL()`-bugs have been fixed in *browser* itself since PR 8081 was submitted.[3] Obviously you could argue that this isn't a lot of code, w.r.t. number of lines, and you'd be technically correct. However, it does add additional complexity in a few different viewer components which thus add overhead when reading and working with this code. Finally, assuming the `URL.createObjectURL()`-bugs are still present in Google Chrome on iOS-devices, I think that we should ask ourselves if it's reasonable for the PDF.js project (and its contributors) to keep attempting to support a configuration if the *browser* developers still haven't fixed these kind of bugs!? --- [1] According to https://groups.google.com/a/chromium.org/forum/#!topic/chromium-html5/RKQ0ZJIj7c4, which is linked in PR 8081, that bug was mentioned/reported as early as the 2014 (eight years ago). [2] Viewer functionality such as e.g. downloading and printing may be affected. [3] I don't have access to any iOS-devices to test with.
1 parent 9fba97d commit 4c902eb

File tree

5 files changed

+11
-49
lines changed

5 files changed

+11
-49
lines changed

web/app.js

+5-16
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {
3535
SpreadMode,
3636
TextLayerMode,
3737
} from "./ui_utils.js";
38-
import { AppOptions, compatibilityParams, OptionKind } from "./app_options.js";
38+
import { AppOptions, OptionKind } from "./app_options.js";
3939
import { AutomationEventBus, EventBus } from "./event_utils.js";
4040
import {
4141
build,
@@ -2490,22 +2490,11 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
24902490
}
24912491
const file = evt.fileInput.files[0];
24922492

2493-
if (!compatibilityParams.disableCreateObjectURL) {
2494-
let url = URL.createObjectURL(file);
2495-
if (file.name) {
2496-
url = { url, originalUrl: file.name };
2497-
}
2498-
PDFViewerApplication.open(url);
2499-
} else {
2500-
PDFViewerApplication.setTitleUsingUrl(file.name);
2501-
// Read the local file into a Uint8Array.
2502-
const fileReader = new FileReader();
2503-
fileReader.onload = function webViewerChangeFileReaderOnload(event) {
2504-
const buffer = event.target.result;
2505-
PDFViewerApplication.open(new Uint8Array(buffer));
2506-
};
2507-
fileReader.readAsArrayBuffer(file);
2493+
let url = URL.createObjectURL(file);
2494+
if (file.name) {
2495+
url = { url, originalUrl: file.name };
25082496
}
2497+
PDFViewerApplication.open(url);
25092498
};
25102499

25112500
webViewerOpenFile = function (evt) {

web/app_options.js

-11
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,6 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
2626
const isIOS =
2727
/\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) ||
2828
(platform === "MacIntel" && maxTouchPoints > 1);
29-
const isIOSChrome = /CriOS/.test(userAgent);
30-
31-
// Disables URL.createObjectURL() usage in some environments.
32-
// Support: Chrome on iOS
33-
(function checkOnBlobSupport() {
34-
// Sometimes Chrome on iOS loses data created with createObjectURL(),
35-
// see issue 8081.
36-
if (isIOSChrome) {
37-
compatibilityParams.disableCreateObjectURL = true;
38-
}
39-
})();
4029

4130
// Limit canvas size to 5 mega-pixels on mobile.
4231
// Support: Android, iOS

web/download_manager.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515

1616
/** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */
1717

18-
import { createObjectURL, createValidAbsoluteUrl, isPdfFile } from "pdfjs-lib";
19-
import { compatibilityParams } from "./app_options.js";
18+
import { createValidAbsoluteUrl, isPdfFile } from "pdfjs-lib";
2019

2120
if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("CHROME || GENERIC")) {
2221
throw new Error(
@@ -61,10 +60,8 @@ class DownloadManager {
6160
}
6261

6362
downloadData(data, filename, contentType) {
64-
const blobUrl = createObjectURL(
65-
data,
66-
contentType,
67-
compatibilityParams.disableCreateObjectURL
63+
const blobUrl = URL.createObjectURL(
64+
new Blob([data], { type: contentType })
6865
);
6966
download(blobUrl, filename);
7067
}
@@ -76,7 +73,7 @@ class DownloadManager {
7673
const isPdfData = isPdfFile(filename);
7774
const contentType = isPdfData ? "application/pdf" : "";
7875

79-
if (isPdfData && !compatibilityParams.disableCreateObjectURL) {
76+
if (isPdfData) {
8077
let blobUrl = this._openBlobUrls.get(element);
8178
if (!blobUrl) {
8279
blobUrl = URL.createObjectURL(new Blob([data], { type: contentType }));
@@ -119,11 +116,6 @@ class DownloadManager {
119116
* the "open with" dialog.
120117
*/
121118
download(blob, url, filename, sourceEventType = "download") {
122-
if (compatibilityParams.disableCreateObjectURL) {
123-
// URL.createObjectURL is not supported
124-
this.downloadUrl(url, filename);
125-
return;
126-
}
127119
const blobUrl = URL.createObjectURL(blob);
128120
download(blobUrl, filename);
129121
}

web/pdf_page_view.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -913,11 +913,7 @@ class PDFPageView {
913913
})
914914
.then(opList => {
915915
ensureNotCancelled();
916-
const svgGfx = new SVGGraphics(
917-
pdfPage.commonObjs,
918-
pdfPage.objs,
919-
/* forceDataSchema = */ compatibilityParams.disableCreateObjectURL
920-
);
916+
const svgGfx = new SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
921917
return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
922918
ensureNotCancelled();
923919
this.svg = svg;

web/pdf_print_service.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import { AnnotationMode, PixelsPerInch } from "pdfjs-lib";
1717
import { PDFPrintServiceFactory, PDFViewerApplication } from "./app.js";
18-
import { compatibilityParams } from "./app_options.js";
1918
import { getXfaHtmlForPrinting } from "./print_utils.js";
2019

2120
let activeService = null;
@@ -176,10 +175,7 @@ PDFPrintService.prototype = {
176175
this.throwIfInactive();
177176
const img = document.createElement("img");
178177
const scratchCanvas = this.scratchCanvas;
179-
if (
180-
"toBlob" in scratchCanvas &&
181-
!compatibilityParams.disableCreateObjectURL
182-
) {
178+
if ("toBlob" in scratchCanvas) {
183179
scratchCanvas.toBlob(function (blob) {
184180
img.src = URL.createObjectURL(blob);
185181
});

0 commit comments

Comments
 (0)