Bug 1462272: Remove handling for an impossible condition. r?dholbert draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 16 May 2018 20:51:17 +0200
changeset 796732 e914cfe48f1130c295cb603d794a83f3952935f3
parent 796731 da0ede9406382f3c2934756ed2569b76e866b15d
child 796733 305c4bbe504fb3816f4936c4521b104cbe19f6c2
push id110351
push userbmo:emilio@crisal.io
push dateFri, 18 May 2018 07:45:13 +0000
reviewersdholbert
bugs1462272
milestone62.0a1
Bug 1462272: Remove handling for an impossible condition. r?dholbert The frame is notified via its mListener, which is an observer of the nsImageLoadingContent (mContent). This last one only notifies for the current and pending requests, otherwise it's a bug we need to fix there, not wallpaper here, since that'd mean that we forgot to cancel the previous request. Added assertions to that effect. Notify() is only called with the this object as a first argument from imgRequestProxy, so it'd better be non-null, too. MozReview-Commit-ID: DHaOLph2EAo
dom/base/nsImageLoadingContent.cpp
layout/generic/nsImageFrame.cpp
--- a/dom/base/nsImageLoadingContent.cpp
+++ b/dom/base/nsImageLoadingContent.cpp
@@ -130,33 +130,29 @@ nsImageLoadingContent::~nsImageLoadingCo
 /*
  * imgINotificationObserver impl
  */
 NS_IMETHODIMP
 nsImageLoadingContent::Notify(imgIRequest* aRequest,
                               int32_t aType,
                               const nsIntRect* aData)
 {
+  MOZ_ASSERT(aRequest, "no request?");
+  MOZ_ASSERT(aRequest == mCurrentRequest || aRequest == mPendingRequest,
+             "Forgot to cancel a previous request?");
+
   if (aType == imgINotificationObserver::IS_ANIMATED) {
     return OnImageIsAnimated(aRequest);
   }
 
   if (aType == imgINotificationObserver::UNLOCKED_DRAW) {
     OnUnlockedDraw();
     return NS_OK;
   }
 
-  if (aType == imgINotificationObserver::LOAD_COMPLETE) {
-    // We should definitely have a request here
-    MOZ_ASSERT(aRequest, "no request?");
-
-    MOZ_ASSERT(aRequest == mCurrentRequest || aRequest == mPendingRequest,
-               "Unknown request");
-  }
-
   {
     // Calling Notify on observers can modify the list of observers so make
     // a local copy.
     AutoTArray<nsCOMPtr<imgINotificationObserver>, 2> observers;
     for (ImageObserver* observer = &mObserverList, *next; observer;
          observer = next) {
       next = observer->mNext;
       if (observer->mObserver) {
--- a/layout/generic/nsImageFrame.cpp
+++ b/layout/generic/nsImageFrame.cpp
@@ -680,33 +680,22 @@ nsImageFrame::InvalidateSelf(const nsInt
                     aLayerInvalidRect,
                     aFrameInvalidRect);
   }
 }
 
 nsresult
 nsImageFrame::OnLoadComplete(imgIRequest* aRequest, nsresult aStatus)
 {
-  // Check what request type we're dealing with
-  nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
-  NS_ASSERTION(imageLoader, "Who's notifying us??");
-  int32_t loadType = nsIImageLoadingContent::UNKNOWN_REQUEST;
-  imageLoader->GetRequestType(aRequest, &loadType);
-  if (loadType != nsIImageLoadingContent::CURRENT_REQUEST &&
-      loadType != nsIImageLoadingContent::PENDING_REQUEST) {
-    return NS_ERROR_FAILURE;
-  }
-
   NotifyNewCurrentRequest(aRequest, aStatus);
   return NS_OK;
 }
 
 void
-nsImageFrame::NotifyNewCurrentRequest(imgIRequest *aRequest,
-                                      nsresult aStatus)
+nsImageFrame::NotifyNewCurrentRequest(imgIRequest* aRequest, nsresult aStatus)
 {
   nsCOMPtr<imgIContainer> image;
   aRequest->GetImage(getter_AddRefs(image));
   NS_ASSERTION(image || NS_FAILED(aStatus), "Successful load with no container?");
 
   // May have to switch sizes here!
   bool intrinsicSizeChanged = true;
   if (NS_SUCCEEDED(aStatus) && image && SizeIsAvailable(aRequest)) {