diff --git a/web/app_options.js b/web/app_options.js index 5f6d4f076..61311172c 100644 --- a/web/app_options.js +++ b/web/app_options.js @@ -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; + } + } } } diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index be4950d8c..adcbd6d78 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -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;