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

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: address comments 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
« no previous file with comments | « third_party/WebKit/Source/core/html/canvas/CanvasImageSource.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 821 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 FloatSize offset = dstRect->location() - scaledSrcLocation; 832 FloatSize offset = dstRect->location() - scaledSrcLocation;
833 833
834 srcRect->intersect(imageRect); 834 srcRect->intersect(imageRect);
835 835
836 // To clip the destination rectangle in the same proportion, transform the c lipped src rect 836 // To clip the destination rectangle in the same proportion, transform the c lipped src rect
837 *dstRect = *srcRect; 837 *dstRect = *srcRect;
838 dstRect->scale(scale.width(), scale.height()); 838 dstRect->scale(scale.width(), scale.height());
839 dstRect->move(offset); 839 dstRect->move(offset);
840 } 840 }
841 841
842 static inline CanvasImageSource* toImageSourceInternal(const CanvasImageSourceUn ion& value) 842 static inline CanvasImageSource* toImageSourceInternal(const CanvasImageSourceUn ion& value, ExceptionState& exceptionState)
843 { 843 {
844 if (value.isHTMLImageElement()) 844 if (value.isHTMLImageElement())
845 return value.getAsHTMLImageElement(); 845 return value.getAsHTMLImageElement();
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 if (static_cast<ImageBitmap*>(value.getAsImageBitmap())->isNeutered()) {
852 exceptionState.throwDOMException(InvalidStateError, String::format(" The image source is neutered"));
853 return nullptr;
854 }
851 return value.getAsImageBitmap(); 855 return value.getAsImageBitmap();
856 }
852 ASSERT_NOT_REACHED(); 857 ASSERT_NOT_REACHED();
853 return nullptr; 858 return nullptr;
854 } 859 }
855 860
856 void BaseRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource , double x, double y, ExceptionState& exceptionState) 861 void BaseRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource , double x, double y, ExceptionState& exceptionState)
857 { 862 {
858 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource); 863 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource, exceptionState);
864 if (!imageSourceInternal)
865 return;
859 FloatSize defaultObjectSize(width(), height()); 866 FloatSize defaultObjectSize(width(), height());
860 FloatSize sourceRectSize = imageSourceInternal->elementSize(defaultObjectSiz e); 867 FloatSize sourceRectSize = imageSourceInternal->elementSize(defaultObjectSiz e);
861 FloatSize destRectSize = imageSourceInternal->defaultDestinationSize(default ObjectSize); 868 FloatSize destRectSize = imageSourceInternal->defaultDestinationSize(default ObjectSize);
862 drawImage(imageSourceInternal, 0, 0, sourceRectSize.width(), sourceRectSize. height(), x, y, destRectSize.width(), destRectSize.height(), exceptionState); 869 drawImage(imageSourceInternal, 0, 0, sourceRectSize.width(), sourceRectSize. height(), x, y, destRectSize.width(), destRectSize.height(), exceptionState);
863 } 870 }
864 871
865 void BaseRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource , 872 void BaseRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource ,
866 double x, double y, double width, double height, ExceptionState& exceptionSt ate) 873 double x, double y, double width, double height, ExceptionState& exceptionSt ate)
867 { 874 {
868 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource); 875 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource, exceptionState);
876 if (!imageSourceInternal)
877 return;
869 FloatSize defaultObjectSize(this->width(), this->height()); 878 FloatSize defaultObjectSize(this->width(), this->height());
870 FloatSize sourceRectSize = imageSourceInternal->elementSize(defaultObjectSiz e); 879 FloatSize sourceRectSize = imageSourceInternal->elementSize(defaultObjectSiz e);
871 drawImage(imageSourceInternal, 0, 0, sourceRectSize.width(), sourceRectSize. height(), x, y, width, height, exceptionState); 880 drawImage(imageSourceInternal, 0, 0, sourceRectSize.width(), sourceRectSize. height(), x, y, width, height, exceptionState);
872 } 881 }
873 882
874 void BaseRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource , 883 void BaseRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource ,
875 double sx, double sy, double sw, double sh, 884 double sx, double sy, double sw, double sh,
876 double dx, double dy, double dw, double dh, ExceptionState& exceptionState) 885 double dx, double dy, double dw, double dh, ExceptionState& exceptionState)
877 { 886 {
878 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource); 887 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource, exceptionState);
888 if (!imageSourceInternal)
889 return;
879 drawImage(imageSourceInternal, sx, sy, sw, sh, dx, dy, dw, dh, exceptionStat e); 890 drawImage(imageSourceInternal, sx, sy, sw, sh, dx, dy, dw, dh, exceptionStat e);
880 } 891 }
881 892
882 bool BaseRenderingContext2D::shouldDrawImageAntialiased(const FloatRect& destRec t) const 893 bool BaseRenderingContext2D::shouldDrawImageAntialiased(const FloatRect& destRec t) const
883 { 894 {
884 if (!state().shouldAntialias()) 895 if (!state().shouldAntialias())
885 return false; 896 return false;
886 SkCanvas* c = drawingCanvas(); 897 SkCanvas* c = drawingCanvas();
887 ASSERT(c); 898 ASSERT(c);
888 899
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 return gradient; 1089 return gradient;
1079 } 1090 }
1080 1091
1081 CanvasPattern* BaseRenderingContext2D::createPattern(const CanvasImageSourceUnio n& imageSource, const String& repetitionType, ExceptionState& exceptionState) 1092 CanvasPattern* BaseRenderingContext2D::createPattern(const CanvasImageSourceUnio n& imageSource, const String& repetitionType, ExceptionState& exceptionState)
1082 { 1093 {
1083 Pattern::RepeatMode repeatMode = CanvasPattern::parseRepetitionType(repetiti onType, exceptionState); 1094 Pattern::RepeatMode repeatMode = CanvasPattern::parseRepetitionType(repetiti onType, exceptionState);
1084 if (exceptionState.hadException()) 1095 if (exceptionState.hadException())
1085 return nullptr; 1096 return nullptr;
1086 1097
1087 SourceImageStatus status; 1098 SourceImageStatus status;
1088 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource); 1099 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource, exceptionState);
1100 if (!imageSourceInternal)
1101 return nullptr;
1089 FloatSize defaultObjectSize(width(), height()); 1102 FloatSize defaultObjectSize(width(), height());
1090 RefPtr<Image> imageForRendering = imageSourceInternal->getSourceImageForCanv as(&status, PreferNoAcceleration, SnapshotReasonCreatePattern, defaultObjectSize ); 1103 RefPtr<Image> imageForRendering = imageSourceInternal->getSourceImageForCanv as(&status, PreferNoAcceleration, SnapshotReasonCreatePattern, defaultObjectSize );
1091 1104
1092 switch (status) { 1105 switch (status) {
1093 case NormalSourceImageStatus: 1106 case NormalSourceImageStatus:
1094 break; 1107 break;
1095 case ZeroSizeCanvasSourceImageStatus: 1108 case ZeroSizeCanvasSourceImageStatus:
1096 exceptionState.throwDOMException(InvalidStateError, String::format("The canvas %s is 0.", imageSourceInternal->elementSize(defaultObjectSize).width() ? "height" : "width")); 1109 exceptionState.throwDOMException(InvalidStateError, String::format("The canvas %s is 0.", imageSourceInternal->elementSize(defaultObjectSize).width() ? "height" : "width"));
1097 return nullptr; 1110 return nullptr;
1098 case UndecodableSourceImageStatus: 1111 case UndecodableSourceImageStatus:
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1373 1386
1374 imageBuffer()->willOverwriteCanvas(); 1387 imageBuffer()->willOverwriteCanvas();
1375 } 1388 }
1376 1389
1377 DEFINE_TRACE(BaseRenderingContext2D) 1390 DEFINE_TRACE(BaseRenderingContext2D)
1378 { 1391 {
1379 visitor->trace(m_stateStack); 1392 visitor->trace(m_stateStack);
1380 } 1393 }
1381 1394
1382 } // namespace blink 1395 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/canvas/CanvasImageSource.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698