mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 17:30:09 +02:00
Limit all compatibilityParams
handling to the GENERIC viewer
With recent improvements to the `AppOptions`, e.g. with better validation and testing, one remaining "annoyance" is the `compatibilityParams` handling. Especially since there's only *a single* parameter left, limited to GENERIC builds. To further reduce the amount of unnecessary code in e.g. the Firefox PDF Viewer, we can move the `compatibilityParams` handling into the user-options instead since that keeps the previous precedence order between default/user-options.
This commit is contained in:
parent
55db43966e
commit
62568b27dc
2 changed files with 31 additions and 16 deletions
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue