Bug 1404222 Part 5: Translate the imgILoader flag into an Image flag passed to Image::Init(). draft
authorBrad Werth <bwerth@mozilla.com>
Fri, 16 Feb 2018 14:01:58 -0800
changeset 762262 5cb784f72082919098591d69d2f338e2cd1751fc
parent 762261 db3066bcf5116acafeaacd0d7975f4b56dc3a507
child 762263 878db8e338f75ebcb8cd0bef98aaccfe0287be13
push id101114
push userbwerth@mozilla.com
push dateThu, 01 Mar 2018 23:33:31 +0000
bugs1404222
milestone60.0a1
Bug 1404222 Part 5: Translate the imgILoader flag into an Image flag passed to Image::Init(). MozReview-Commit-ID: I0cEklbSOt4
image/Image.h
image/ImageFactory.cpp
--- a/image/Image.h
+++ b/image/Image.h
@@ -155,22 +155,26 @@ public:
    * INIT_FLAG_TRANSIENT: The container is likely to exist for only a short time
    * before being destroyed. (For example, containers for
    * multipart/x-mixed-replace image parts fall into this category.) If this
    * flag is set, INIT_FLAG_DISCARDABLE and INIT_FLAG_DECODE_ONLY_ON_DRAW must
    * not be set.
    *
    * INIT_FLAG_SYNC_LOAD: The container is being loaded synchronously, so
    * it should avoid relying on async workers to get the container ready.
+   *
+   * INIT_FLAG_LOADEVENT_AFTER_DECODE: When the image is loaded, don't
+   * allow an onLoad event to be sent until the image is fully decoded.
    */
   static const uint32_t INIT_FLAG_NONE                     = 0x0;
   static const uint32_t INIT_FLAG_DISCARDABLE              = 0x1;
   static const uint32_t INIT_FLAG_DECODE_IMMEDIATELY       = 0x2;
   static const uint32_t INIT_FLAG_TRANSIENT                = 0x4;
   static const uint32_t INIT_FLAG_SYNC_LOAD                = 0x8;
+  static const uint32_t INIT_FLAG_LOADEVENT_AFTER_DECODE   = 0x10;
 
   virtual already_AddRefed<ProgressTracker> GetProgressTracker() = 0;
   virtual void SetProgressTracker(ProgressTracker* aProgressTracker) {}
 
   /**
    * The size, in bytes, occupied by the compressed source data of the image.
    * If MallocSizeOf does not work on this platform, uses a fallback approach to
    * ensure that something reasonable is always returned.
--- a/image/ImageFactory.cpp
+++ b/image/ImageFactory.cpp
@@ -15,16 +15,17 @@
 #include "nsIFile.h"
 #include "nsMimeTypes.h"
 #include "nsIRequest.h"
 
 #include "MultipartImage.h"
 #include "RasterImage.h"
 #include "VectorImage.h"
 #include "Image.h"
+#include "imgILoader.h"
 #include "nsMediaFragmentURIParser.h"
 #include "nsContentUtils.h"
 #include "nsIScriptSecurityManager.h"
 
 #include "gfxPrefs.h"
 
 namespace mozilla {
 namespace image {
@@ -266,17 +267,27 @@ ImageFactory::CreateRasterImage(nsIReque
   MOZ_ASSERT(aProgressTracker);
 
   nsresult rv;
 
   RefPtr<RasterImage> newImage = new RasterImage(aURI);
   aProgressTracker->SetImage(newImage);
   newImage->SetProgressTracker(aProgressTracker);
 
-  rv = newImage->Init(aMimeType.get(), aImageFlags);
+  uint32_t imageFlags = aImageFlags;
+
+  // Accept the passed in aImageFlags, but add additional flags
+  // based upon the aRequest flags.
+  nsLoadFlags requestFlags;
+  aRequest->GetLoadFlags(&requestFlags);
+  if (requestFlags & imgILoader::DELAY_LOAD_EVENT_UNTIL_DECODE) {
+    imageFlags |= Image::INIT_FLAG_LOADEVENT_AFTER_DECODE;
+  }
+
+  rv = newImage->Init(aMimeType.get(), imageFlags);
   if (NS_FAILED(rv)) {
     return BadImage("RasterImage::Init failed", newImage);
   }
 
   newImage->SetInnerWindowID(aInnerWindowId);
 
   SetSourceSizeHint(newImage, GetContentSize(aRequest));
   return newImage.forget();