Bug 505385 - Part 14: Update image request status on decoding errors. r=joe
authorJosh Matthews <josh@joshmatthews.net>
Fri, 12 Oct 2012 12:11:22 -0400
changeset 110238 92f3a3fd032fc5da3a3264ffda9eb5ff5802a704
parent 110237 163205db950dccd29cba7f320f1c9d29cb703d7c
child 110239 395f1c3e4bc348edc2f3949bb47553190fec4951
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersjoe
bugs505385
milestone19.0a1
Bug 505385 - Part 14: Update image request status on decoding errors. r=joe
image/src/imgStatusTracker.cpp
--- a/image/src/imgStatusTracker.cpp
+++ b/image/src/imgStatusTracker.cpp
@@ -630,17 +630,17 @@ imgStatusTracker::SendStopFrame(imgReque
 
 void
 imgStatusTracker::RecordStopDecode(nsresult aStatus)
 {
   NS_ABORT_IF_FALSE(mImage,
                     "RecordStopDecode called before we have an Image");
   mState |= stateDecodeStopped;
 
-  if (NS_SUCCEEDED(aStatus))
+  if (NS_SUCCEEDED(aStatus) && mImageStatus != imgIRequest::STATUS_ERROR)
     mImageStatus |= imgIRequest::STATUS_DECODE_COMPLETE;
   // If we weren't successful, clear all success status bits and set error.
   else
     mImageStatus = imgIRequest::STATUS_ERROR;
 }
 
 void
 imgStatusTracker::SendStopDecode(imgRequestProxy* aProxy, nsresult aStatus)
@@ -745,18 +745,20 @@ imgStatusTracker::OnStartRequest()
 
 void
 imgStatusTracker::RecordStopRequest(bool aLastPart, nsresult aStatus)
 {
   mHadLastPart = aLastPart;
   mState |= stateRequestStopped;
 
   // If we were successful in loading, note that the image is complete.
-  if (NS_SUCCEEDED(aStatus))
+  if (NS_SUCCEEDED(aStatus) && mImageStatus != imgIRequest::STATUS_ERROR)
     mImageStatus |= imgIRequest::STATUS_LOAD_COMPLETE;
+  else
+    mImageStatus = imgIRequest::STATUS_ERROR;
 }
 
 void
 imgStatusTracker::SendStopRequest(imgRequestProxy* aProxy, bool aLastPart, nsresult aStatus)
 {
   if (!aProxy->NotificationsDeferred()) {
     aProxy->OnStopRequest(aLastPart);
   }
@@ -766,16 +768,28 @@ void
 imgStatusTracker::OnStopRequest(bool aLastPart, nsresult aStatus)
 {
   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;
+      mTracker->GetRequest()->GetURI(getter_AddRefs(uri));
+      os->NotifyObservers(uri, "net:failed-to-process-uri-content", nullptr);
+    }
+  }
 }
 
 void
 imgStatusTracker::OnDataAvailable()
 {
   // Notify any imgRequestProxys that are observing us that we have an Image.
   nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mConsumers);
   while (iter.HasMore()) {