b=386799, crash with zero-width canvas, r=stuart,sr=roc
authorvladimir@pobox.com
Wed, 18 Jul 2007 07:40:19 -0700
changeset 3610 4107eb58583e3bfc72755b230146e7ade09dbd54
parent 3609 b93288890e5d4bfb9d12fad843f7affb622e90cb
child 3611 9404837c389e8e2dbfbe54bae3ecc1f462fec92d
push idunknown
push userunknown
push dateunknown
reviewersstuart, roc
bugs386799
milestone1.9a7pre
b=386799, crash with zero-width canvas, r=stuart,sr=roc
layout/generic/nsHTMLCanvasFrame.cpp
widget/src/cocoa/nsNativeThemeCocoa.mm
--- a/layout/generic/nsHTMLCanvasFrame.cpp
+++ b/layout/generic/nsHTMLCanvasFrame.cpp
@@ -183,16 +183,20 @@ nsHTMLCanvasFrame::PaintCanvas(nsIRender
                                const nsRect& aDirtyRect, nsPoint aPt) 
 {
   nsRect inner = GetInnerArea() + aPt;
 
   nsCOMPtr<nsICanvasElement> canvas(do_QueryInterface(GetContent()));
   if (!canvas)
     return;
 
+  // anything to do?
+  if (inner.width == 0 || inner.height == 0)
+    return;
+
   nsSize canvasSize = GetCanvasSize();
   nsSize sizeAppUnits(PresContext()->DevPixelsToAppUnits(canvasSize.width),
                       PresContext()->DevPixelsToAppUnits(canvasSize.height));
 
   // XXXvlad clip to aDirtyRect!
 
   if (inner.Size() != sizeAppUnits)
   {
--- a/widget/src/cocoa/nsNativeThemeCocoa.mm
+++ b/widget/src/cocoa/nsNativeThemeCocoa.mm
@@ -507,31 +507,35 @@ nsNativeThemeCocoa::DrawWidgetBackground
     aContext->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
   if (!thebesCtx)
     return NS_ERROR_FAILURE;
 
   thebesCtx->UpdateSurfaceClip();
 
   double offsetX = 0.0, offsetY = 0.0;
   nsRefPtr<gfxASurface> thebesSurface = thebesCtx->CurrentSurface(&offsetX, &offsetY);
+  if (thebesSurface->CairoStatus() != 0) {
+    NS_WARNING("Got Cairo surface with nonzero error status");
+    return NS_ERROR_FAILURE;
+  }
+
   if (thebesSurface->GetType() != gfxASurface::SurfaceTypeQuartz) {
-    fprintf(stderr, "Expected surface of type Quartz, got %d\n",
-            thebesSurface->GetType());
+    NS_WARNING("Expected surface of type Quartz, got somthing else");
     return NS_ERROR_FAILURE;
   }
 
   gfxMatrix mat = thebesCtx->CurrentMatrix();
   gfxQuartzSurface* quartzSurf = (gfxQuartzSurface*) (thebesSurface.get());
   CGContextRef cgContext = quartzSurf->GetCGContext();
 
   //fprintf (stderr, "surface: %p cgContext: %p\n", quartzSurf, cgContext);
 
-  if (cgContext == nsnull ||
-      ((((unsigned long)cgContext) & 0xffff) == 0x3f3f)) {
-    fprintf (stderr, "********** Invalid CGContext!\n");
+  if (cgContext == nsnull) {
+    NS_WARNING("Invalid CGContext!");
+    return NS_ERROR_FAILURE;
   }
 
   // Eventually we can just do a GetCTM and restore it with SetCTM,
   // but for now do a full save/restore
   CGAffineTransform mm0 = CGContextGetCTM(cgContext);
 
   CGContextSaveGState(cgContext);
   //CGContextSetCTM(cgContext, CGAffineTransformIdentity);