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 7ca764f3bd3747d000e47bff2860c2bc569530db..a906c7f9f67c9e10cfd555f9d65879b94e602b8d 100644 |
--- a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
+++ b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp |
@@ -625,7 +625,7 @@ ImageData* HTMLCanvasElement::toImageData(SourceDrawingBuffer sourceBuffer, Snap |
m_context->paintRenderingResultsToCanvas(sourceBuffer); |
imageData = ImageData::create(m_size); |
- if (hasImageBuffer()) { |
+ if (imageData && hasImageBuffer()) { |
sk_sp<SkImage> snapshot = buffer()->newSkImageSnapshot(PreferNoAcceleration, reason); |
if (snapshot) { |
SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8888_SkColorType, kUnpremul_SkAlphaType); |
@@ -637,7 +637,7 @@ ImageData* HTMLCanvasElement::toImageData(SourceDrawingBuffer sourceBuffer, Snap |
imageData = ImageData::create(m_size); |
- if (!m_context) |
+ if (!m_context || !imageData) |
return imageData; |
DCHECK(m_context->is2d()); |
@@ -661,6 +661,9 @@ String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double |
ImageData* imageData = toImageData(sourceBuffer, SnapshotReasonToDataURL); |
+ if (!imageData) // allocation failure |
+ return String("data:,"); |
+ |
return ImageDataBuffer(imageData->size(), imageData->data()->data()).toDataURL(encodingMimeType, quality); |
} |
@@ -745,6 +748,12 @@ void HTMLCanvasElement::toBlob(BlobCallback* callback, const String& mimeType, c |
ImageData* imageData = toImageData(BackBuffer, SnapshotReasonToBlob); |
+ if (!imageData) { |
+ // ImageData allocation faillure |
+ TaskRunnerHelper::get(TaskType::CanvasBlobSerialization, &document())->postTask(BLINK_FROM_HERE, WTF::bind(&BlobCallback::handleEvent, wrapPersistent(callback), nullptr)); |
+ return; |
+ } |
+ |
CanvasAsyncBlobCreator* asyncCreator = CanvasAsyncBlobCreator::create(imageData->data(), encodingMimeType, imageData->size(), callback, startTime, document()); |
bool useIdlePeriodScheduling = (encodingMimeType != "image/webp"); |