diff --git a/modules/libpr0n/decoders/gif/nsGIFDecoder2.cpp b/modules/libpr0n/decoders/gif/nsGIFDecoder2.cpp index 9a7a1e4edf0a..bcfb95ffce28 100644 --- a/modules/libpr0n/decoders/gif/nsGIFDecoder2.cpp +++ b/modules/libpr0n/decoders/gif/nsGIFDecoder2.cpp @@ -142,8 +142,18 @@ NS_IMETHODIMP nsGIFDecoder2::Init(imgILoad *aLoad) { mObserver = do_QueryInterface(aLoad); - mImageContainer = do_CreateInstance("@mozilla.org/image/container;1"); - aLoad->SetImage(mImageContainer); + /* The image container may already exist if it is reloading itself from us. + */ + aLoad->GetImage(getter_AddRefs(mImageContainer)); + if (!mImageContainer) { + mImageContainer = do_CreateInstance("@mozilla.org/image/container;1"); + if (!mImageContainer) + return NS_ERROR_OUT_OF_MEMORY; + + aLoad->SetImage(mImageContainer); + nsresult rv = mImageContainer->SetDiscardable("image/gif"); + NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); + } // Start with the version (GIF89a|GIF87a) mGIFStruct.state = gif_type; @@ -174,7 +184,7 @@ NS_IMETHODIMP nsGIFDecoder2::Close() /* void flush (); */ NS_IMETHODIMP nsGIFDecoder2::Flush() { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_OK; } //****************************************************************************** @@ -187,7 +197,7 @@ static NS_METHOD ReadDataOut(nsIInputStream* in, PRUint32 *writeCount) { nsGIFDecoder2 *decoder = static_cast(closure); - nsresult rv = decoder->ProcessData((unsigned char*)fromRawSegment, count, writeCount); + nsresult rv = decoder->ProcessData(fromRawSegment, count, writeCount); if (NS_FAILED(rv)) { *writeCount = 0; return rv; @@ -236,11 +246,11 @@ nsGIFDecoder2::FlushImageData() } //****************************************************************************** -nsresult nsGIFDecoder2::ProcessData(unsigned char *data, PRUint32 count, PRUint32 *_retval) +nsresult nsGIFDecoder2::ProcessData(const char *data, PRUint32 count, PRUint32 *_retval) { // Push the data to the GIF decoder - nsresult rv = GifWrite(data, count); + nsresult rv = GifWrite((const PRUint8*)data, count); NS_ENSURE_SUCCESS(rv, rv); // Flushing is only needed for first frame @@ -250,6 +260,13 @@ nsresult nsGIFDecoder2::ProcessData(unsigned char *data, PRUint32 count, PRUint3 mLastFlushedPass = mCurrentPass; } + // We should just disable the 'restore' when AddRestoreData fails, so that we still load the image... + rv = mImageContainer->AddRestoreData(data, count); + if (NS_FAILED(rv)) { + mGIFStruct.state = gif_oom; + return rv; + } + *_retval = count; return NS_OK; @@ -310,6 +327,7 @@ void nsGIFDecoder2::EndGIF() mImageContainer->SetLoopCount(mGIFStruct.loop_count); mImageContainer->DecodingComplete(); + (void)mImageContainer->RestoreDataDone(); // Discard error code mGIFOpen = PR_FALSE; } diff --git a/modules/libpr0n/decoders/gif/nsGIFDecoder2.h b/modules/libpr0n/decoders/gif/nsGIFDecoder2.h index 570cca2e1f56..2c43bed1f0a3 100644 --- a/modules/libpr0n/decoders/gif/nsGIFDecoder2.h +++ b/modules/libpr0n/decoders/gif/nsGIFDecoder2.h @@ -68,7 +68,7 @@ public: nsGIFDecoder2(); ~nsGIFDecoder2(); - nsresult ProcessData(unsigned char *data, PRUint32 count, PRUint32 *_retval); + nsresult ProcessData(const char *data, PRUint32 count, PRUint32 *_retval); private: /* These functions will be called when the decoder has a decoded row, diff --git a/modules/libpr0n/decoders/icon/nsIconDecoder.cpp b/modules/libpr0n/decoders/icon/nsIconDecoder.cpp index cc28063d6242..bff7fc8562be 100644 --- a/modules/libpr0n/decoders/icon/nsIconDecoder.cpp +++ b/modules/libpr0n/decoders/icon/nsIconDecoder.cpp @@ -96,7 +96,7 @@ NS_IMETHODIMP nsIconDecoder::Close() NS_IMETHODIMP nsIconDecoder::Flush() { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_OK; } NS_IMETHODIMP nsIconDecoder::WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval)