Index: third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp |
diff --git a/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp b/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp |
index b3bd7d93278ee227f858d7c18dbbf28eacff334c..b45274cadd1c2e9b4c2724d300e7a0cd9bf33b94 100644 |
--- a/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp |
+++ b/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp |
@@ -80,49 +80,65 @@ inline bool matchesBMPSignature(const char* contents) |
return !memcmp(contents, "BM", 2); |
} |
-std::unique_ptr<ImageDecoder> ImageDecoder::create(const char* contents, size_t length, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions) |
+std::unique_ptr<ImageDecoder> ImageDecoder::create(SniffResult sniffResult, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions) |
{ |
- const size_t longestSignatureLength = sizeof("RIFF????WEBPVP") - 1; |
- ASSERT(longestSignatureLength == 14); |
+ size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecodedImageBytes() : noDecodedImageByteLimit; |
- if (length < longestSignatureLength) |
+ switch (sniffResult) { |
+ case SniffResult::JPEG: |
+ return wrapUnique(new JPEGImageDecoder(alphaOption, colorOptions, maxDecodedBytes)); |
+ case SniffResult::PNG: |
+ return wrapUnique(new PNGImageDecoder(alphaOption, colorOptions, maxDecodedBytes)); |
+ case SniffResult::GIF: |
+ return wrapUnique(new GIFImageDecoder(alphaOption, colorOptions, maxDecodedBytes)); |
+ case SniffResult::WEBP: |
+ return wrapUnique(new WEBPImageDecoder(alphaOption, colorOptions, maxDecodedBytes)); |
+ case SniffResult::ICO: |
+ return wrapUnique(new ICOImageDecoder(alphaOption, colorOptions, maxDecodedBytes)); |
+ case SniffResult::BMP: |
+ return wrapUnique(new BMPImageDecoder(alphaOption, colorOptions, maxDecodedBytes)); |
+ case SniffResult::InsufficientData: |
+ case SniffResult::Invalid: |
return nullptr; |
+ } |
+ NOTREACHED(); |
+ return nullptr; |
+} |
- size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecodedImageBytes() : noDecodedImageByteLimit; |
+ImageDecoder::SniffResult ImageDecoder::determineImageType(const char* contents, size_t length) |
+{ |
+ const size_t longestSignatureLength = sizeof("RIFF????WEBPVP") - 1; |
+ DCHECK_EQ(14u, longestSignatureLength); |
+ if (length < longestSignatureLength) |
+ return SniffResult::InsufficientData; |
if (matchesJPEGSignature(contents)) |
- return wrapUnique(new JPEGImageDecoder(alphaOption, colorOptions, maxDecodedBytes)); |
- |
+ return SniffResult::JPEG; |
if (matchesPNGSignature(contents)) |
- return wrapUnique(new PNGImageDecoder(alphaOption, colorOptions, maxDecodedBytes)); |
- |
+ return SniffResult::PNG; |
if (matchesGIFSignature(contents)) |
- return wrapUnique(new GIFImageDecoder(alphaOption, colorOptions, maxDecodedBytes)); |
- |
+ return SniffResult::GIF; |
if (matchesWebPSignature(contents)) |
- return wrapUnique(new WEBPImageDecoder(alphaOption, colorOptions, maxDecodedBytes)); |
- |
+ return SniffResult::WEBP; |
if (matchesICOSignature(contents) || matchesCURSignature(contents)) |
- return wrapUnique(new ICOImageDecoder(alphaOption, colorOptions, maxDecodedBytes)); |
- |
+ return SniffResult::ICO; |
if (matchesBMPSignature(contents)) |
- return wrapUnique(new BMPImageDecoder(alphaOption, colorOptions, maxDecodedBytes)); |
- |
- return nullptr; |
+ return SniffResult::BMP; |
+ return SniffResult::Invalid; |
} |
-std::unique_ptr<ImageDecoder> ImageDecoder::create(const SharedBuffer& data, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions) |
+ImageDecoder::SniffResult ImageDecoder::determineImageType(const SharedBuffer& data) |
{ |
const char* contents; |
const size_t length = data.getSomeData<size_t>(contents); |
- return create(contents, length, alphaOption, colorOptions); |
+ return determineImageType(contents, length); |
} |
-std::unique_ptr<ImageDecoder> ImageDecoder::create(const SegmentReader& data, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions) |
+ImageDecoder::SniffResult ImageDecoder::determineImageType(const SegmentReader& data) |
{ |
const char* contents; |
const size_t length = data.getSomeData(contents, 0); |
- return create(contents, length, alphaOption, colorOptions); |
+ return determineImageType(contents, length); |
} |
size_t ImageDecoder::frameCount() |