Bug 514033 - Error recovery for imagelib - part 1 - Introduce error tracking to Decoder.r=joe,a=blocker
authorBobby Holley <bobbyholley@gmail.com>
Sun, 12 Sep 2010 08:22:27 -0700
changeset 53661 bdad0efef3000038c5b22fe796ef189157c07a28
parent 53660 dbdd01fabe455d0497143136fc68264279f00f1f
child 53662 03486e7a7b322faa3e8860e1f0a6e662251f827d
push idunknown
push userunknown
push dateunknown
reviewersjoe, blocker
bugs514033
milestone2.0b6pre
Bug 514033 - Error recovery for imagelib - part 1 - Introduce error tracking to Decoder.r=joe,a=blocker
modules/libpr0n/src/Decoder.cpp
modules/libpr0n/src/Decoder.h
--- a/modules/libpr0n/src/Decoder.cpp
+++ b/modules/libpr0n/src/Decoder.cpp
@@ -38,19 +38,21 @@
 
 #include "Decoder.h"
 
 namespace mozilla {
 namespace imagelib {
 
 Decoder::Decoder()
   : mFrameCount(0)
+  , mFailCode(NS_OK)
   , mInitialized(false)
   , mSizeDecode(false)
   , mInFrame(false)
+  , mDataError(false)
 {
 }
 
 Decoder::~Decoder()
 {
   NS_WARN_IF_FALSE(!mInFrame, "Shutting down decoder mid-frame!");
   mInitialized = false;
 }
@@ -187,10 +189,30 @@ Decoder::PostInvalidation(nsIntRect& aRe
 {
   // We should be mid-frame
   NS_ABORT_IF_FALSE(mInFrame, "Can't invalidate when not mid-frame!");
 
   // Account for the new region
   mInvalidRect.UnionRect(mInvalidRect, aRect);
 }
 
+void
+Decoder::PostDataError()
+{
+  mDataError = true;
+
+  //XXXbholley - we should probably log to the web console here
+}
+
+void
+Decoder::PostDecoderError(nsresult aFailureCode)
+{
+  NS_ABORT_IF_FALSE(NS_FAILED(aFailureCode), "Not a failure code!");
+
+  mFailCode = aFailureCode;
+
+  // XXXbholley - we should report the image URI here, but imgContainer
+  // needs to know its URI first
+  NS_WARNING("Image decoding error - This is probably a bug!");
+}
+
 } // namespace imagelib
 } // namespace mozilla
--- a/modules/libpr0n/src/Decoder.h
+++ b/modules/libpr0n/src/Decoder.h
@@ -112,16 +112,22 @@ public:
     NS_ABORT_IF_FALSE(!mInitialized, "Can't set size decode after Init()!");
     mSizeDecode = aSizeDecode;
   }
 
   // The number of frames we have, including anything in-progress. Thus, this
   // is only 0 if we haven't begun any frames.
   PRUint32 GetFrameCount() { return mFrameCount; }
 
+  // Error tracking
+  bool IsError() { return IsDataError() || IsDecoderError(); };
+  bool IsDataError() { return mDataError; };
+  bool IsDecoderError() { return NS_FAILED(mFailCode); };
+  nsresult GetDecoderError() { return mFailCode; };
+
 protected:
 
   /*
    * Internal hooks. Decoder implementations may override these and
    * only these methods.
    */
   virtual nsresult InitInternal();
   virtual nsresult WriteInternal(const char* aBuffer, PRUint32 aCount);
@@ -139,29 +145,36 @@ protected:
   // notifications, and does internal book-keeping.
   void PostFrameStart();
   void PostFrameStop();
 
   // Called by the decoders when they have a region to invalidate. We may not
   // actually pass these invalidations on right away.
   void PostInvalidation(nsIntRect& aRect);
 
+  // Data errors are the fault of the source data, decoder errors are our fault
+  void PostDataError();
+  void PostDecoderError(nsresult aFailCode);
+
   /*
    * Member variables.
    *
    * XXX - Some of these become private later in the patch stack.
    */
   nsRefPtr<RasterImage> mImage;
   nsCOMPtr<imgIDecoderObserver> mObserver;
 
   PRUint32 mFrameCount; // Number of frames, including anything in-progress
 
   nsIntRect mInvalidRect; // Tracks an invalidation region in the current frame.
 
+  nsresult mFailCode;
+
   bool mInitialized;
   bool mSizeDecode;
   bool mInFrame;
+  bool mDataError;
 };
 
 } // namespace imagelib
 } // namespace mozilla
 
 #endif // MOZILLA_IMAGELIB_DECODER_H_