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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/canvas2d/BaseRenderingContext2D.h" 5 #include "modules/canvas2d/BaseRenderingContext2D.h"
6 6
7 #include "bindings/core/v8/ExceptionMessages.h" 7 #include "bindings/core/v8/ExceptionMessages.h"
8 #include "bindings/core/v8/ExceptionState.h" 8 #include "bindings/core/v8/ExceptionState.h"
9 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 9 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
10 #include "core/css/parser/CSSParser.h" 10 #include "core/css/parser/CSSParser.h"
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 if (value.isHTMLVideoElement()) 846 if (value.isHTMLVideoElement())
847 return value.getAsHTMLVideoElement(); 847 return value.getAsHTMLVideoElement();
848 if (value.isHTMLCanvasElement()) 848 if (value.isHTMLCanvasElement())
849 return value.getAsHTMLCanvasElement(); 849 return value.getAsHTMLCanvasElement();
850 if (value.isImageBitmap()) 850 if (value.isImageBitmap())
851 return value.getAsImageBitmap(); 851 return value.getAsImageBitmap();
852 ASSERT_NOT_REACHED(); 852 ASSERT_NOT_REACHED();
853 return nullptr; 853 return nullptr;
854 } 854 }
855 855
856 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.
857 {
858 if (imageSource->isImageBitmap() && static_cast<ImageBitmap*>(imageSource)-> isNeutered()) {
859 exceptionState.throwDOMException(InvalidStateError, String::format("The image source is neutered"));
860 return true;
861 }
862 return false;
863 }
864
856 void BaseRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource , double x, double y, ExceptionState& exceptionState) 865 void BaseRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource , double x, double y, ExceptionState& exceptionState)
857 { 866 {
858 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource); 867 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
868 if (imageSourceNeutered(imageSourceInternal, exceptionState))
869 return;
859 FloatSize defaultObjectSize(width(), height()); 870 FloatSize defaultObjectSize(width(), height());
860 FloatSize sourceRectSize = imageSourceInternal->elementSize(defaultObjectSiz e); 871 FloatSize sourceRectSize = imageSourceInternal->elementSize(defaultObjectSiz e);
861 FloatSize destRectSize = imageSourceInternal->defaultDestinationSize(default ObjectSize); 872 FloatSize destRectSize = imageSourceInternal->defaultDestinationSize(default ObjectSize);
862 drawImage(imageSourceInternal, 0, 0, sourceRectSize.width(), sourceRectSize. height(), x, y, destRectSize.width(), destRectSize.height(), exceptionState); 873 drawImage(imageSourceInternal, 0, 0, sourceRectSize.width(), sourceRectSize. height(), x, y, destRectSize.width(), destRectSize.height(), exceptionState);
863 } 874 }
864 875
865 void BaseRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource , 876 void BaseRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource ,
866 double x, double y, double width, double height, ExceptionState& exceptionSt ate) 877 double x, double y, double width, double height, ExceptionState& exceptionSt ate)
867 { 878 {
868 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource); 879 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
880 if (imageSourceNeutered(imageSourceInternal, exceptionState))
881 return;
869 FloatSize defaultObjectSize(this->width(), this->height()); 882 FloatSize defaultObjectSize(this->width(), this->height());
870 FloatSize sourceRectSize = imageSourceInternal->elementSize(defaultObjectSiz e); 883 FloatSize sourceRectSize = imageSourceInternal->elementSize(defaultObjectSiz e);
871 drawImage(imageSourceInternal, 0, 0, sourceRectSize.width(), sourceRectSize. height(), x, y, width, height, exceptionState); 884 drawImage(imageSourceInternal, 0, 0, sourceRectSize.width(), sourceRectSize. height(), x, y, width, height, exceptionState);
872 } 885 }
873 886
874 void BaseRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource , 887 void BaseRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource ,
875 double sx, double sy, double sw, double sh, 888 double sx, double sy, double sw, double sh,
876 double dx, double dy, double dw, double dh, ExceptionState& exceptionState) 889 double dx, double dy, double dw, double dh, ExceptionState& exceptionState)
877 { 890 {
878 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource); 891 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
892 if (imageSourceNeutered(imageSourceInternal, exceptionState))
893 return;
879 drawImage(imageSourceInternal, sx, sy, sw, sh, dx, dy, dw, dh, exceptionStat e); 894 drawImage(imageSourceInternal, sx, sy, sw, sh, dx, dy, dw, dh, exceptionStat e);
880 } 895 }
881 896
882 bool BaseRenderingContext2D::shouldDrawImageAntialiased(const FloatRect& destRec t) const 897 bool BaseRenderingContext2D::shouldDrawImageAntialiased(const FloatRect& destRec t) const
883 { 898 {
884 if (!state().shouldAntialias()) 899 if (!state().shouldAntialias())
885 return false; 900 return false;
886 SkCanvas* c = drawingCanvas(); 901 SkCanvas* c = drawingCanvas();
887 ASSERT(c); 902 ASSERT(c);
888 903
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 return gradient; 1093 return gradient;
1079 } 1094 }
1080 1095
1081 CanvasPattern* BaseRenderingContext2D::createPattern(const CanvasImageSourceUnio n& imageSource, const String& repetitionType, ExceptionState& exceptionState) 1096 CanvasPattern* BaseRenderingContext2D::createPattern(const CanvasImageSourceUnio n& imageSource, const String& repetitionType, ExceptionState& exceptionState)
1082 { 1097 {
1083 Pattern::RepeatMode repeatMode = CanvasPattern::parseRepetitionType(repetiti onType, exceptionState); 1098 Pattern::RepeatMode repeatMode = CanvasPattern::parseRepetitionType(repetiti onType, exceptionState);
1084 if (exceptionState.hadException()) 1099 if (exceptionState.hadException())
1085 return nullptr; 1100 return nullptr;
1086 1101
1087 SourceImageStatus status; 1102 SourceImageStatus status;
1088 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource); 1103 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
Justin Novosad 2016/04/21 20:45:19 You forgot about this guy.
xidachen 2016/04/22 01:58:13 Done.
1089 FloatSize defaultObjectSize(width(), height()); 1104 FloatSize defaultObjectSize(width(), height());
1090 RefPtr<Image> imageForRendering = imageSourceInternal->getSourceImageForCanv as(&status, PreferNoAcceleration, SnapshotReasonCreatePattern, defaultObjectSize ); 1105 RefPtr<Image> imageForRendering = imageSourceInternal->getSourceImageForCanv as(&status, PreferNoAcceleration, SnapshotReasonCreatePattern, defaultObjectSize );
1091 1106
1092 switch (status) { 1107 switch (status) {
1093 case NormalSourceImageStatus: 1108 case NormalSourceImageStatus:
1094 break; 1109 break;
1095 case ZeroSizeCanvasSourceImageStatus: 1110 case ZeroSizeCanvasSourceImageStatus:
1096 exceptionState.throwDOMException(InvalidStateError, String::format("The canvas %s is 0.", imageSourceInternal->elementSize(defaultObjectSize).width() ? "height" : "width")); 1111 exceptionState.throwDOMException(InvalidStateError, String::format("The canvas %s is 0.", imageSourceInternal->elementSize(defaultObjectSize).width() ? "height" : "width"));
1097 return nullptr; 1112 return nullptr;
1098 case UndecodableSourceImageStatus: 1113 case UndecodableSourceImageStatus:
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1373 1388
1374 imageBuffer()->willOverwriteCanvas(); 1389 imageBuffer()->willOverwriteCanvas();
1375 } 1390 }
1376 1391
1377 DEFINE_TRACE(BaseRenderingContext2D) 1392 DEFINE_TRACE(BaseRenderingContext2D)
1378 { 1393 {
1379 visitor->trace(m_stateStack); 1394 visitor->trace(m_stateStack);
1380 } 1395 }
1381 1396
1382 } // namespace blink 1397 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698