Skip to content

Commit

Permalink
Merge pull request #16686 from calixteman/bug1843255
Browse files Browse the repository at this point in the history
[Editor] Always use the data url when loading a SVG in order to avoid CSP issue (bug 1843255)
  • Loading branch information
calixteman authored Jul 13, 2023
2 parents 762d86a + ed42577 commit 36fc34e
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/display/editor/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,25 +110,20 @@ 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 imagePromise = new Promise(resolve => {
image.onload = () => {
URL.revokeObjectURL(url);
data.bitmap = image;
const imageElement = new Image();
const imagePromise = new Promise((resolve, reject) => {
imageElement.onload = () => {
data.bitmap = imageElement;
data.isSvg = true;
resolve();
};
fileReader.onload = () => {
imageElement.src = data.svgUrl = fileReader.result;
};
imageElement.onerror = fileReader.onerror = reject;
});
image.src = url;
await Promise.all([imagePromise, dataUrlPromise]);
fileReader.readAsDataURL(image);
await imagePromise;
} else {
data.bitmap = await createImageBitmap(image);
}
Expand Down

0 comments on commit 36fc34e

Please sign in to comment.