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 762585 3809307f73101bc2e60355a5a3684c555f33e163
parent 762584 53e60d7b78a64370ecaa8ccc436543c436e8e692
child 762586 394a4df965d536f314e1119ab8c710b4079b9f5f
push id101211
push userbwerth@mozilla.com
push dateFri, 02 Mar 2018 18:20:33 +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();