Bug 514033 - Error recovery for imagelib - part 5 - Coalesce OnStartDecode into superclass.r=joe,a=blocker
authorBobby Holley <bobbyholley@gmail.com>
Sun, 12 Sep 2010 08:22:30 -0700
changeset 53665 817a480e3836d07cb9a5966f656ac593477a14de
parent 53664 bba73a834d330a5e1946e54bf69738ec9fd2105c
child 53666 c2686243b32e5f430dee8fd219acdce93c602132
push idunknown
push userunknown
push dateunknown
reviewersjoe, blocker
bugs514033
milestone2.0b6pre
Bug 514033 - Error recovery for imagelib - part 5 - Coalesce OnStartDecode into superclass.r=joe,a=blocker
modules/libpr0n/decoders/nsBMPDecoder.cpp
modules/libpr0n/decoders/nsBMPDecoder.h
modules/libpr0n/decoders/nsGIFDecoder2.cpp
modules/libpr0n/decoders/nsGIFDecoder2.h
modules/libpr0n/decoders/nsICODecoder.cpp
modules/libpr0n/decoders/nsICODecoder.h
modules/libpr0n/decoders/nsIconDecoder.cpp
modules/libpr0n/decoders/nsIconDecoder.h
modules/libpr0n/decoders/nsJPEGDecoder.cpp
modules/libpr0n/decoders/nsPNGDecoder.cpp
modules/libpr0n/src/Decoder.cpp
--- a/modules/libpr0n/decoders/nsBMPDecoder.cpp
+++ b/modules/libpr0n/decoders/nsBMPDecoder.cpp
@@ -76,26 +76,16 @@ nsBMPDecoder::nsBMPDecoder()
 nsBMPDecoder::~nsBMPDecoder()
 {
   delete[] mColors;
   if (mRow)
       free(mRow);
 }
 
 void
-nsBMPDecoder::InitInternal()
-{
-    PR_LOG(gBMPLog, PR_LOG_DEBUG, ("nsBMPDecoder::Init(%p)\n", mImage.get()));
-
-    // Fire OnStartDecode at init time to support bug 512435
-    if (!IsSizeDecode() && mObserver)
-        mObserver->OnStartDecode(nsnull);
-}
-
-void
 nsBMPDecoder::FinishInternal()
 {
     // We should never make multiple frames
     NS_ABORT_IF_FALSE(GetFrameCount() <= 1, "Multiple BMP frames?");
 
     // Send notifications if appropriate
     if (!IsSizeDecode() && !IsError() && (GetFrameCount() == 1)) {
         PostFrameStop();
--- a/modules/libpr0n/decoders/nsBMPDecoder.h
+++ b/modules/libpr0n/decoders/nsBMPDecoder.h
@@ -141,17 +141,16 @@ class RasterImage;
  */
 class nsBMPDecoder : public Decoder
 {
 public:
 
     nsBMPDecoder();
     ~nsBMPDecoder();
 
-    virtual void InitInternal();
     virtual void WriteInternal(const char* aBuffer, PRUint32 aCount);
     virtual void FinishInternal();
 
 private:
 
     /** Calculates the red-, green- and blueshift in mBitFields using
      * the bitmasks from mBitFields */
     NS_METHOD CalcBitShift();
--- a/modules/libpr0n/decoders/nsGIFDecoder2.cpp
+++ b/modules/libpr0n/decoders/nsGIFDecoder2.cpp
@@ -116,36 +116,28 @@ nsGIFDecoder2::nsGIFDecoder2()
   , mCurrentPass(0)
   , mLastFlushedPass(0)
   , mGIFOpen(PR_FALSE)
   , mSawTransparency(PR_FALSE)
   , mEnded(PR_FALSE)
 {
   // Clear out the structure, excluding the arrays
   memset(&mGIFStruct, 0, sizeof(mGIFStruct));
+
+  // Start with the version (GIF89a|GIF87a)
+  mGIFStruct.state = gif_type;
+  mGIFStruct.bytes_to_consume = 6;
 }
 
 nsGIFDecoder2::~nsGIFDecoder2()
 {
   PR_FREEIF(mGIFStruct.local_colormap);
 }
 
 void
-nsGIFDecoder2::InitInternal()
-{
-  // Fire OnStartDecode at init time to support bug 512435
-  if (!IsSizeDecode() && mObserver)
-    mObserver->OnStartDecode(nsnull);
-
-  // Start with the version (GIF89a|GIF87a)
-  mGIFStruct.state = gif_type;
-  mGIFStruct.bytes_to_consume = 6;
-}
-
-void
 nsGIFDecoder2::FinishInternal()
 {
   // Send notifications if appropriate
   if (!IsSizeDecode() && !IsError()) {
     if (mCurrentFrame == mGIFStruct.images_decoded)
       EndImageFrame();
     EndGIF(/* aSuccess = */ PR_TRUE);
   }
--- a/modules/libpr0n/decoders/nsGIFDecoder2.h
+++ b/modules/libpr0n/decoders/nsGIFDecoder2.h
@@ -56,17 +56,16 @@ class RasterImage;
 
 class nsGIFDecoder2 : public Decoder
 {
 public:
 
   nsGIFDecoder2();
   ~nsGIFDecoder2();
 
-  virtual void InitInternal();
   virtual void WriteInternal(const char* aBuffer, PRUint32 aCount);
   virtual void FinishInternal();
 
 private:
   /* These functions will be called when the decoder has a decoded row,
    * frame size information, etc. */
 
   void      BeginGIF();
--- a/modules/libpr0n/decoders/nsICODecoder.cpp
+++ b/modules/libpr0n/decoders/nsICODecoder.cpp
@@ -96,24 +96,16 @@ nsICODecoder::~nsICODecoder()
   if (mRow) {
     free(mRow);
     mRow = nsnull;
   }
   mDecodingAndMask = PR_FALSE;
 }
 
 void
-nsICODecoder::InitInternal()
-{
-  // Fire OnStartDecode at init time to support bug 512435
-  if (!IsSizeDecode() && mObserver)
-    mObserver->OnStartDecode(nsnull);
-}
-
-void
 nsICODecoder::FinishInternal()
 {
   // We should never make multiple frames
   NS_ABORT_IF_FALSE(GetFrameCount() <= 1, "Multiple ICO frames?");
 
   // Send notifications if appropriate
   if (!IsSizeDecode() && !IsError() && (GetFrameCount() == 1)) {
 
--- a/modules/libpr0n/decoders/nsICODecoder.h
+++ b/modules/libpr0n/decoders/nsICODecoder.h
@@ -71,17 +71,16 @@ struct IconDirEntry
 
 class nsICODecoder : public Decoder
 {
 public:
 
   nsICODecoder();
   virtual ~nsICODecoder();
 
-  virtual void InitInternal();
   virtual void WriteInternal(const char* aBuffer, PRUint32 aCount);
   virtual void FinishInternal();
 
 private:
   // Private helper methods
   void ProcessDirEntry(IconDirEntry& aTarget);
   void ProcessInfoHeader();
 
--- a/modules/libpr0n/decoders/nsIconDecoder.cpp
+++ b/modules/libpr0n/decoders/nsIconDecoder.cpp
@@ -60,25 +60,16 @@ nsIconDecoder::nsIconDecoder() :
   mNotifiedDone(PR_FALSE)
 {
   // Nothing to do
 }
 
 nsIconDecoder::~nsIconDecoder()
 { }
 
-
-void
-nsIconDecoder::InitInternal()
-{
-  // Fire OnStartDecode at init time to support bug 512435
-  if (!IsSizeDecode() && mObserver)
-    mObserver->OnStartDecode(nsnull);
-}
-
 void
 nsIconDecoder::FinishInternal()
 {
   // If we haven't notified of completion yet for a full/success decode, we
   // didn't finish. Notify in error mode
   if (!IsSizeDecode() && !mNotifiedDone)
     NotifyDone(/* aSuccess = */ PR_FALSE);
 }
--- a/modules/libpr0n/decoders/nsIconDecoder.h
+++ b/modules/libpr0n/decoders/nsIconDecoder.h
@@ -72,17 +72,16 @@ class RasterImage;
 
 class nsIconDecoder : public Decoder
 {
 public:
 
   nsIconDecoder();
   virtual ~nsIconDecoder();
 
-  virtual void InitInternal();
   virtual void WriteInternal(const char* aBuffer, PRUint32 aCount);
   virtual void FinishInternal();
 
   PRUint8 mWidth;
   PRUint8 mHeight;
   PRUint32 mPixBytesRead;
   PRUint32 mPixBytesTotal;
   PRUint8* mImageData;
--- a/modules/libpr0n/decoders/nsJPEGDecoder.cpp
+++ b/modules/libpr0n/decoders/nsJPEGDecoder.cpp
@@ -137,20 +137,16 @@ nsJPEGDecoder::~nsJPEGDecoder()
          ("nsJPEGDecoder::~nsJPEGDecoder: Destroying JPEG decoder %p",
           this));
 }
 
 
 void
 nsJPEGDecoder::InitInternal()
 {
-  /* Fire OnStartDecode at init time to support bug 512435 */
-  if (!IsSizeDecode() && mObserver)
-    mObserver->OnStartDecode(nsnull);
-
   /* We set up the normal JPEG error routines, then override error_exit. */
   mInfo.err = jpeg_std_error(&mErr.pub);
   /*   mInfo.err = jpeg_std_error(&mErr.pub); */
   mErr.pub.error_exit = my_error_exit;
   /* Establish the setjmp return context for my_error_exit to use. */
   if (setjmp(mErr.setjmp_buffer)) {
     /* If we get here, the JPEG code has signaled an error.
      * We need to clean up the JPEG object, close the input file, and return.
--- a/modules/libpr0n/decoders/nsPNGDecoder.cpp
+++ b/modules/libpr0n/decoders/nsPNGDecoder.cpp
@@ -230,20 +230,16 @@ nsPNGDecoder::InitInternal()
         112,  72,  89, 115, '\0',   /* pHYs */
         115,  66,  73,  84, '\0',   /* sBIT */
         115,  80,  76,  84, '\0',   /* sPLT */
         116,  69,  88, 116, '\0',   /* tEXt */
         116,  73,  77,  69, '\0',   /* tIME */
         122,  84,  88, 116, '\0'};  /* zTXt */
 #endif
 
-  // Fire OnStartDecode at init time to support bug 512435
-  if (!IsSizeDecode() && mObserver)
-    mObserver->OnStartDecode(nsnull);
-
   // For size decodes, we only need a small buffer
   if (IsSizeDecode()) {
     mHeaderBuf = (PRUint8 *)nsMemory::Alloc(BYTES_NEEDED_FOR_DIMENSIONS);
     if (!mHeaderBuf) {
       PostDecoderError(NS_ERROR_OUT_OF_MEMORY);
       return;
     }
     return;
--- a/modules/libpr0n/src/Decoder.cpp
+++ b/modules/libpr0n/src/Decoder.cpp
@@ -69,16 +69,20 @@ Decoder::Init(RasterImage* aImage, imgID
 
   // No re-initializing
   NS_ABORT_IF_FALSE(mImage == nsnull, "Can't re-initialize a decoder!");
 
   // Save our paremeters
   mImage = aImage;
   mObserver = aObserver;
 
+  // Fire OnStartDecode at init time to support bug 512435
+  if (!IsSizeDecode() && mObserver)
+      mObserver->OnStartDecode(nsnull);
+
   // Implementation-specific initialization
   InitInternal();
   mInitialized = true;
   return IsError() ? NS_ERROR_FAILURE : NS_OK;
 }
 
 nsresult
 Decoder::Write(const char* aBuffer, PRUint32 aCount)