Skip to content

Commit

Permalink
[Editor] Always use the data url when loading a SVG in order to avoid…
Browse files Browse the repository at this point in the history
… CSP issue (bug 1843255)
  • Loading branch information
calixteman committed Jul 13, 2023
1 parent 762d86a commit 3964ef2
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/display/editor/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,25 +110,19 @@ class ImageManager {
// Unfortunately, createImageBitmap doesn't work with SVG images.
// (see https://bugzilla.mozilla.org/1841972).
const fileReader = new FileReader();
const dataUrlPromise = new Promise(resolve => {
fileReader.onload = () => {
data.svgUrl = fileReader.result;
resolve();
};
});
fileReader.readAsDataURL(image);
const url = URL.createObjectURL(image);
image = new Image();
const imageElement = new Image();
const imagePromise = new Promise(resolve => {
image.onload = () => {
URL.revokeObjectURL(url);
data.bitmap = image;
imageElement.onload = () => {
data.bitmap = imageElement;
data.isSvg = true;
resolve();
};
});
image.src = url;
await Promise.all([imagePromise, dataUrlPromise]);
fileReader.onload = () => {
imageElement.src = data.svgUrl = fileReader.result;
};
fileReader.readAsDataURL(image);
await imagePromise;
} else {
data.bitmap = await createImageBitmap(image);
}
Expand Down

0 comments on commit 3964ef2

Please sign in to comment.