Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(714)

Unified Diff: Source/core/html/HTMLCanvasElement.cpp

Issue 1257253004: [HTMLCanvasElement.toBlob] Default callback version without scheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: A small change from thread safe bind to common bind based on Kinuko's review Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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();

Powered by Google App Engine
This is Rietveld 408576698