Bug 505385 - Part 15: Fix cases where pending requests in nsImageLoadingContent could be cancelled and never receive OnStartRequest. r=joe
authorJosh Matthews <josh@joshmatthews.net>
Thu, 11 Oct 2012 21:34:24 -0400
changeset 110159 4f3390a9eec7b0370a5bb47753f12302831df1ae
parent 110158 64a67cc6691bd4fc606fb649fa483c9b4267b7cd
child 110160 84629d3f4c74de39e442dae7aadffaa1f4d18167
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersjoe
bugs505385
milestone19.0a1
Bug 505385 - Part 15: Fix cases where pending requests in nsImageLoadingContent could be cancelled and never receive OnStartRequest. r=joe
content/base/src/nsImageLoadingContent.cpp
image/src/imgStatusTracker.cpp
--- a/content/base/src/nsImageLoadingContent.cpp
+++ b/content/base/src/nsImageLoadingContent.cpp
@@ -164,16 +164,29 @@ nsImageLoadingContent::Notify(imgIReques
 
   return NS_OK;
 }
 
 nsresult
 nsImageLoadingContent::OnStopRequest(imgIRequest* aRequest,
                                      nsresult aStatus)
 {
+  uint32_t oldStatus;
+  aRequest->GetImageStatus(&oldStatus);
+
+  //XXXjdm This occurs when we have a pending request created, then another
+  //       pending request replaces it before the first one is finished.
+  //       This begs the question of what the correct behaviour is; we used
+  //       to not have to care because we ran this code in OnStopDecode which
+  //       wasn't called when the first request was cancelled. For now, I choose
+  //       to punt when the given request doesn't appear to have terminated in
+  //       an expected state.
+  if (!(oldStatus & (imgIRequest::STATUS_ERROR | imgIRequest::STATUS_LOAD_COMPLETE)))
+    return NS_OK;
+
   // Our state may change. Watch it.
   AutoStateChanger changer(this, true);
 
   // If the pending request is loaded, switch to it.
   if (aRequest == mPendingRequest) {
     MakePendingRequestCurrent();
   }
   NS_ABORT_IF_FALSE(aRequest == mCurrentRequest,
--- a/image/src/imgStatusTracker.cpp
+++ b/image/src/imgStatusTracker.cpp
@@ -488,16 +488,20 @@ imgStatusTracker::SyncNotify(imgRequestP
 }
 
 void
 imgStatusTracker::EmulateRequestFinished(imgRequestProxy* aProxy,
                                          nsresult aStatus)
 {
   nsCOMPtr<imgIRequest> kungFuDeathGrip(aProxy);
 
+  if (!(mState & stateRequestStarted)) {
+    aProxy->OnStartRequest();
+  }
+
   if (mState & stateBlockingOnload) {
     aProxy->UnblockOnload();
   }
 
   if (!(mState & stateRequestStopped)) {
     aProxy->OnStopRequest(true);
   }
 }
@@ -777,17 +781,17 @@ imgStatusTracker::OnStopRequest(bool aLa
 
   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));
+      GetRequest()->GetURI(getter_AddRefs(uri));
       os->NotifyObservers(uri, "net:failed-to-process-uri-content", nullptr);
     }
   }
 }
 
 void
 imgStatusTracker::OnDataAvailable()
 {