Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the compatibilityParams into the web/app_options.js file #13804

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ function buildDefaultPreferences(defines, dir) {
});

const inputStream = merge([
gulp.src(["web/{app_options,viewer_compatibility}.js"], {
gulp.src(["web/app_options.js"], {
base: ".",
}),
]);
Expand Down
5 changes: 2 additions & 3 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
SpreadMode,
TextLayerMode,
} from "./ui_utils.js";
import { AppOptions, OptionKind } from "./app_options.js";
import { AppOptions, compatibilityParams, OptionKind } from "./app_options.js";
import {
build,
createPromiseCapability,
Expand Down Expand Up @@ -78,7 +78,6 @@ import { PDFThumbnailViewer } from "./pdf_thumbnail_viewer.js";
import { PDFViewer } from "./pdf_viewer.js";
import { SecondaryToolbar } from "./secondary_toolbar.js";
import { Toolbar } from "./toolbar.js";
import { viewerCompatibilityParams } from "./viewer_compatibility.js";
import { ViewHistory } from "./view_history.js";

const DEFAULT_SCALE_DELTA = 1.1;
Expand Down Expand Up @@ -2484,7 +2483,7 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
}
const file = evt.fileInput.files[0];

if (!viewerCompatibilityParams.disableCreateObjectURL) {
if (!compatibilityParams.disableCreateObjectURL) {
let url = URL.createObjectURL(file);
if (file.name) {
url = { url, originalUrl: file.name };
Expand Down
38 changes: 35 additions & 3 deletions web/app_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,39 @@
* limitations under the License.
*/

import { viewerCompatibilityParams } from "./viewer_compatibility.js";
const compatibilityParams = Object.create(null);
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
const userAgent =
(typeof navigator !== "undefined" && navigator.userAgent) || "";
const platform =
(typeof navigator !== "undefined" && navigator.platform) || "";
const maxTouchPoints =
(typeof navigator !== "undefined" && navigator.maxTouchPoints) || 1;

const isAndroid = /Android/.test(userAgent);
const isIOS =
/\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) ||
(platform === "MacIntel" && maxTouchPoints > 1);
const isIOSChrome = /CriOS/.test(userAgent);

// Disables URL.createObjectURL() usage in some environments.
// Support: Chrome on iOS
(function checkOnBlobSupport() {
// Sometimes Chrome on iOS loses data created with createObjectURL(),
// see issue 8081.
if (isIOSChrome) {
compatibilityParams.disableCreateObjectURL = true;
}
})();

// Limit canvas size to 5 mega-pixels on mobile.
// Support: Android, iOS
(function checkCanvasSizeLimitation() {
if (isIOS || isAndroid) {
compatibilityParams.maxCanvasPixels = 5242880;
}
})();
}

const OptionKind = {
VIEWER: 0x02,
Expand Down Expand Up @@ -95,7 +127,7 @@ const defaultOptions = {
maxCanvasPixels: {
/** @type {number} */
value: 16777216,
compatibility: viewerCompatibilityParams.maxCanvasPixels,
compatibility: compatibilityParams.maxCanvasPixels,
kind: OptionKind.VIEWER,
},
pdfBugEnabled: {
Expand Down Expand Up @@ -348,4 +380,4 @@ class AppOptions {
}
}

export { AppOptions, OptionKind };
export { AppOptions, compatibilityParams, OptionKind };
8 changes: 4 additions & 4 deletions web/download_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

import { createObjectURL, createValidAbsoluteUrl, isPdfFile } from "pdfjs-lib";
import { viewerCompatibilityParams } from "./viewer_compatibility.js";
import { compatibilityParams } from "./app_options.js";

if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("CHROME || GENERIC")) {
throw new Error(
Expand Down Expand Up @@ -58,7 +58,7 @@ class DownloadManager {
const blobUrl = createObjectURL(
data,
contentType,
viewerCompatibilityParams.disableCreateObjectURL
compatibilityParams.disableCreateObjectURL
);
download(blobUrl, filename);
}
Expand All @@ -70,7 +70,7 @@ class DownloadManager {
const isPdfData = isPdfFile(filename);
const contentType = isPdfData ? "application/pdf" : "";

if (isPdfData && !viewerCompatibilityParams.disableCreateObjectURL) {
if (isPdfData && !compatibilityParams.disableCreateObjectURL) {
let blobUrl = this._openBlobUrls.get(element);
if (!blobUrl) {
blobUrl = URL.createObjectURL(new Blob([data], { type: contentType }));
Expand Down Expand Up @@ -113,7 +113,7 @@ class DownloadManager {
* the "open with" dialog.
*/
download(blob, url, filename, sourceEventType = "download") {
if (viewerCompatibilityParams.disableCreateObjectURL) {
if (compatibilityParams.disableCreateObjectURL) {
// URL.createObjectURL is not supported
this.downloadUrl(url, filename);
return;
Expand Down
6 changes: 3 additions & 3 deletions web/pdf_page_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import {
RenderingCancelledException,
SVGGraphics,
} from "pdfjs-lib";
import { compatibilityParams } from "./app_options.js";
import { NullL10n } from "./l10n_utils.js";
import { RenderingStates } from "./pdf_rendering_queue.js";
import { viewerCompatibilityParams } from "./viewer_compatibility.js";

/**
* @typedef {Object} PDFPageViewOptions
Expand Down Expand Up @@ -63,7 +63,7 @@ import { viewerCompatibilityParams } from "./viewer_compatibility.js";
* @property {IL10n} l10n - Localization service.
*/

const MAX_CANVAS_PIXELS = viewerCompatibilityParams.maxCanvasPixels || 16777216;
const MAX_CANVAS_PIXELS = compatibilityParams.maxCanvasPixels || 16777216;

/**
* @implements {IRenderableView}
Expand Down Expand Up @@ -819,7 +819,7 @@ class PDFPageView {
const svgGfx = new SVGGraphics(
pdfPage.commonObjs,
pdfPage.objs,
/* forceDataSchema = */ viewerCompatibilityParams.disableCreateObjectURL
/* forceDataSchema = */ compatibilityParams.disableCreateObjectURL
);
return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
ensureNotCancelled();
Expand Down
4 changes: 2 additions & 2 deletions web/pdf_print_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*/

import { PDFPrintServiceFactory, PDFViewerApplication } from "./app.js";
import { compatibilityParams } from "./app_options.js";
import { getXfaHtmlForPrinting } from "./print_utils.js";
import { viewerCompatibilityParams } from "./viewer_compatibility.js";

let activeService = null;
let overlayManager = null;
Expand Down Expand Up @@ -177,7 +177,7 @@ PDFPrintService.prototype = {
const scratchCanvas = this.scratchCanvas;
if (
"toBlob" in scratchCanvas &&
!viewerCompatibilityParams.disableCreateObjectURL
!compatibilityParams.disableCreateObjectURL
) {
scratchCanvas.toBlob(function (blob) {
img.src = URL.createObjectURL(blob);
Expand Down
51 changes: 0 additions & 51 deletions web/viewer_compatibility.js

This file was deleted.