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>
Fri, 12 Oct 2012 12:11:22 -0400
changeset 110239 395f1c3e4bc348edc2f3949bb47553190fec4951
parent 110238 92f3a3fd032fc5da3a3264ffda9eb5ff5802a704
child 110240 353b9b430a96f6058c74fdebd563735e378aec3b
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);
   }
 }
@@ -776,17 +780,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()
 {