Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(767)

Unified Diff: third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp

Issue 1911793003: drawImage throw when ImageBitmap is neutered (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clean up code Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp
diff --git a/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp b/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp
index 4c3f5f306b0f063272e0c5e3b6a02d28f50e878a..05cb0e501d8ad6a828ebeda134dc11b2106de734 100644
--- a/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp
+++ b/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp
@@ -853,9 +853,20 @@ static inline CanvasImageSource* toImageSourceInternal(const CanvasImageSourceUn
return nullptr;
}
+static bool imageSourceNeutered(CanvasImageSource* imageSource, ExceptionState& exceptionState)
Justin Novosad 2016/04/21 20:45:19 I think you should put this inside toImageSourceIn
xidachen 2016/04/22 01:58:13 Done.
+{
+ if (imageSource->isImageBitmap() && static_cast<ImageBitmap*>(imageSource)->isNeutered()) {
+ exceptionState.throwDOMException(InvalidStateError, String::format("The image source is neutered"));
+ return true;
+ }
+ return false;
+}
+
void BaseRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource, double x, double y, ExceptionState& exceptionState)
{
CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
+ if (imageSourceNeutered(imageSourceInternal, exceptionState))
+ return;
FloatSize defaultObjectSize(width(), height());
FloatSize sourceRectSize = imageSourceInternal->elementSize(defaultObjectSize);
FloatSize destRectSize = imageSourceInternal->defaultDestinationSize(defaultObjectSize);
@@ -866,6 +877,8 @@ void BaseRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource
double x, double y, double width, double height, ExceptionState& exceptionState)
{
CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
+ if (imageSourceNeutered(imageSourceInternal, exceptionState))
+ return;
FloatSize defaultObjectSize(this->width(), this->height());
FloatSize sourceRectSize = imageSourceInternal->elementSize(defaultObjectSize);
drawImage(imageSourceInternal, 0, 0, sourceRectSize.width(), sourceRectSize.height(), x, y, width, height, exceptionState);
@@ -876,6 +889,8 @@ void BaseRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource
double dx, double dy, double dw, double dh, ExceptionState& exceptionState)
{
CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
+ if (imageSourceNeutered(imageSourceInternal, exceptionState))
+ return;
drawImage(imageSourceInternal, sx, sy, sw, sh, dx, dy, dw, dh, exceptionState);
}

Powered by Google App Engine
This is Rietveld 408576698