From f2bf0ccc4f3fd89a6da59341c3a1ab7444e0154d Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Mon, 31 Jul 2023 10:47:18 +0200 Subject: [PATCH] [Editor] Limit image types to the ones supported by the browser (bug 1846230) --- src/display/editor/stamp.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/display/editor/stamp.js b/src/display/editor/stamp.js index 8dac89005..b0d3d2dc8 100644 --- a/src/display/editor/stamp.js +++ b/src/display/editor/stamp.js @@ -13,8 +13,8 @@ * limitations under the License. */ +import { AnnotationEditorType, shadow } from "../../shared/util.js"; import { AnnotationEditor } from "./editor.js"; -import { AnnotationEditorType } from "../../shared/util.js"; import { PixelsPerInch } from "../display_utils.js"; import { StampAnnotationElement } from "../annotation_layer.js"; @@ -45,6 +45,27 @@ class StampEditor extends AnnotationEditor { this.#bitmapUrl = params.bitmapUrl; } + static get supportedTypes() { + // See https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types + // to know which types are supported by the browser. + const types = [ + "apng", + "avif", + "bmp", + "gif", + "jpeg", + "png", + "svg+xml", + "webp", + "x-icon", + ]; + return shadow( + this, + "supportedTypes", + types.map(type => `image/${type}`).join(",") + ); + } + #getBitmap() { if (this.#bitmapId) { this._uiManager.imageManager.getFromId(this.#bitmapId).then(data => { @@ -86,7 +107,7 @@ class StampEditor extends AnnotationEditor { document.body.append(input); } input.type = "file"; - input.accept = "image/*"; + input.accept = StampEditor.supportedTypes; this.#bitmapPromise = new Promise(resolve => { input.addEventListener("change", async () => { this.#bitmapPromise = null;