Bug 918864. r=bz, a=abillings
authorOlli Pettay <bugs@pettay.fi>
Thu, 17 Oct 2013 13:59:55 -0400
changeset 119951 7fedb6a967eabeafc58fff4efcdff624a9af77ef
parent 119950 e58ba4276d7ba111c70973302e7cb29719a0ed4f
child 119952 53542d252c2dffa1d725a87c624d085c88c607a2
push id1090
push userryanvm@gmail.com
push dateThu, 17 Oct 2013 20:02:55 +0000
reviewersbz, abillings
bugs918864
milestone18.1
Bug 918864. r=bz, a=abillings
uriloader/prefetch/nsOfflineCacheUpdateService.cpp
--- a/uriloader/prefetch/nsOfflineCacheUpdateService.cpp
+++ b/uriloader/prefetch/nsOfflineCacheUpdateService.cpp
@@ -123,25 +123,27 @@ public:
 
     nsOfflineCachePendingUpdate(nsOfflineCacheUpdateService *aService,
                                 nsIURI *aManifestURI,
                                 nsIURI *aDocumentURI,
                                 nsIDOMDocument *aDocument)
         : mService(aService)
         , mManifestURI(aManifestURI)
         , mDocumentURI(aDocumentURI)
+        , mDidReleaseThis(false)
         {
             mDocument = do_GetWeakReference(aDocument);
         }
 
 private:
     nsRefPtr<nsOfflineCacheUpdateService> mService;
     nsCOMPtr<nsIURI> mManifestURI;
     nsCOMPtr<nsIURI> mDocumentURI;
     nsCOMPtr<nsIWeakReference> mDocument;
+    bool mDidReleaseThis;
 };
 
 NS_IMPL_ISUPPORTS2(nsOfflineCachePendingUpdate,
                    nsIWebProgressListener,
                    nsISupportsWeakReference)
 
 //-----------------------------------------------------------------------------
 // nsOfflineCacheUpdateService::nsIWebProgressListener
@@ -160,21 +162,26 @@ nsOfflineCachePendingUpdate::OnProgressC
 }
 
 NS_IMETHODIMP
 nsOfflineCachePendingUpdate::OnStateChange(nsIWebProgress* aWebProgress,
                                            nsIRequest *aRequest,
                                            uint32_t progressStateFlags,
                                            nsresult aStatus)
 {
+    if (mDidReleaseThis) {
+        return NS_OK;
+    }
     nsCOMPtr<nsIDOMDocument> updateDoc = do_QueryReferent(mDocument);
     if (!updateDoc) {
         // The document that scheduled this update has gone away,
         // we don't need to listen anymore.
         aWebProgress->RemoveProgressListener(this);
+        MOZ_ASSERT(!mDidReleaseThis);
+        mDidReleaseThis = true;
         NS_RELEASE_THIS();
         return NS_OK;
     }
 
     if (!(progressStateFlags & STATE_STOP)) {
         return NS_OK;
     }
 
@@ -200,19 +207,24 @@ nsOfflineCachePendingUpdate::OnStateChan
         bool isInBrowserElement;
         nsresult rv = GetAppIDAndInBrowserFromWindow(window, &appId, &isInBrowserElement);
         NS_ENSURE_SUCCESS(rv, rv);
 
         nsCOMPtr<nsIOfflineCacheUpdate> update;
         mService->Schedule(mManifestURI, mDocumentURI,
                            updateDoc, window, nullptr,
                            appId, isInBrowserElement, getter_AddRefs(update));
+        if (mDidReleaseThis) {
+            return NS_OK;
+        }
     }
 
     aWebProgress->RemoveProgressListener(this);
+    MOZ_ASSERT(!mDidReleaseThis);
+    mDidReleaseThis = true;
     NS_RELEASE_THIS();
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsOfflineCachePendingUpdate::OnLocationChange(nsIWebProgress* aWebProgress,
                                               nsIRequest* aRequest,