Index: Source/core/html/HTMLCanvasElement.cpp |
diff --git a/Source/core/html/HTMLCanvasElement.cpp b/Source/core/html/HTMLCanvasElement.cpp |
index b56dbd2a6b1fec36a8a9a8c2af421e51850300b2..5a52557d6d76a34092f65c5ca34f652833bc934a 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" |
Justin Novosad
2015/08/13 21:03:40
File is in core. I think FileCallback should be a
xlai (Olivia)
2015/08/20 19:46:44
Acknowledged. Great! This sounds a simpler solutio
|
#include "core/frame/LocalFrame.h" |
#include "core/frame/Settings.h" |
#include "core/html/ImageData.h" |
@@ -45,6 +46,7 @@ |
#include "core/paint/DeprecatedPaintLayer.h" |
#include "platform/MIMETypeRegistry.h" |
#include "platform/RuntimeEnabledFeatures.h" |
+#include "platform/ThreadSafeFunctional.h" |
#include "platform/graphics/Canvas2DImageBufferSurface.h" |
#include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" |
#include "platform/graphics/ImageBuffer.h" |
@@ -54,6 +56,7 @@ |
#include "platform/graphics/gpu/AcceleratedImageBufferSurface.h" |
#include "platform/transforms/AffineTransform.h" |
#include "public/platform/Platform.h" |
+#include "public/platform/WebTraceLocation.h" |
#include <math.h> |
#include <v8.h> |
@@ -508,6 +511,11 @@ String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double |
return ImageDataBuffer(imageData->size(), imageData->data()->data()).toDataURL(encodingMimeType, quality); |
} |
+static void invokeFileCallbackWithBlob(FileCallback* callback, File* blob) |
+{ |
+ callback->handleEvent(blob); |
+} |
+ |
String HTMLCanvasElement::toDataURL(const String& mimeType, const ScriptValue& qualityArgument, ExceptionState& exceptionState) const |
{ |
if (!originClean()) { |
@@ -526,6 +534,41 @@ 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."); |
Justin Novosad
2015/08/13 21:03:40
Excellent. But this need to be covered by a test.
xlai (Olivia)
2015/08/20 19:46:44
Acknowledged. One more layout test in my to-do lis
|
+ return; |
+ } |
+ |
+ File* resultBlob; |
Justin Novosad
2015/08/13 21:03:40
Code is less fragile if you initialize to nullptr
|
+ if (!isPaintable()) { |
+ // If the canvas element's bitmap has no pixels |
+ resultBlob = nullptr; |
+ return; |
+ } |
+ |
+ 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()).toDataVector(encodingMimeType, &quality, encodedImage); |
+ resultBlob = File::create(&encodedImage, encodingMimeType); |
+ |
+ Platform::current()->mainThread()->postDelayedTask(FROM_HERE, threadSafeBind(&invokeFileCallbackWithBlob, callback, resultBlob), 1); |
Justin Novosad
2015/08/13 21:03:40
Why delayed?
xlai (Olivia)
2015/08/20 19:46:44
Done. Changed back to postTask. It was my layout t
|
+} |
+ |
SecurityOrigin* HTMLCanvasElement::securityOrigin() const |
{ |
return document().securityOrigin(); |