Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
| diff --git a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
| index 80d196bcc1ba02d4519451fad4f66b009db6d91f..81ea8feeff2dce39c42e1255e1a24a77aacce6a6 100644 |
| --- a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
| +++ b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
| @@ -492,14 +492,44 @@ void HTMLCanvasElement::setSurfaceSize(const IntSize& size) |
| } |
| } |
| -String HTMLCanvasElement::toEncodingMimeType(const String& mimeType) |
| +String HTMLCanvasElement::toEncodingMimeType(const String& mimeType, const String& callFunctionName) |
| { |
| String lowercaseMimeType = mimeType.lower(); |
| + if (mimeType.isNull()) |
| + lowercaseMimeType = DefaultMimeType; |
| + |
| + CanvasReturnImageFormat imageFormat; |
| + if (lowercaseMimeType == "image/png") { |
| + imageFormat = CanvasReturnImageFormat::Png; |
| + } else if (lowercaseMimeType == "image/jpeg") { |
| + imageFormat = CanvasReturnImageFormat::Jpeg; |
| + } else if (lowercaseMimeType == "image/webp") { |
| + imageFormat = CanvasReturnImageFormat::Webp; |
| + } else if (lowercaseMimeType == "image/gif") { |
| + imageFormat = CanvasReturnImageFormat::Gif; |
| + } else if (lowercaseMimeType == "image/bmp") { |
|
Justin Novosad
2016/03/22 15:09:04
There is also an alternate MIME type for bmp: imag
|
| + imageFormat = CanvasReturnImageFormat::Bmp; |
| + } else if (lowercaseMimeType == "image/ico") { |
|
Justin Novosad
2016/03/22 15:09:03
this is not a valid MIME type. should be "image/x-
|
| + imageFormat = CanvasReturnImageFormat::Ico; |
| + } else if (lowercaseMimeType == "image/tiff") { |
|
Justin Novosad
2016/03/22 15:09:03
can also be image/x-tiff
|
| + imageFormat = CanvasReturnImageFormat::Tiff; |
| + } else { |
| + imageFormat = CanvasReturnImageFormat::NumberOfImageFormats; |
| + } |
| + |
| + if (imageFormat != CanvasReturnImageFormat::NumberOfImageFormats) { |
| + if (callFunctionName == "toDataURL") { |
| + DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, toDataURLImageFormatHistogram, new EnumerationHistogram("Canvas.ReturnImageFormats.toDataURL", CanvasReturnImageFormat::NumberOfImageFormats)); |
| + toDataURLImageFormatHistogram.count(imageFormat); |
| + } else if (callFunctionName == "toBlobCallback") { |
| + DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, toBlobCallbackImageFormatHistogram, new EnumerationHistogram("Canvas.ReturnImageFormats.toBlobCallback", CanvasReturnImageFormat::NumberOfImageFormats)); |
| + toBlobCallbackImageFormatHistogram.count(imageFormat); |
| + } |
| + } |
| // FIXME: Make isSupportedImageMIMETypeForEncoding threadsafe (to allow this method to be used on a worker thread). |
| - if (mimeType.isNull() || !MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(lowercaseMimeType)) |
| + if (!MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(lowercaseMimeType)) |
| lowercaseMimeType = DefaultMimeType; |
| - |
| return lowercaseMimeType; |
| } |
| @@ -554,7 +584,7 @@ String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double |
| if (!isPaintable()) |
| return String("data:,"); |
| - String encodingMimeType = toEncodingMimeType(mimeType); |
| + String encodingMimeType = toEncodingMimeType(mimeType, "toDataURL"); |
| ImageData* imageData = toImageData(sourceBuffer, SnapshotReasonToDataURL); |
| ScopedDisposal<ImageData> disposer(imageData); |
| @@ -599,7 +629,7 @@ void HTMLCanvasElement::toBlob(BlobCallback* callback, const String& mimeType, c |
| } |
| } |
| - String encodingMimeType = toEncodingMimeType(mimeType); |
| + String encodingMimeType = toEncodingMimeType(mimeType, "toBlobCallback"); |
| ImageData* imageData = toImageData(BackBuffer, SnapshotReasonToBlob); |
| // imageData unref its data, which we still keep alive for the async toBlob thread |