diff --git a/addons/web_editor/static/src/js/common/utils.js b/addons/web_editor/static/src/js/common/utils.js index c96c832fcc5..16fa0e08db0 100644 --- a/addons/web_editor/static/src/js/common/utils.js +++ b/addons/web_editor/static/src/js/common/utils.js @@ -87,6 +87,7 @@ const DEFAULT_PALETTE = { const BACKGROUND_IMAGE_ATTRIBUTES = new Set([ "originalId", "originalSrc", "mimetype", "resizeWidth", "glFilter", "quality", "bgSrc", "filterOptions", + "mimetypeBeforeConversion", ]); /** diff --git a/addons/web_editor/static/src/js/editor/image_processing.js b/addons/web_editor/static/src/js/editor/image_processing.js index 2c688b62ca3..0aa452236f4 100644 --- a/addons/web_editor/static/src/js/editor/image_processing.js +++ b/addons/web_editor/static/src/js/editor/image_processing.js @@ -443,7 +443,9 @@ export async function activateCropper(image, aspectRatio, dataset) { export async function loadImageInfo(img, rpc, attachmentSrc = '') { const src = attachmentSrc || img.getAttribute('src'); // If there is a marked originalSrc, the data is already loaded. - if (img.dataset.originalSrc || !src) { + // If the image does not have the "mimetypeBeforeConversion" attribute, it + // has to be added. + if ((img.dataset.originalSrc && img.dataset.mimetypeBeforeConversion) || !src) { return; } @@ -465,9 +467,14 @@ export async function loadImageInfo(img, rpc, attachmentSrc = '') { // The "redirect" check is for when it is a redirect image attachment due to // an external URL upload. if (original && original.image_src && !/\/web\/image\/\d+-redirect\//.test(original.image_src)) { + if (!img.dataset.mimetype) { + // The mimetype has to be added only if it is not already present as + // we want to avoid to reset a mimetype set by the user. + img.dataset.mimetype = original.mimetype; + } img.dataset.originalId = original.id; img.dataset.originalSrc = original.image_src; - img.dataset.mimetype = original.mimetype; + img.dataset.mimetypeBeforeConversion = original.mimetype; } } diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index e5f301861e3..0b85cea88ca 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -5780,9 +5780,9 @@ const ImageHandlerOption = SnippetOptionWidget.extend({ }; widths[img.naturalWidth] = [_t("%spx", img.naturalWidth), 'image/webp']; widths[optimizedWidth] = [_t("%spx (Suggested)", optimizedWidth), 'image/webp']; - const imgMimetype = this._getImageMimetype(img); - widths[maxWidth] = [_t("%spx (Original)", maxWidth), imgMimetype]; - if (imgMimetype !== 'image/webp') { + const mimetypeBeforeConversion = img.dataset.mimetypeBeforeConversion; + widths[maxWidth] = [_t("%spx (Original)", maxWidth), mimetypeBeforeConversion]; + if (mimetypeBeforeConversion !== "image/webp") { // Avoid a key collision by subtracting 0.1 - putting the webp // above the original format one of the same size. widths[maxWidth - 0.1] = [_t("%spx", maxWidth), 'image/webp']; diff --git a/odoo/tools/mail.py b/odoo/tools/mail.py index 1c9881306ae..b9a9e6f48ae 100644 --- a/odoo/tools/mail.py +++ b/odoo/tools/mail.py @@ -37,6 +37,7 @@ safe_attrs = clean.defs.safe_attrs | frozenset( 'data-class', 'data-mimetype', 'data-original-src', 'data-original-id', 'data-gl-filter', 'data-quality', 'data-resize-width', 'data-shape', 'data-shape-colors', 'data-file-name', 'data-original-mimetype', 'data-behavior-props', 'data-prop-name', # knowledge commands + 'data-mimetype-before-conversion', ]) SANITIZE_TAGS = { # allow new semantic HTML5 tags