Chromium Code Reviews| Index: Source/core/html/HTMLCanvasElement.cpp |
| diff --git a/Source/core/html/HTMLCanvasElement.cpp b/Source/core/html/HTMLCanvasElement.cpp |
| index 50e6afbb428e0bea70f3aace7a0a07cf64e98161..21f45a9b8164e68aefc0c88282349410d1129b11 100644 |
| --- a/Source/core/html/HTMLCanvasElement.cpp |
| +++ b/Source/core/html/HTMLCanvasElement.cpp |
| @@ -34,6 +34,7 @@ |
| #include "core/HTMLNames.h" |
| #include "core/dom/Document.h" |
| #include "core/dom/ExceptionCode.h" |
| +#include "core/fileapi/File.h" |
| #include "core/frame/LocalFrame.h" |
| #include "core/frame/Settings.h" |
| #include "core/html/ImageData.h" |
| @@ -54,6 +55,8 @@ |
| #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h" |
| #include "platform/transforms/AffineTransform.h" |
| #include "public/platform/Platform.h" |
| +#include "public/platform/WebTraceLocation.h" |
| +#include "wtf/Functional.h" |
| #include <math.h> |
| #include <v8.h> |
| @@ -538,6 +541,40 @@ String HTMLCanvasElement::toDataURL(const String& mimeType, const ScriptValue& q |
| return toDataURLInternal(mimeType, qualityPtr, BackBuffer); |
| } |
| +void HTMLCanvasElement::toBlob(FileCallback* callback, const String& mimeType, const ScriptValue& qualityArgument, ExceptionState& exceptionState) const |
| +{ |
| + if (!originClean()) { |
| + exceptionState.throwSecurityError("Tainted canvases may not be exported."); |
| + return; |
| + } |
| + |
| + File* resultBlob = nullptr; |
| + if (!isPaintable()) { |
| + // If the canvas element's bitmap has no pixels |
| + return; |
|
Noel Gordon
2015/08/28 08:53:47
I don't think the spec allows us to just return he
xlai (Olivia)
2015/08/28 19:54:19
Acknowledged. The spec says "If the canvas element
|
| + } |
| + |
| + double quality; |
| + if (!qualityArgument.isEmpty()) { |
| + v8::Local<v8::Value> v8Value = qualityArgument.v8Value(); |
| + if (v8Value->IsNumber()) { |
| + quality = v8Value.As<v8::Number>()->Value(); |
| + } |
| + } |
| + |
| + String encodingMimeType = toEncodingMimeType(mimeType); |
| + |
| + ImageData* imageData = toImageData(BackBuffer); |
| + ScopedDisposal<ImageData> disposer(imageData); |
| + |
| + // Perform image encoding |
| + Vector<char> encodedImage; |
| + ImageDataBuffer(imageData->size(), imageData->data()->data()).encodeImage(encodingMimeType, &quality, &encodedImage); |
|
Noel Gordon
2015/08/28 08:53:47
encodeImage is bool returning (success/failure).
xlai (Olivia)
2015/08/28 19:54:19
Acknowledged. I will explain in the overall messag
|
| + resultBlob = File::create(encodedImage.data(), encodedImage.size(), encodingMimeType); |
| + |
| + Platform::current()->mainThread()->postTask(FROM_HERE, bind(&FileCallback::handleEvent, callback, resultBlob)); |
| +} |
| + |
| SecurityOrigin* HTMLCanvasElement::securityOrigin() const |
| { |
| return document().securityOrigin(); |