Bug 1098108 (Part 4) - Make resniffed multipart requests progress like normal requests. r=tn
authorSeth Fowler <seth@mozilla.com>
Fri, 14 Nov 2014 20:10:48 -0800
changeset 240209 0b3a6fee879c389028c97f903a1917c57fa9f365
parent 240208 e51b39c7d64b1a6050e45d42ba029ae2a418b3fb
child 240210 c786bdac4406ca9920a83fa50e558750be6d5f60
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstn
bugs1098108
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1098108 (Part 4) - Make resniffed multipart requests progress like normal requests. r=tn
image/src/ProgressTracker.cpp
image/src/imgRequest.cpp
--- a/image/src/ProgressTracker.cpp
+++ b/image/src/ProgressTracker.cpp
@@ -53,22 +53,25 @@ void
 ProgressTracker::ResetImage()
 {
   NS_ABORT_IF_FALSE(mImage, "Resetting image when it's already null!");
   mImage = nullptr;
 }
 
 void ProgressTracker::SetIsMultipart()
 {
-  mProgress |= FLAG_IS_MULTIPART;
+  if (mProgress & FLAG_IS_MULTIPART) {
+    return;
+  }
 
-  // If we haven't already blocked onload, make sure we never do.
-  if (!(mProgress & FLAG_ONLOAD_BLOCKED)) {
-    mProgress |= FLAG_ONLOAD_BLOCKED | FLAG_ONLOAD_UNBLOCKED;
-  }
+  MOZ_ASSERT(!(mProgress & FLAG_ONLOAD_BLOCKED),
+             "Blocked onload before we knew we were multipart?");
+
+  // Set the MULTIPART flag and ensure that we never block onload.
+  mProgress |= FLAG_IS_MULTIPART | FLAG_ONLOAD_BLOCKED | FLAG_ONLOAD_UNBLOCKED;
 }
 
 bool
 ProgressTracker::IsLoading() const
 {
   // Checking for whether OnStopRequest has fired allows us to say we're
   // loading before OnStartRequest gets called, letting the request properly
   // get removed from the cache in certain cases.
@@ -425,17 +428,18 @@ ProgressTracker::OnUnlockedDraw()
 
 void
 ProgressTracker::ResetForNewRequest()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // We're starting a new load (and if this is called more than once, this is a
   // multipart request) so keep only the bits that carry over between loads.
-  mProgress &= FLAG_IS_MULTIPART | FLAG_HAS_ERROR;
+  mProgress &= FLAG_IS_MULTIPART | FLAG_HAS_ERROR |
+               FLAG_ONLOAD_BLOCKED | FLAG_ONLOAD_UNBLOCKED;
 }
 
 void
 ProgressTracker::OnDiscard()
 {
   MOZ_ASSERT(NS_IsMainThread());
   NOTIFY_IMAGE_OBSERVERS(mConsumers, OnDiscard());
 }
--- a/image/src/imgRequest.cpp
+++ b/image/src/imgRequest.cpp
@@ -885,19 +885,24 @@ imgRequest::OnDataAvailable(nsIRequest *
     // reinitializing themselves.
     if (mContentType != newType || newType.EqualsLiteral(IMAGE_SVG_XML)) {
       mContentType = newType;
 
       // If we've resniffed our MIME type and it changed, we need to create a
       // new status tracker to give to the image, because we don't have one of
       // our own any more.
       if (resniffMimeType) {
-        NS_ABORT_IF_FALSE(mIsMultiPartChannel, "Resniffing a non-multipart image");
+        MOZ_ASSERT(mIsMultiPartChannel, "Resniffing a non-multipart image");
 
+        // Initialize a new status tracker.
         nsRefPtr<ProgressTracker> freshTracker = new ProgressTracker(nullptr);
+        freshTracker->SetIsMultipart();
+        freshTracker->SyncNotifyProgress(FLAG_REQUEST_STARTED);
+
+        // Replace the old status tracker with it.
         nsRefPtr<ProgressTracker> oldProgressTracker = GetProgressTracker();
         freshTracker->AdoptConsumers(oldProgressTracker);
         mProgressTracker = freshTracker.forget();
       }
 
       SetProperties(chan);
 
       LOG_MSG_WITH_PARAM(GetImgLog(), "imgRequest::OnDataAvailable", "content type", mContentType.get());