Bug 593489 - Make Image hold onto its URI.r=joe,a=blockerblocker
authorBobby Holley <bobbyholley@gmail.com>
Sun, 12 Sep 2010 08:22:26 -0700
changeset 53660 dbdd01fabe455d0497143136fc68264279f00f1f
parent 53659 4252fe859077c6b465cb0c12a8203b1756683602
child 53661 bdad0efef3000038c5b22fe796ef189157c07a28
push idunknown
push userunknown
push dateunknown
reviewersjoe, blockerblocker
bugs593489
milestone2.0b6pre
Bug 593489 - Make Image hold onto its URI.r=joe,a=blockerblocker
modules/libpr0n/src/Image.h
modules/libpr0n/src/RasterImage.cpp
modules/libpr0n/src/RasterImage.h
modules/libpr0n/src/VectorImage.cpp
modules/libpr0n/src/VectorImage.h
modules/libpr0n/src/imgRequest.cpp
modules/libpr0n/src/imgTools.cpp
--- a/modules/libpr0n/src/Image.h
+++ b/modules/libpr0n/src/Image.h
@@ -75,16 +75,17 @@ public:
    * Creates a new image container.
    *
    * @param aObserver Observer to send decoder and animation notifications to.
    * @param aMimeType The mimetype of the image.
    * @param aFlags Initialization flags of the INIT_FLAG_* variety.
    */
   virtual nsresult Init(imgIDecoderObserver* aObserver,
                         const char* aMimeType,
+                        const char* aURIString,
                         PRUint32 aFlags) = 0;
 
   /**
    * The rectangle defining the location and size of the currently displayed
    * frame.
    */
   virtual void GetCurrentFrameRect(nsIntRect& aRect) = 0;
 
--- a/modules/libpr0n/src/RasterImage.cpp
+++ b/modules/libpr0n/src/RasterImage.cpp
@@ -246,16 +246,17 @@ RasterImage::~RasterImage()
   // Total statistics
   num_containers--;
   total_source_bytes -= mSourceData.Length();
 }
 
 nsresult
 RasterImage::Init(imgIDecoderObserver *aObserver,
                   const char* aMimeType,
+                  const char* aURIString,
                   PRUint32 aFlags)
 {
   // We don't support re-initialization
   if (mInitialized)
     return NS_ERROR_ILLEGAL_VALUE;
 
   // Not sure an error can happen before init, but be safe
   if (mError)
@@ -268,16 +269,17 @@ RasterImage::Init(imgIDecoderObserver *a
   NS_ABORT_IF_FALSE(!(aFlags & INIT_FLAG_MULTIPART) ||
                     (!(aFlags & INIT_FLAG_DISCARDABLE) &&
                      !(aFlags & INIT_FLAG_DECODE_ON_DRAW)),
                     "Can't be discardable or decode-on-draw for multipart");
 
   // Store initialization data
   mObserver = do_GetWeakReference(aObserver);
   mSourceDataMimeType.Assign(aMimeType);
+  mURIString.Assign(aURIString);
   mDiscardable = !!(aFlags & INIT_FLAG_DISCARDABLE);
   mDecodeOnDraw = !!(aFlags & INIT_FLAG_DECODE_ON_DRAW);
   mMultipart = !!(aFlags & INIT_FLAG_MULTIPART);
 
   // Statistics
   if (mDiscardable) {
     num_discardable_containers++;
     discardable_source_bytes += mSourceData.Length();
@@ -331,17 +333,17 @@ RasterImage::ExtractFrame(PRUint32 aWhic
 
   // Make a new container. This should switch to another class with bug 505959.
   nsRefPtr<RasterImage> img(new RasterImage());
   NS_ENSURE_TRUE(img, NS_ERROR_OUT_OF_MEMORY);
 
   // We don't actually have a mimetype in this case. The empty string tells the
   // init routine not to try to instantiate a decoder. This should be fixed in
   // bug 505959.
-  img->Init(nsnull, "", INIT_FLAG_NONE);
+  img->Init(nsnull, "", "", INIT_FLAG_NONE);
   img->SetSize(aRegion.width, aRegion.height);
   img->mDecoded = PR_TRUE; // Also, we need to mark the image as decoded
   img->mHasBeenDecoded = PR_TRUE;
 
   // If a synchronous decode was requested, do it
   if (aFlags & FLAG_SYNC_DECODE) {
     rv = SyncDecode();
     CONTAINER_ENSURE_SUCCESS(rv);
--- a/modules/libpr0n/src/RasterImage.h
+++ b/modules/libpr0n/src/RasterImage.h
@@ -172,16 +172,17 @@ public:
   virtual nsresult StopAnimation();
 
   // C++-only version of imgIContainer::GetType, for convenience
   virtual PRUint16 GetType() { return imgIContainer::TYPE_RASTER; }
 
   // Methods inherited from Image
   nsresult Init(imgIDecoderObserver* aObserver,
                 const char* aMimeType,
+                const char* aURIString,
                 PRUint32 aFlags);
   void     GetCurrentFrameRect(nsIntRect& aRect);
   PRUint32 GetDataSize();
 
   // Raster-specific methods
   static NS_METHOD WriteToRasterImage(nsIInputStream* aIn, void* aClosure,
                                       const char* aFromRawSegment,
                                       PRUint32 aToOffset, PRUint32 aCount,
@@ -468,16 +469,17 @@ private: // data
 
   // Discard members
   PRUint32                   mLockCount;
   DiscardTrackerNode         mDiscardTrackerNode;
 
   // Source data members
   nsTArray<char>             mSourceData;
   nsCString                  mSourceDataMimeType;
+  nsCString                  mURIString;
 
   friend class imgDecodeWorker;
   friend class DiscardTracker;
 
   // Decoder and friends
   nsRefPtr<Decoder>              mDecoder;
   nsRefPtr<imgDecodeWorker>      mWorker;
   PRUint32                       mBytesDecoded;
--- a/modules/libpr0n/src/VectorImage.cpp
+++ b/modules/libpr0n/src/VectorImage.cpp
@@ -216,16 +216,17 @@ VectorImage::~VectorImage()
 }
 
 //------------------------------------------------------------------------------
 // Methods inherited from Image.h
 
 nsresult
 VectorImage::Init(imgIDecoderObserver* aObserver,
                   const char* aMimeType,
+                  const char* aURIString,
                   PRUint32 aFlags)
 {
   // We don't support re-initialization
   if (mIsInitialized)
     return NS_ERROR_ILLEGAL_VALUE;
 
   NS_ABORT_IF_FALSE(!mIsFullyLoaded && !mHaveAnimations &&
                     !mHaveRestrictedRegion && !mError,
--- a/modules/libpr0n/src/VectorImage.h
+++ b/modules/libpr0n/src/VectorImage.h
@@ -64,16 +64,17 @@ public:
   virtual ~VectorImage();
 
   // C++-only version of imgIContainer::GetType, for convenience
   PRUint16 GetType() { return imgIContainer::TYPE_VECTOR; }
 
   // Methods inherited from Image
   nsresult Init(imgIDecoderObserver* aObserver,
                 const char* aMimeType,
+                const char* aURIString,
                 PRUint32 aFlags);
   void GetCurrentFrameRect(nsIntRect& aRect);
   PRUint32 GetDataSize();
 
   // Callback for SVGRootRenderingObserver
   void InvalidateObserver();
 
 protected:
--- a/modules/libpr0n/src/imgRequest.cpp
+++ b/modules/libpr0n/src/imgRequest.cpp
@@ -1101,20 +1101,26 @@ NS_IMETHODIMP imgRequest::OnDataAvailabl
     PRUint32 imageFlags = Image::INIT_FLAG_NONE;
     if (isDiscardable)
       imageFlags |= Image::INIT_FLAG_DISCARDABLE;
     if (doDecodeOnDraw)
       imageFlags |= Image::INIT_FLAG_DECODE_ON_DRAW;
     if (mIsMultiPartChannel)
       imageFlags |= Image::INIT_FLAG_MULTIPART;
 
+    // Get our URI string
+    nsCAutoString uriString;
+    rv = mURI->GetSpec(uriString);
+    if (NS_FAILED(rv))
+      uriString.Assign("<unknown image URI>");
+
     // Initialize the image that we created above. For RasterImages, this
     // instantiates a decoder behind the scenes, so if we don't have a decoder
     // for this mimetype we'll find out about it here.
-    rv = mImage->Init(this, mContentType.get(), imageFlags);
+    rv = mImage->Init(this, mContentType.get(), uriString.get(), imageFlags);
     if (NS_FAILED(rv)) { // Probably bad mimetype
 
       this->Cancel(rv);
       return NS_BINDING_ABORTED;
     }
 
     if (imageType == imgIContainer::TYPE_RASTER) {
       /* Use content-length as a size hint for http channels. */
--- a/modules/libpr0n/src/imgTools.cpp
+++ b/modules/libpr0n/src/imgTools.cpp
@@ -89,17 +89,17 @@ NS_IMETHODIMP imgTools::DecodeImageData(
   } else {
     *aContainer = image = new RasterImage();
     NS_ADDREF(image);
   }
 
   // Initialize the Image. If we're using the one from the caller, we
   // require that it not be initialized.
   nsCString mimeType(aMimeType);
-  rv = image->Init(nsnull, mimeType.get(), Image::INIT_FLAG_NONE);
+  rv = image->Init(nsnull, mimeType.get(), "<unknown>", Image::INIT_FLAG_NONE);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIInputStream> inStream = aInStr;
   if (!NS_InputStreamIsBuffered(aInStr)) {
     nsCOMPtr<nsIInputStream> bufStream;
     rv = NS_NewBufferedInputStream(getter_AddRefs(bufStream), aInStr, 1024);
     if (NS_SUCCEEDED(rv))
       inStream = bufStream;