Merge pull request #13804 from Snuffleupagus/move-viewer-compatibilityParams

Move the `compatibilityParams` into the `web/app_options.js` file
This commit is contained in:
Tim van der Meij 2021-07-27 22:13:40 +02:00 committed by GitHub
commit d3dffa7fa3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 47 additions and 67 deletions

View File

@ -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: ".",
}),
]);

View File

@ -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,
@ -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;
@ -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 };

View File

@ -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,
@ -95,7 +127,7 @@ const defaultOptions = {
maxCanvasPixels: {
/** @type {number} */
value: 16777216,
compatibility: viewerCompatibilityParams.maxCanvasPixels,
compatibility: compatibilityParams.maxCanvasPixels,
kind: OptionKind.VIEWER,
},
pdfBugEnabled: {
@ -348,4 +380,4 @@ class AppOptions {
}
}
export { AppOptions, OptionKind };
export { AppOptions, compatibilityParams, OptionKind };

View File

@ -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(
@ -58,7 +58,7 @@ class DownloadManager {
const blobUrl = createObjectURL(
data,
contentType,
viewerCompatibilityParams.disableCreateObjectURL
compatibilityParams.disableCreateObjectURL
);
download(blobUrl, filename);
}
@ -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 }));
@ -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;

View File

@ -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
@ -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}
@ -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();

View File

@ -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;
@ -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);

View File

@ -1,51 +0,0 @@
/* Copyright 2018 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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);
// Checks if possible to use URL.createObjectURL()
// Support: IE, 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 viewerCompatibilityParams = Object.freeze(compatibilityParams);
export { viewerCompatibilityParams };