Backed out changeset 6ba917df6b41 (bug 997014)
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Thu, 17 Apr 2014 08:43:35 +0200
changeset 179359 cf6ccdc2e849e6718b95d355f5f33034c4b39b9f
parent 179358 6ba917df6b413f2b56d2f2bb42b0107e3315641d
child 179360 72dd3220abbee756db6af6ec9c3f0fa6cc6971ad
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
bugs997014
milestone31.0a1
backs out6ba917df6b413f2b56d2f2bb42b0107e3315641d
Backed out changeset 6ba917df6b41 (bug 997014)
content/canvas/src/CanvasRenderingContext2D.cpp
--- a/content/canvas/src/CanvasRenderingContext2D.cpp
+++ b/content/canvas/src/CanvasRenderingContext2D.cpp
@@ -3211,16 +3211,43 @@ CanvasRenderingContext2D::DrawImage(cons
   gfxIntSize imgSize;
 
   Element* element;
 
   EnsureTarget();
   if (image.IsHTMLCanvasElement()) {
     HTMLCanvasElement* canvas = &image.GetAsHTMLCanvasElement();
     element = canvas;
+    nsIntSize size = canvas->GetSize();
+    if (size.width == 0 || size.height == 0) {
+      error.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
+      return;
+    }
+
+    // Special case for Canvas, which could be an Azure canvas!
+    nsICanvasRenderingContextInternal *srcCanvas = canvas->GetContextAtIndex(0);
+    if (srcCanvas == this) {
+      // Self-copy.
+      srcSurf = mTarget->Snapshot();
+      imgSize = gfxIntSize(mWidth, mHeight);
+    } else if (srcCanvas) {
+      // This might not be an Azure canvas!
+      srcSurf = srcCanvas->GetSurfaceSnapshot();
+
+      if (srcSurf) {
+        if (mCanvasElement) {
+          // Do security check here.
+          CanvasUtils::DoDrawImageSecurityCheck(mCanvasElement,
+                                                element->NodePrincipal(),
+                                                canvas->IsWriteOnly(),
+                                                false);
+        }
+        imgSize = gfxIntSize(srcSurf->GetSize().width, srcSurf->GetSize().height);
+      }
+    }
   } else {
     if (image.IsHTMLImageElement()) {
       HTMLImageElement* img = &image.GetAsHTMLImageElement();
       element = img;
     } else {
       HTMLVideoElement* video = &image.GetAsHTMLVideoElement();
       element = video;
     }