diff --git a/modules/libpr0n/src/imgContainer.cpp b/modules/libpr0n/src/imgContainer.cpp index 73b93fc24143..4193544bf939 100644 --- a/modules/libpr0n/src/imgContainer.cpp +++ b/modules/libpr0n/src/imgContainer.cpp @@ -652,6 +652,8 @@ NS_IMETHODIMP imgContainer::RestoreDataDone (void) /* void notify(in nsITimer timer); */ NS_IMETHODIMP imgContainer::Notify(nsITimer *timer) { + // Note that as long as the image is animated, it will not be discarded, + // so this should never happen... nsresult rv = RestoreDiscardedData(); NS_ENSURE_SUCCESS(rv, rv); @@ -661,7 +663,7 @@ NS_IMETHODIMP imgContainer::Notify(nsITimer *timer) NS_ASSERTION(mAnim->timer == timer, "imgContainer::Notify() called with incorrect timer"); - if (!(mAnim->animating) || !(mAnim->timer)) + if (!mAnim->animating || !mAnim->timer) return NS_OK; nsCOMPtr observer(do_QueryReferent(mObserver)); @@ -1305,15 +1307,23 @@ imgContainer::sDiscardTimerCallback(nsITimer *aTimer, void *aClosure) nsresult imgContainer::ResetDiscardTimer (void) { - if (!DiscardingEnabled()) + if (!mRestoreDataDone) + return NS_OK; + + if (mDiscardTimer) { + /* Cancel current timer */ + nsresult rv = mDiscardTimer->Cancel(); + NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); + mDiscardTimer = nsnull; + } + + /* Don't activate timer when we are animating... */ + if (mAnim && mAnim->animating) return NS_OK; if (!mDiscardTimer) { mDiscardTimer = do_CreateInstance("@mozilla.org/timer;1"); NS_ENSURE_TRUE(mDiscardTimer, NS_ERROR_OUT_OF_MEMORY); - } else { - nsresult rv = mDiscardTimer->Cancel(); - NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); } return mDiscardTimer->InitWithFuncCallback(sDiscardTimerCallback,