| 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..fc7e8c34c1f960c14315417cfa1c495d90a59d9d 100644
|
| --- a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
|
| +++ b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
|
| @@ -492,14 +492,55 @@ void HTMLCanvasElement::setSurfaceSize(const IntSize& size)
|
| }
|
| }
|
|
|
| -String HTMLCanvasElement::toEncodingMimeType(const String& mimeType)
|
| +// This enum is used in a UMA histogram; the values should not be changed.
|
| +enum RequestedImageMimeType {
|
| + RequestedImageMimeTypePng = 0,
|
| + RequestedImageMimeTypeJpeg = 1,
|
| + RequestedImageMimeTypeWebp = 2,
|
| + RequestedImageMimeTypeGif = 3,
|
| + RequestedImageMimeTypeBmp = 4,
|
| + RequestedImageMimeTypeIco = 5,
|
| + RequestedImageMimeTypeTiff = 6,
|
| + RequestedImageMimeTypeUnknown = 7,
|
| + NumberOfRequestedImageMimeTypes
|
| +};
|
| +
|
| +String HTMLCanvasElement::toEncodingMimeType(const String& mimeType, const EncodeReason encodeReason)
|
| {
|
| String lowercaseMimeType = mimeType.lower();
|
| + if (mimeType.isNull())
|
| + lowercaseMimeType = DefaultMimeType;
|
| +
|
| + RequestedImageMimeType imageFormat;
|
| + if (lowercaseMimeType == "image/png") {
|
| + imageFormat = RequestedImageMimeTypePng;
|
| + } else if (lowercaseMimeType == "image/jpeg") {
|
| + imageFormat = RequestedImageMimeTypeJpeg;
|
| + } else if (lowercaseMimeType == "image/webp") {
|
| + imageFormat = RequestedImageMimeTypeWebp;
|
| + } else if (lowercaseMimeType == "image/gif") {
|
| + imageFormat = RequestedImageMimeTypeGif;
|
| + } else if (lowercaseMimeType == "image/bmp" || lowercaseMimeType == "image/x-windows-bmp") {
|
| + imageFormat = RequestedImageMimeTypeBmp;
|
| + } else if (lowercaseMimeType == "image/x-icon") {
|
| + imageFormat = RequestedImageMimeTypeIco;
|
| + } else if (lowercaseMimeType == "image/tiff" || lowercaseMimeType == "image/x-tiff") {
|
| + imageFormat = RequestedImageMimeTypeTiff;
|
| + } else {
|
| + imageFormat = RequestedImageMimeTypeUnknown;
|
| + }
|
| +
|
| + if (encodeReason == EncodeReasonToDataURL) {
|
| + DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, toDataURLImageFormatHistogram, new EnumerationHistogram("Canvas.RequestedImageMimeTypes_toDataURL", NumberOfRequestedImageMimeTypes));
|
| + toDataURLImageFormatHistogram.count(imageFormat);
|
| + } else if (encodeReason == EncodeReasonToBlobCallback) {
|
| + DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, toBlobCallbackImageFormatHistogram, new EnumerationHistogram("Canvas.RequestedImageMimeTypes_toBlobCallback", NumberOfRequestedImageMimeTypes));
|
| + 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 +595,7 @@ String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double
|
| if (!isPaintable())
|
| return String("data:,");
|
|
|
| - String encodingMimeType = toEncodingMimeType(mimeType);
|
| + String encodingMimeType = toEncodingMimeType(mimeType, EncodeReasonToDataURL);
|
|
|
| ImageData* imageData = toImageData(sourceBuffer, SnapshotReasonToDataURL);
|
| ScopedDisposal<ImageData> disposer(imageData);
|
| @@ -599,7 +640,7 @@ void HTMLCanvasElement::toBlob(BlobCallback* callback, const String& mimeType, c
|
| }
|
| }
|
|
|
| - String encodingMimeType = toEncodingMimeType(mimeType);
|
| + String encodingMimeType = toEncodingMimeType(mimeType, EncodeReasonToBlobCallback);
|
|
|
| ImageData* imageData = toImageData(BackBuffer, SnapshotReasonToBlob);
|
| // imageData unref its data, which we still keep alive for the async toBlob thread
|
|
|