Bug 505385 - Part 17: Consolidate image request failure handling code into a central location and deal with preexisting errors correctly. r=joe
authorJosh Matthews <josh@joshmatthews.net>
Thu, 11 Oct 2012 21:34:24 -0400
changeset 110161 9449ddf1199efa3f8564f2d5b1069c8435069297
parent 110160 84629d3f4c74de39e442dae7aadffaa1f4d18167
child 110162 b4ec385f733b9e2e04eea14b418a9ab2aea5b673
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersjoe
bugs505385
milestone19.0a1
Bug 505385 - Part 17: Consolidate image request failure handling code into a central location and deal with preexisting errors correctly. r=joe
image/src/imgStatusTracker.cpp
--- a/image/src/imgStatusTracker.cpp
+++ b/image/src/imgStatusTracker.cpp
@@ -167,49 +167,57 @@ NS_IMETHODIMP imgStatusTrackerObserver::
     mTracker->SendStopFrame(iter.GetNext(), frame);
   }
 
   mTracker->MaybeUnblockOnload();
 
   return NS_OK;
 }
 
+static void
+FireFailureNotification(imgRequest* aRequest)
+{
+  // Some kind of problem has happened with image decoding.
+  // Report the URI to net:failed-to-process-uri-conent observers.
+
+  nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
+  if (os) {
+    nsCOMPtr<nsIURI> uri;
+    aRequest->GetURI(getter_AddRefs(uri));
+    os->NotifyObservers(uri, "net:failed-to-process-uri-content", nullptr);
+  }
+}
+
 /* void onStopDecode (in imgIRequest request, in nsresult status, in wstring statusArg); */
 NS_IMETHODIMP imgStatusTrackerObserver::OnStopDecode(imgIRequest *aRequest,
                                                      nsresult aStatus)
 {
   LOG_SCOPE(gImgLog, "imgStatusTrackerObserver::OnStopDecode");
   NS_ABORT_IF_FALSE(mTracker->GetImage(),
                     "OnStopDecode callback before we've created our image");
 
   // We finished the decode, and thus have the decoded frames. Update the cache
   // entry size to take this into account.
   mTracker->GetRequest()->UpdateCacheEntrySize();
 
+  bool preexistingError = mTracker->GetImageStatus() == imgIRequest::STATUS_ERROR;
+
   mTracker->RecordStopDecode(aStatus);
 
   nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mTracker->mConsumers);
   while (iter.HasMore()) {
     mTracker->SendStopDecode(iter.GetNext(), aStatus);
   }
 
   // This is really hacky. We need to handle the case where we start decoding,
   // block onload, but then hit an error before we get to our first frame.
   mTracker->MaybeUnblockOnload();
 
-  if (NS_FAILED(aStatus)) {
-    // Some kind of problem has happened with image decoding.
-    // Report the URI to net:failed-to-process-uri-conent observers.
-
-    nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
-    if (os) {
-      nsCOMPtr<nsIURI> uri;
-      mTracker->GetRequest()->GetURI(getter_AddRefs(uri));
-      os->NotifyObservers(uri, "net:failed-to-process-uri-content", nullptr);
-    }
+  if (NS_FAILED(aStatus) && !preexistingError) {
+    FireFailureNotification(mTracker->GetRequest());
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP imgStatusTrackerObserver::OnStopRequest(imgIRequest *aRequest,
                                         bool aLastPart)
 {
@@ -767,33 +775,27 @@ imgStatusTracker::SendStopRequest(imgReq
   if (!aProxy->NotificationsDeferred()) {
     aProxy->OnStopRequest(aLastPart);
   }
 }
 
 void
 imgStatusTracker::OnStopRequest(bool aLastPart, nsresult aStatus)
 {
+  bool preexistingError = mImageStatus == imgIRequest::STATUS_ERROR;
+
   RecordStopRequest(aLastPart, aStatus);
   /* notify the kids */
   nsTObserverArray<imgRequestProxy*>::ForwardIterator srIter(mConsumers);
   while (srIter.HasMore()) {
     SendStopRequest(srIter.GetNext(), aLastPart, aStatus);
   }
 
-  if (NS_FAILED(aStatus)) {
-    // Some kind of problem has happened with image decoding.
-    // Report the URI to net:failed-to-process-uri-conent observers.
-
-    nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
-    if (os) {
-      nsCOMPtr<nsIURI> uri;
-      GetRequest()->GetURI(getter_AddRefs(uri));
-      os->NotifyObservers(uri, "net:failed-to-process-uri-content", nullptr);
-    }
+  if (NS_FAILED(aStatus) && !preexistingError) {
+    FireFailureNotification(GetRequest());
   }
 }
 
 void
 imgStatusTracker::OnDataAvailable()
 {
   // Notify any imgRequestProxys that are observing us that we have an Image.
   nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mConsumers);