Bug 920630 - Part 3. Change Image/ImageResource and derived classes to use nsIURI directly instead of ImageURL. r=tnikkel
authorAndrew Osmond <aosmond@mozilla.com>
Tue, 05 Jun 2018 20:42:56 -0400
changeset 475740 7597bbcc9d66111326aa69048ad5847bdc7497f2
parent 475739 9f7a040f06f92605ca55f72b20a9863e906bfe2e
child 475741 dcf212d04876742f581acab5f428e703b54de82f
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstnikkel
bugs920630
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 920630 - Part 3. Change Image/ImageResource and derived classes to use nsIURI directly instead of ImageURL. r=tnikkel
image/DynamicImage.cpp
image/DynamicImage.h
image/Image.cpp
image/Image.h
image/ImageFactory.cpp
image/ImageFactory.h
image/ImageWrapper.cpp
image/ImageWrapper.h
image/RasterImage.cpp
image/RasterImage.h
image/VectorImage.cpp
image/VectorImage.h
--- a/image/DynamicImage.cpp
+++ b/image/DynamicImage.cpp
@@ -99,18 +99,18 @@ DynamicImage::HasError()
 {
   return !mDrawable;
 }
 
 void
 DynamicImage::SetHasError()
 { }
 
-ImageURL*
-DynamicImage::GetURI()
+nsIURI*
+DynamicImage::GetURI() const
 {
   return nullptr;
 }
 
 // Methods inherited from XPCOM interfaces.
 
 NS_IMPL_ISUPPORTS(DynamicImage, imgIContainer)
 
--- a/image/DynamicImage.h
+++ b/image/DynamicImage.h
@@ -58,17 +58,17 @@ public:
   virtual void OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey) override;
 
   virtual void SetInnerWindowID(uint64_t aInnerWindowId) override;
   virtual uint64_t InnerWindowID() const override;
 
   virtual bool HasError() override;
   virtual void SetHasError() override;
 
-  virtual ImageURL* GetURI() override;
+  nsIURI* GetURI() const override;
 
 private:
   virtual ~DynamicImage() { }
 
   RefPtr<gfxDrawable> mDrawable;
 };
 
 } // namespace image
--- a/image/Image.cpp
+++ b/image/Image.cpp
@@ -21,17 +21,17 @@ namespace image {
 ImageMemoryCounter::ImageMemoryCounter(Image* aImage,
                                        SizeOfState& aState,
                                        bool aIsUsed)
   : mIsUsed(aIsUsed)
 {
   MOZ_ASSERT(aImage);
 
   // Extract metadata about the image.
-  RefPtr<ImageURL> imageURL(aImage->GetURI());
+  nsCOMPtr<nsIURI> imageURL(aImage->GetURI());
   if (imageURL) {
     imageURL->GetSpec(mURI);
   }
 
   int32_t width = 0;
   int32_t height = 0;
   aImage->GetWidth(&width);
   aImage->GetHeight(&height);
@@ -49,16 +49,30 @@ ImageMemoryCounter::ImageMemoryCounter(I
   }
 }
 
 
 ///////////////////////////////////////////////////////////////////////////////
 // Image Base Types
 ///////////////////////////////////////////////////////////////////////////////
 
+bool
+ImageResource::GetSpecTruncatedTo1k(nsCString& aSpec) const
+{
+  static const size_t sMaxTruncatedLength = 1024;
+
+  mURI->GetSpec(aSpec);
+  if (sMaxTruncatedLength >= aSpec.Length()) {
+    return true;
+  }
+
+  aSpec.Truncate(sMaxTruncatedLength);
+  return false;
+}
+
 void
 ImageResource::SetCurrentImage(ImageContainer* aContainer,
                                SourceSurface* aSurface,
                                bool aInTransaction)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aContainer);
 
@@ -264,17 +278,17 @@ ImageResource::UpdateImageContainer()
 void
 ImageResource::ReleaseImageContainer()
 {
   MOZ_ASSERT(NS_IsMainThread());
   mImageContainers.Clear();
 }
 
 // Constructor
-ImageResource::ImageResource(ImageURL* aURI) :
+ImageResource::ImageResource(nsIURI* aURI) :
   mURI(aURI),
   mInnerWindowId(0),
   mAnimationConsumers(0),
   mAnimationMode(kNormalAnimMode),
   mInitialized(false),
   mAnimating(false),
   mError(false),
   mImageProducerID(ImageContainer::AllocateProducerID()),
@@ -399,17 +413,17 @@ ImageResource::NotifyDrawingObservers()
 
   bool match = false;
   if ((NS_FAILED(mURI->SchemeIs("resource", &match)) || !match) &&
       (NS_FAILED(mURI->SchemeIs("chrome", &match)) || !match)) {
     return;
   }
 
   // Record the image drawing for startup performance testing.
-  nsCOMPtr<nsIURI> uri = mURI->ToIURI();
+  nsCOMPtr<nsIURI> uri = mURI;
   nsContentUtils::AddScriptRunner(NS_NewRunnableFunction(
     "image::ImageResource::NotifyDrawingObservers", [uri]() {
       nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
       NS_WARNING_ASSERTION(obs, "Can't get an observer service handle");
       if (obs) {
         nsAutoCString spec;
         uri->GetSpec(spec);
         obs->NotifyObservers(nullptr, "image-drawing", NS_ConvertUTF8toUTF16(spec).get());
--- a/image/Image.h
+++ b/image/Image.h
@@ -6,17 +6,16 @@
 #ifndef mozilla_image_Image_h
 #define mozilla_image_Image_h
 
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/Tuple.h"
 #include "mozilla/TimeStamp.h"
 #include "gfx2DGlue.h"
 #include "imgIContainer.h"
-#include "ImageURL.h"
 #include "ImageContainer.h"
 #include "LookupResult.h"
 #include "nsStringFwd.h"
 #include "ProgressTracker.h"
 #include "SurfaceCache.h"
 
 class nsIRequest;
 class nsIInputStream;
@@ -228,17 +227,17 @@ public:
   virtual void OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey) = 0;
 
   virtual void SetInnerWindowID(uint64_t aInnerWindowId) = 0;
   virtual uint64_t InnerWindowID() const = 0;
 
   virtual bool HasError() = 0;
   virtual void SetHasError() = 0;
 
-  virtual ImageURL* GetURI() = 0;
+  virtual nsIURI* GetURI() const = 0;
 
   virtual void ReportUseCounters() { }
 };
 
 class ImageResource : public Image
 {
 public:
   already_AddRefed<ProgressTracker> GetProgressTracker() override
@@ -274,22 +273,24 @@ public:
 
   virtual bool HasError() override    { return mError; }
   virtual void SetHasError() override { mError = true; }
 
   /*
    * Returns a non-AddRefed pointer to the URI associated with this image.
    * Illegal to use off-main-thread.
    */
-  virtual ImageURL* GetURI() override { return mURI.get(); }
+  nsIURI* GetURI() const override { return mURI; }
 
 protected:
-  explicit ImageResource(ImageURL* aURI);
+  explicit ImageResource(nsIURI* aURI);
   ~ImageResource();
 
+  bool GetSpecTruncatedTo1k(nsCString& aSpec) const;
+
   // Shared functionality for implementors of imgIContainer. Every
   // implementation of attribute animationMode should forward here.
   nsresult GetAnimationModeInternal(uint16_t* aAnimationMode);
   nsresult SetAnimationModeInternal(uint16_t aAnimationMode);
 
   /**
    * Helper for RequestRefresh.
    *
@@ -321,18 +322,18 @@ protected:
   void SendOnUnlockedDraw(uint32_t aFlags);
 
 #ifdef DEBUG
   // Records the image drawing for startup performance testing.
   void NotifyDrawingObservers();
 #endif
 
   // Member data shared by all implementations of this abstract class
-  RefPtr<ProgressTracker>     mProgressTracker;
-  RefPtr<ImageURL>            mURI;
+  RefPtr<ProgressTracker>       mProgressTracker;
+  nsCOMPtr<nsIURI>              mURI;
   TimeStamp                     mLastRefreshTime;
   uint64_t                      mInnerWindowId;
   uint32_t                      mAnimationConsumers;
   uint16_t                      mAnimationMode; // Enum values in imgIContainer
   bool                          mInitialized:1; // Have we been initalized?
   bool                          mAnimating:1;   // Are we currently animating?
   bool                          mError:1;       // Error handling
 
--- a/image/ImageFactory.cpp
+++ b/image/ImageFactory.cpp
@@ -29,17 +29,17 @@
 namespace mozilla {
 namespace image {
 
 /*static*/ void
 ImageFactory::Initialize()
 { }
 
 static uint32_t
-ComputeImageFlags(ImageURL* uri, const nsCString& aMimeType, bool isMultiPart)
+ComputeImageFlags(nsIURI* uri, const nsCString& aMimeType, bool isMultiPart)
 {
   nsresult rv;
 
   // We default to the static globals.
   bool isDiscardable = gfxPrefs::ImageMemDiscardable();
   bool doDecodeImmediately = gfxPrefs::ImageDecodeImmediatelyEnabled();
 
   // We want UI to be as snappy as possible and not to flicker. Disable
@@ -83,20 +83,20 @@ ComputeImageFlags(ImageURL* uri, const n
     imageFlags |= Image::INIT_FLAG_SYNC_LOAD;
   }
 
   return imageFlags;
 }
 
 #ifdef DEBUG
 static void
-NotifyImageLoading(ImageURL* aURI)
+NotifyImageLoading(nsIURI* aURI)
 {
   if (!NS_IsMainThread()) {
-    RefPtr<ImageURL> uri(aURI);
+    nsCOMPtr<nsIURI> uri(aURI);
     nsCOMPtr<nsIRunnable> ev =
       NS_NewRunnableFunction("NotifyImageLoading", [uri] () -> void {
         NotifyImageLoading(uri);
     });
     SystemGroup::Dispatch(TaskCategory::Other, ev.forget());
     return;
   }
 
@@ -109,17 +109,17 @@ NotifyImageLoading(ImageURL* aURI)
   }
 }
 #endif
 
 /* static */ already_AddRefed<Image>
 ImageFactory::CreateImage(nsIRequest* aRequest,
                           ProgressTracker* aProgressTracker,
                           const nsCString& aMimeType,
-                          ImageURL* aURI,
+                          nsIURI* aURI,
                           bool aIsMultiPart,
                           uint32_t aInnerWindowId)
 {
   MOZ_ASSERT(gfxPrefs::SingletonExists(),
              "Pref observers should have been initialized already");
 
   // Compute the image's initialization flags.
   uint32_t imageFlags = ComputeImageFlags(aURI, aMimeType, aIsMultiPart);
@@ -235,17 +235,17 @@ GetContentSize(nsIRequest* aRequest)
   // Fallback - neither http nor file. We'll use dynamic allocation.
   return 0;
 }
 
 /* static */ already_AddRefed<Image>
 ImageFactory::CreateRasterImage(nsIRequest* aRequest,
                                 ProgressTracker* aProgressTracker,
                                 const nsCString& aMimeType,
-                                ImageURL* aURI,
+                                nsIURI* aURI,
                                 uint32_t aImageFlags,
                                 uint32_t aInnerWindowId)
 {
   MOZ_ASSERT(aProgressTracker);
 
   nsresult rv;
 
   RefPtr<RasterImage> newImage = new RasterImage(aURI);
@@ -266,17 +266,17 @@ ImageFactory::CreateRasterImage(nsIReque
 
   return newImage.forget();
 }
 
 /* static */ already_AddRefed<Image>
 ImageFactory::CreateVectorImage(nsIRequest* aRequest,
                                 ProgressTracker* aProgressTracker,
                                 const nsCString& aMimeType,
-                                ImageURL* aURI,
+                                nsIURI* aURI,
                                 uint32_t aImageFlags,
                                 uint32_t aInnerWindowId)
 {
   MOZ_ASSERT(aProgressTracker);
 
   nsresult rv;
 
   RefPtr<VectorImage> newImage = new VectorImage(aURI);
--- a/image/ImageFactory.h
+++ b/image/ImageFactory.h
@@ -7,22 +7,22 @@
 #ifndef mozilla_image_ImageFactory_h
 #define mozilla_image_ImageFactory_h
 
 #include "nsCOMPtr.h"
 #include "nsProxyRelease.h"
 #include "nsStringFwd.h"
 
 class nsIRequest;
+class nsIURI;
 
 namespace mozilla {
 namespace image {
 
 class Image;
-class ImageURL;
 class MultipartImage;
 class ProgressTracker;
 
 class ImageFactory
 {
 public:
   /**
    * Registers vars with Preferences. Should only be called on the main thread.
@@ -38,17 +38,17 @@ public:
    * @param aMimeType        The mimetype of the image.
    * @param aURI             The URI of the image.
    * @param aIsMultiPart     Whether the image is part of a multipart request.
    * @param aInnerWindowId   The window this image belongs to.
    */
   static already_AddRefed<Image> CreateImage(nsIRequest* aRequest,
                                              ProgressTracker* aProgressTracker,
                                              const nsCString& aMimeType,
-                                             ImageURL* aURI,
+                                             nsIURI* aURI,
                                              bool aIsMultiPart,
                                              uint32_t aInnerWindowId);
   /**
    * Creates a new image which isn't associated with a URI or loaded through
    * the usual image loading mechanism.
    *
    * @param aMimeType      The mimetype of the image.
    * @param aSizeHint      The length of the source data for the image.
@@ -69,25 +69,25 @@ public:
   CreateMultipartImage(Image* aFirstPart, ProgressTracker* aProgressTracker);
 
 private:
   // Factory functions that create specific types of image containers.
   static already_AddRefed<Image>
   CreateRasterImage(nsIRequest* aRequest,
                     ProgressTracker* aProgressTracker,
                     const nsCString& aMimeType,
-                    ImageURL* aURI,
+                    nsIURI* aURI,
                     uint32_t aImageFlags,
                     uint32_t aInnerWindowId);
 
   static already_AddRefed<Image>
   CreateVectorImage(nsIRequest* aRequest,
                     ProgressTracker* aProgressTracker,
                     const nsCString& aMimeType,
-                    ImageURL* aURI,
+                    nsIURI* aURI,
                     uint32_t aImageFlags,
                     uint32_t aInnerWindowId);
 
   // This is a static factory class, so disallow instantiation.
   virtual ~ImageFactory() = 0;
 };
 
 } // namespace image
--- a/image/ImageWrapper.cpp
+++ b/image/ImageWrapper.cpp
@@ -112,18 +112,18 @@ ImageWrapper::HasError()
 }
 
 void
 ImageWrapper::SetHasError()
 {
   mInnerImage->SetHasError();
 }
 
-ImageURL*
-ImageWrapper::GetURI()
+nsIURI*
+ImageWrapper::GetURI() const
 {
   return mInnerImage->GetURI();
 }
 
 // Methods inherited from XPCOM interfaces.
 
 NS_IMPL_ISUPPORTS(ImageWrapper, imgIContainer)
 
--- a/image/ImageWrapper.h
+++ b/image/ImageWrapper.h
@@ -50,17 +50,17 @@ public:
   virtual void OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey) override;
 
   virtual void SetInnerWindowID(uint64_t aInnerWindowId) override;
   virtual uint64_t InnerWindowID() const override;
 
   virtual bool HasError() override;
   virtual void SetHasError() override;
 
-  virtual ImageURL* GetURI() override;
+  nsIURI* GetURI() const override;
 
 protected:
   explicit ImageWrapper(Image* aInnerImage)
     : mInnerImage(aInnerImage)
   {
     MOZ_ASSERT(aInnerImage, "Need an image to wrap");
   }
 
--- a/image/RasterImage.cpp
+++ b/image/RasterImage.cpp
@@ -65,17 +65,17 @@ using std::min;
 #ifndef DEBUG
 NS_IMPL_ISUPPORTS(RasterImage, imgIContainer, nsIProperties)
 #else
 NS_IMPL_ISUPPORTS(RasterImage, imgIContainer, nsIProperties,
                   imgIContainerDebug)
 #endif
 
 //******************************************************************************
-RasterImage::RasterImage(ImageURL* aURI /* = nullptr */) :
+RasterImage::RasterImage(nsIURI* aURI /* = nullptr */) :
   ImageResource(aURI), // invoke superclass's constructor
   mSize(0,0),
   mLockCount(0),
   mDecodeCount(0),
 #ifdef DEBUG
   mFramesNotified(0),
 #endif
   mSourceBuffer(MakeNotNull<SourceBuffer*>()),
@@ -1812,18 +1812,18 @@ RasterImage::ReportDecoderError()
     do_GetService(NS_CONSOLESERVICE_CONTRACTID);
   nsCOMPtr<nsIScriptError> errorObject =
     do_CreateInstance(NS_SCRIPTERROR_CONTRACTID);
 
   if (consoleService && errorObject) {
     nsAutoString msg(NS_LITERAL_STRING("Image corrupt or truncated."));
     nsAutoString src;
     if (GetURI()) {
-      nsCString uri;
-      if (GetURI()->GetSpecTruncatedTo1k(uri) == ImageURL::TruncatedTo1k) {
+      nsAutoCString uri;
+      if (!GetSpecTruncatedTo1k(uri)) {
         msg += NS_LITERAL_STRING(" URI in this note truncated due to length.");
       }
       src = NS_ConvertUTF8toUTF16(uri);
     }
     if (NS_SUCCEEDED(errorObject->InitWithWindowID(
                        msg,
                        src,
                        EmptyString(), 0, 0, nsIScriptError::errorFlag,
--- a/image/RasterImage.h
+++ b/image/RasterImage.h
@@ -464,17 +464,17 @@ private: // data
   // Helpers
   bool CanDiscard();
 
   bool IsOpaque();
 
   DrawableSurface RequestDecodeForSizeInternal(const gfx::IntSize& aSize, uint32_t aFlags);
 
 protected:
-  explicit RasterImage(ImageURL* aURI = nullptr);
+  explicit RasterImage(nsIURI* aURI = nullptr);
 
   bool ShouldAnimate() override;
 
   friend class ImageFactory;
 };
 
 inline NS_IMETHODIMP
 RasterImage::GetAnimationMode(uint16_t* aAnimationMode) {
--- a/image/VectorImage.cpp
+++ b/image/VectorImage.cpp
@@ -366,17 +366,17 @@ private:
 NS_IMPL_ISUPPORTS(VectorImage,
                   imgIContainer,
                   nsIStreamListener,
                   nsIRequestObserver)
 
 //------------------------------------------------------------------------------
 // Constructor / Destructor
 
-VectorImage::VectorImage(ImageURL* aURI /* = nullptr */) :
+VectorImage::VectorImage(nsIURI* aURI /* = nullptr */) :
   ImageResource(aURI), // invoke superclass's constructor
   mLockCount(0),
   mIsInitialized(false),
   mIsFullyLoaded(false),
   mIsDrawing(false),
   mHaveAnimations(false),
   mHasPendingInvalidation(false)
 { }
@@ -917,18 +917,17 @@ VectorImage::MaybeRestrictSVGContext(May
                                      const Maybe<SVGImageContext>& aSVGContext,
                                      uint32_t aFlags)
 {
   bool overridePAR = (aFlags & FLAG_FORCE_PRESERVEASPECTRATIO_NONE) && aSVGContext;
 
   bool haveContextPaint = aSVGContext && aSVGContext->GetContextPaint();
   bool blockContextPaint = false;
   if (haveContextPaint) {
-    nsCOMPtr<nsIURI> imageURI = mURI->ToIURI();
-    blockContextPaint = !SVGContextPaint::IsAllowedForImageFromURI(imageURI);
+    blockContextPaint = !SVGContextPaint::IsAllowedForImageFromURI(mURI);
   }
 
   if (overridePAR || blockContextPaint) {
     // The key that we create for the image surface cache must match the way
     // that the image will be painted, so we need to initialize a new matching
     // SVGImageContext here in order to generate the correct key.
 
     aNewSVGContext = aSVGContext; // copy
--- a/image/VectorImage.h
+++ b/image/VectorImage.h
@@ -68,17 +68,17 @@ public:
 
   // Callbacks for SVGLoadEventListener.
   void OnSVGDocumentLoaded();
   void OnSVGDocumentError();
 
   virtual void ReportUseCounters() override;
 
 protected:
-  explicit VectorImage(ImageURL* aURI = nullptr);
+  explicit VectorImage(nsIURI* aURI = nullptr);
   virtual ~VectorImage();
 
   virtual nsresult StartAnimation() override;
   virtual nsresult StopAnimation() override;
   virtual bool     ShouldAnimate() override;
 
 private:
   Tuple<ImgDrawResult, IntSize, RefPtr<SourceSurface>>