1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Merge pull request #17861 from Snuffleupagus/compatibilityParams-init

Limit all `compatibilityParams` handling to the GENERIC viewer
This commit is contained in:
Tim van der Meij 2024-04-02 14:47:37 +02:00 committed by GitHub
commit 10312105a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 16 deletions

View file

@ -13,8 +13,9 @@
* limitations under the License.
*/
const compatibilityParams = Object.create(null);
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
// eslint-disable-next-line no-var
var compatibilityParams = Object.create(null);
if (
typeof PDFJSDev !== "undefined" &&
PDFJSDev.test("LIB") &&
@ -417,6 +418,14 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
const userOptions = Object.create(null);
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
// Apply any compatibility-values to the user-options,
// see also `AppOptions.remove` below.
for (const name in compatibilityParams) {
userOptions[name] = compatibilityParams[name];
}
}
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING || LIB")) {
// Ensure that the `defaultOptions` are correctly specified.
for (const name in defaultOptions) {
@ -429,7 +438,10 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING || LIB")) {
if (kind & OptionKind.BROWSER) {
throw new Error(`Cannot mix "PREFERENCE" and "BROWSER" kind: ${name}`);
}
if (compatibilityParams[name] !== undefined) {
if (
typeof compatibilityParams === "object" &&
compatibilityParams[name] !== undefined
) {
throw new Error(
`Should not have compatibility-value for "PREFERENCE" kind: ${name}`
);
@ -451,17 +463,8 @@ class AppOptions {
throw new Error("Cannot initialize AppOptions.");
}
static getCompat(name) {
return compatibilityParams[name] ?? undefined;
}
static get(name) {
return (
userOptions[name] ??
compatibilityParams[name] ??
defaultOptions[name]?.value ??
undefined
);
return userOptions[name] ?? defaultOptions[name]?.value ?? undefined;
}
static getAll(kind = null, defaultOnly = false) {
@ -474,7 +477,7 @@ class AppOptions {
}
options[name] = defaultOnly
? defaultOption.value
: userOptions[name] ?? compatibilityParams[name] ?? defaultOption.value;
: userOptions[name] ?? defaultOption.value;
}
return options;
}
@ -490,11 +493,16 @@ class AppOptions {
// opt-out of having the `Preferences` override existing `AppOptions`.
return;
}
if (Object.keys(userOptions).length) {
for (const name in userOptions) {
// Ignore any compatibility-values in the user-options.
if (compatibilityParams[name] !== undefined) {
continue;
}
console.warn(
"setAll: The Preferences may override manually set AppOptions; " +
'please use the "disablePreferences"-option in order to prevent that.'
);
break;
}
}
@ -505,6 +513,14 @@ class AppOptions {
static remove(name) {
delete userOptions[name];
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
// Re-apply a compatibility-value, if it exists, to the user-options.
const val = compatibilityParams[name];
if (val !== undefined) {
userOptions[name] = val;
}
}
}
}

View file

@ -161,8 +161,7 @@ class PDFPageView {
options.annotationMode ?? AnnotationMode.ENABLE_FORMS;
this.imageResourcesPath = options.imageResourcesPath || "";
this.maxCanvasPixels =
options.maxCanvasPixels ??
(AppOptions.getCompat("maxCanvasPixels") || 2 ** 25);
options.maxCanvasPixels ?? AppOptions.get("maxCanvasPixels");
this.pageColors = options.pageColors || null;
this.eventBus = options.eventBus;