Bug 1404222 Part 5: Translate the imgILoader flag into an Image flag passed to Image::Init().
MozReview-Commit-ID: I0cEklbSOt4
--- 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();