Don't creates too many canvas
This commit is contained in:
@@ -77,6 +77,11 @@ class IconImage extends EventTarget {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.tainted_;
|
this.tainted_;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.taintedTestContext_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,12 +90,15 @@ class IconImage extends EventTarget {
|
|||||||
*/
|
*/
|
||||||
isTainted_() {
|
isTainted_() {
|
||||||
if (this.tainted_ === undefined && this.imageState_ === ImageState.LOADED) {
|
if (this.tainted_ === undefined && this.imageState_ === ImageState.LOADED) {
|
||||||
const context = createCanvasContext2D(1, 1);
|
if (!this.taintedTestContext_) {
|
||||||
context.drawImage(this.image_, 0, 0);
|
this.taintedTestContext_ = createCanvasContext2D(1, 1);
|
||||||
|
}
|
||||||
|
this.taintedTestContext_.drawImage(this.image_, 0, 0);
|
||||||
try {
|
try {
|
||||||
context.getImageData(0, 0, 1, 1);
|
this.taintedTestContext_.getImageData(0, 0, 1, 1);
|
||||||
this.tainted_ = false;
|
this.tainted_ = false;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
this.taintedTestContext_ = undefined;
|
||||||
this.tainted_ = true;
|
this.tainted_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user