From a6d4a9adc818df60bc0f6354579bde20e5c40524 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 11 Jun 2011 09:52:27 +0200 Subject: [PATCH] Bug 663194 - Calling drawImage with zero-size canvas should throw INVALID_STATE_ERR; r=sicking --- .../canvas/src/nsCanvasRenderingContext2D.cpp | 12 +++- content/canvas/test/Makefile.in | 1 + .../test/test_2d.drawImage.zerocanvas.html | 56 +++++++++++++++++++ .../html/content/public/nsHTMLCanvasElement.h | 7 +++ 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 content/canvas/test/test_2d.drawImage.zerocanvas.html diff --git a/content/canvas/src/nsCanvasRenderingContext2D.cpp b/content/canvas/src/nsCanvasRenderingContext2D.cpp index fa0127ddd40a..47b62fed6f84 100644 --- a/content/canvas/src/nsCanvasRenderingContext2D.cpp +++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp @@ -3291,8 +3291,14 @@ nsCanvasRenderingContext2D::DrawImage(nsIDOMElement *imgElt, float a1, return NS_ERROR_DOM_TYPE_MISMATCH_ERR; } - double sx,sy,sw,sh; - double dx,dy,dw,dh; + nsCOMPtr content = do_QueryInterface(imgElt); + nsHTMLCanvasElement* canvas = nsHTMLCanvasElement::FromContent(content); + if (canvas) { + nsIntSize size = canvas->GetSize(); + if (size.width == 0 || size.height == 0) { + return NS_ERROR_DOM_INVALID_STATE_ERR; + } + } gfxMatrix matrix; nsRefPtr pattern; @@ -3334,6 +3340,8 @@ nsCanvasRenderingContext2D::DrawImage(nsIDOMElement *imgElt, float a1, } } + double sx,sy,sw,sh; + double dx,dy,dw,dh; if (optional_argc == 0) { dx = a1; dy = a2; diff --git a/content/canvas/test/Makefile.in b/content/canvas/test/Makefile.in index 3d30e9b3d961..e848cfe373f4 100644 --- a/content/canvas/test/Makefile.in +++ b/content/canvas/test/Makefile.in @@ -79,6 +79,7 @@ _TEST_FILES_0 = \ test_2d.composite.uncovered.image.destination-in.html \ test_2d.composite.uncovered.image.source-in.html \ test_2d.composite.uncovered.image.source-out.html \ + test_2d.drawImage.zerocanvas.html \ test_toDataURL_lowercase_ascii.html \ test_toDataURL_parameters.html \ test_mozGetAsFile.html \ diff --git a/content/canvas/test/test_2d.drawImage.zerocanvas.html b/content/canvas/test/test_2d.drawImage.zerocanvas.html new file mode 100644 index 000000000000..e085051d7aa5 --- /dev/null +++ b/content/canvas/test/test_2d.drawImage.zerocanvas.html @@ -0,0 +1,56 @@ + +Canvas test: 2d.drawImage.zerocanvas + + + + +

FAIL (fallback content)

+ + diff --git a/content/html/content/public/nsHTMLCanvasElement.h b/content/html/content/public/nsHTMLCanvasElement.h index 69ac3f6321c0..1f624154ae34 100644 --- a/content/html/content/public/nsHTMLCanvasElement.h +++ b/content/html/content/public/nsHTMLCanvasElement.h @@ -68,6 +68,13 @@ public: nsHTMLCanvasElement(already_AddRefed aNodeInfo); virtual ~nsHTMLCanvasElement(); + static nsHTMLCanvasElement* FromContent(nsIContent* aPossibleCanvas) + { + if (!aPossibleCanvas || !aPossibleCanvas->IsHTML(nsGkAtoms::canvas)) { + return nsnull; + } + return static_cast(aPossibleCanvas); + } // nsISupports NS_DECL_ISUPPORTS_INHERITED