Bug 800603: Just check rv (not rv & outparam) after calling imgIRequest:GetImage & GetImagePrincipal. r=jrmuizel
authorDaniel Holbert <dholbert@cs.stanford.edu>
Tue, 16 Oct 2012 16:05:54 -0700
changeset 110615 3de1ec1e38cfcb666de5ae9fe2558b0245a2eccb
parent 110614 2f52467023f2ba5cd2dbfbf3eef59b0680f4180b
child 110616 70016bc36b452a067cb4d9cdcd1d6de298a2aaac
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersjrmuizel
bugs800603
milestone19.0a1
Bug 800603: Just check rv (not rv & outparam) after calling imgIRequest:GetImage & GetImagePrincipal. r=jrmuizel
layout/base/nsCSSRendering.cpp
layout/base/nsLayoutUtils.cpp
layout/base/nsRefreshDriver.cpp
--- a/layout/base/nsCSSRendering.cpp
+++ b/layout/base/nsCSSRendering.cpp
@@ -2829,18 +2829,18 @@ DrawBorderImage(nsPresContext*       aPr
   ImageLoader* loader = aPresContext->Document()->StyleImageLoader();
 
   // If this fails there's not much we can do ...
   loader->AssociateRequestToFrame(req, aForFrame);
 
   // Get the actual image.
 
   nsCOMPtr<imgIContainer> imgContainer;
-  req->GetImage(getter_AddRefs(imgContainer));
-  NS_ASSERTION(imgContainer, "no image to draw");
+  DebugOnly<nsresult> rv = req->GetImage(getter_AddRefs(imgContainer));
+  NS_ASSERTION(NS_SUCCEEDED(rv) && imgContainer, "no image to draw");
 
   nsIntSize imageSize;
   if (NS_FAILED(imgContainer->GetWidth(&imageSize.width))) {
     imageSize.width =
       nsPresContext::AppUnitsToIntCSSPixels(aBorderArea.width);
   }
   if (NS_FAILED(imgContainer->GetHeight(&imageSize.height))) {
     imageSize.height =
@@ -4028,28 +4028,30 @@ nsImageRenderer::PrepareImage()
     if (!mImage->IsComplete()) {
       // We can not prepare the image for rendering if it is not fully loaded.
       //
       // Special case: If we requested a sync decode and we have an image, push
       // on through because the Draw() will do a sync decode then
       nsCOMPtr<imgIContainer> img;
       if (!((mFlags & FLAG_SYNC_DECODE_IMAGES) &&
             (mType == eStyleImageType_Image) &&
-            (NS_SUCCEEDED(mImage->GetImageData()->GetImage(getter_AddRefs(img))) && img)))
+            (NS_SUCCEEDED(mImage->GetImageData()->GetImage(getter_AddRefs(img))))))
         return false;
     }
   }
 
   switch (mType) {
     case eStyleImageType_Image:
     {
       nsCOMPtr<imgIContainer> srcImage;
-      mImage->GetImageData()->GetImage(getter_AddRefs(srcImage));
-      NS_ABORT_IF_FALSE(srcImage, "If srcImage is null, mImage->IsComplete() "
-                                  "should have returned false");
+      DebugOnly<nsresult> rv =
+        mImage->GetImageData()->GetImage(getter_AddRefs(srcImage));
+      NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) && srcImage,
+                        "If GetImage() is failing, mImage->IsComplete() "
+                        "should have returned false");
 
       if (!mImage->GetCropRect()) {
         mImageContainer.swap(srcImage);
       } else {
         nsIntRect actualCropRect;
         bool isEntireImage;
         bool success =
           mImage->ComputeActualCropRect(actualCropRect, &isEntireImage);
@@ -4460,30 +4462,29 @@ nsImageRenderer::Draw(nsPresContext*    
 }
 
 bool
 nsImageRenderer::IsRasterImage()
 {
   if (mType != eStyleImageType_Image)
     return false;
   nsCOMPtr<imgIContainer> img;
-  nsresult rv = mImage->GetImageData()->GetImage(getter_AddRefs(img));
-  if (NS_FAILED(rv) || !img)
+  if (NS_FAILED(mImage->GetImageData()->GetImage(getter_AddRefs(img))))
     return false;
   return img->GetType() == imgIContainer::TYPE_RASTER;
 }
 
 already_AddRefed<mozilla::layers::ImageContainer>
 nsImageRenderer::GetContainer()
 {
   if (mType != eStyleImageType_Image)
     return nullptr;
   nsCOMPtr<imgIContainer> img;
   nsresult rv = mImage->GetImageData()->GetImage(getter_AddRefs(img));
-  if (NS_FAILED(rv) || !img)
+  if (NS_FAILED(rv))
     return nullptr;
   nsRefPtr<ImageContainer> container;
   rv = img->GetImageContainer(getter_AddRefs(container));
   NS_ENSURE_SUCCESS(rv, nullptr);
   return container.forget();
 }
 
 #define MAX_BLUR_RADIUS 300
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -4286,22 +4286,22 @@ nsLayoutUtils::SurfaceFromElement(nsIIma
     // nsIDOMHTMLImageElement, and we support all sorts of other stuff
     // here.  Do this for now pending spec clarification.
     result.mIsStillLoading = (status & imgIRequest::STATUS_ERROR) == 0;
     return result;
   }
 
   nsCOMPtr<nsIPrincipal> principal;
   rv = imgRequest->GetImagePrincipal(getter_AddRefs(principal));
-  if (NS_FAILED(rv) || !principal)
+  if (NS_FAILED(rv))
     return result;
 
   nsCOMPtr<imgIContainer> imgContainer;
   rv = imgRequest->GetImage(getter_AddRefs(imgContainer));
-  if (NS_FAILED(rv) || !imgContainer)
+  if (NS_FAILED(rv))
     return result;
 
   uint32_t whichFrame = (aSurfaceFlags & SFE_WANT_FIRST_FRAME)
                         ? (uint32_t) imgIContainer::FRAME_FIRST
                         : (uint32_t) imgIContainer::FRAME_CURRENT;
   uint32_t frameFlags = imgIContainer::FLAG_SYNC_DECODE;
   if (aSurfaceFlags & SFE_NO_COLORSPACE_CONVERSION)
     frameFlags |= imgIContainer::FLAG_DECODE_NO_COLORSPACE_CONVERSION;
@@ -4781,19 +4781,17 @@ nsLayoutUtils::RegisterImageRequestIfAni
   if (aRequestRegistered && *aRequestRegistered) {
     // Our request is already registered with the refresh driver, so
     // no need to register it again.
     return;
   }
 
   if (aRequest) {
     nsCOMPtr<imgIContainer> image;
-    aRequest->GetImage(getter_AddRefs(image));
-    if (image) {
-
+    if (NS_SUCCEEDED(aRequest->GetImage(getter_AddRefs(image)))) {
       // Check to verify that the image is animated. If so, then add it to the
       // list of images tracked by the refresh driver.
       bool isAnimated = false;
       nsresult rv = image->GetAnimated(&isAnimated);
       if (NS_SUCCEEDED(rv) && isAnimated) {
         if (!aPresContext->RefreshDriver()->AddImageRequest(aRequest)) {
           NS_WARNING("Unable to add image request");
           return;
@@ -4820,18 +4818,17 @@ nsLayoutUtils::DeregisterImageRequest(ns
   // Deregister our imgIRequest with the refresh driver to
   // complete tear-down, but only if it has been registered
   if (aRequestRegistered && !*aRequestRegistered) {
     return;
   }
 
   if (aRequest) {
     nsCOMPtr<imgIContainer> image;
-    aRequest->GetImage(getter_AddRefs(image));
-    if (image) {
+    if (NS_SUCCEEDED(aRequest->GetImage(getter_AddRefs(image)))) {
       aPresContext->RefreshDriver()->RemoveImageRequest(aRequest);
 
       if (aRequestRegistered) {
         *aRequestRegistered = false;
       }
     }
   }
 }
--- a/layout/base/nsRefreshDriver.cpp
+++ b/layout/base/nsRefreshDriver.cpp
@@ -459,18 +459,17 @@ nsRefreshDriver::ImageRequestEnumerator(
                                         void* aUserArg)
 {
   ImageRequestParameters* parms =
     static_cast<ImageRequestParameters*> (aUserArg);
   mozilla::TimeStamp mostRecentRefresh = parms->ts;
   imgIRequest* req = static_cast<imgIRequest*>(aEntry->GetKey());
   NS_ABORT_IF_FALSE(req, "Unable to retrieve the image request");
   nsCOMPtr<imgIContainer> image;
-  req->GetImage(getter_AddRefs(image));
-  if (image) {
+  if (NS_SUCCEEDED(req->GetImage(getter_AddRefs(image)))) {
     image->RequestRefresh(mostRecentRefresh);
   }
 
   return PL_DHASH_NEXT;
 }
 
 void
 nsRefreshDriver::Freeze()