Don't render SVG nodes if it taints canvas

This commit is contained in:
Niklas von Hertzen
2017-08-13 13:11:03 +08:00
parent c765e2042f
commit 37a9249a4a
3 changed files with 47 additions and 10 deletions

View File

@@ -25,6 +25,21 @@ const testRangeBounds = document => {
return false;
};
const testSVG = document => {
const img = new Image();
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
img.src = `data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'></svg>`;
try {
ctx.drawImage(img, 0, 0);
canvas.toDataURL();
} catch (e) {
return false;
}
return true;
};
const FEATURES = {
// $FlowFixMe - get/set properties not yet supported
get SUPPORT_RANGE_BOUNDS() {
@@ -32,6 +47,12 @@ const FEATURES = {
const value = testRangeBounds(document);
Object.defineProperty(FEATURES, 'SUPPORT_RANGE_BOUNDS', {value});
return value;
},
get SUPPORT_SVG_DRAWING() {
'use strict';
const value = testSVG(document);
Object.defineProperty(FEATURES, 'SUPPORT_SVG_DRAWING', {value});
return value;
}
};