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. * limitations under the License.
*/ */
const compatibilityParams = Object.create(null);
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
// eslint-disable-next-line no-var
var compatibilityParams = Object.create(null);
if ( if (
typeof PDFJSDev !== "undefined" && typeof PDFJSDev !== "undefined" &&
PDFJSDev.test("LIB") && PDFJSDev.test("LIB") &&
@ -417,6 +418,14 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
const userOptions = Object.create(null); 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")) { if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING || LIB")) {
// Ensure that the `defaultOptions` are correctly specified. // Ensure that the `defaultOptions` are correctly specified.
for (const name in defaultOptions) { for (const name in defaultOptions) {
@ -429,7 +438,10 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING || LIB")) {
if (kind & OptionKind.BROWSER) { if (kind & OptionKind.BROWSER) {
throw new Error(`Cannot mix "PREFERENCE" and "BROWSER" kind: ${name}`); throw new Error(`Cannot mix "PREFERENCE" and "BROWSER" kind: ${name}`);
} }
if (compatibilityParams[name] !== undefined) { if (
typeof compatibilityParams === "object" &&
compatibilityParams[name] !== undefined
) {
throw new Error( throw new Error(
`Should not have compatibility-value for "PREFERENCE" kind: ${name}` `Should not have compatibility-value for "PREFERENCE" kind: ${name}`
); );
@ -451,17 +463,8 @@ class AppOptions {
throw new Error("Cannot initialize AppOptions."); throw new Error("Cannot initialize AppOptions.");
} }
static getCompat(name) {
return compatibilityParams[name] ?? undefined;
}
static get(name) { static get(name) {
return ( return userOptions[name] ?? defaultOptions[name]?.value ?? undefined;
userOptions[name] ??
compatibilityParams[name] ??
defaultOptions[name]?.value ??
undefined
);
} }
static getAll(kind = null, defaultOnly = false) { static getAll(kind = null, defaultOnly = false) {
@ -474,7 +477,7 @@ class AppOptions {
} }
options[name] = defaultOnly options[name] = defaultOnly
? defaultOption.value ? defaultOption.value
: userOptions[name] ?? compatibilityParams[name] ?? defaultOption.value; : userOptions[name] ?? defaultOption.value;
} }
return options; return options;
} }
@ -490,11 +493,16 @@ class AppOptions {
// opt-out of having the `Preferences` override existing `AppOptions`. // opt-out of having the `Preferences` override existing `AppOptions`.
return; 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( console.warn(
"setAll: The Preferences may override manually set AppOptions; " + "setAll: The Preferences may override manually set AppOptions; " +
'please use the "disablePreferences"-option in order to prevent that.' 'please use the "disablePreferences"-option in order to prevent that.'
); );
break;
} }
} }
@ -505,6 +513,14 @@ class AppOptions {
static remove(name) { static remove(name) {
delete userOptions[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; options.annotationMode ?? AnnotationMode.ENABLE_FORMS;
this.imageResourcesPath = options.imageResourcesPath || ""; this.imageResourcesPath = options.imageResourcesPath || "";
this.maxCanvasPixels = this.maxCanvasPixels =
options.maxCanvasPixels ?? options.maxCanvasPixels ?? AppOptions.get("maxCanvasPixels");
(AppOptions.getCompat("maxCanvasPixels") || 2 ** 25);
this.pageColors = options.pageColors || null; this.pageColors = options.pageColors || null;
this.eventBus = options.eventBus; this.eventBus = options.eventBus;