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

Unified Diff: third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp

Issue 2550413005: ShapeDetection: use ImageBitmapSource as input and support ImageData (Closed)
Patch Set: xianglu@ comments and added forgotten LayoutTest detection-ImageData.html Created 4 years 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
« no previous file with comments | « third_party/WebKit/Source/modules/shapedetection/ShapeDetector.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp
diff --git a/third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp b/third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp
index a574933828cdd82b3196d42c231462206a67bff0..241ac7cd5075f7965115e0e04510165fc75d4512 100644
--- a/third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp
+++ b/third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp
@@ -11,7 +11,7 @@
#include "core/frame/LocalFrame.h"
#include "core/html/HTMLImageElement.h"
#include "core/html/HTMLVideoElement.h"
-#include "core/html/canvas/CanvasImageSource.h"
+#include "core/html/ImageData.h"
#include "core/loader/resource/ImageResourceContent.h"
#include "platform/graphics/Image.h"
#include "third_party/skia/include/core/SkImage.h"
@@ -53,10 +53,14 @@ ShapeDetector::ShapeDetector(LocalFrame& frame) {
}
ScriptPromise ShapeDetector::detect(ScriptState* scriptState,
- const CanvasImageSourceUnion& imageSource) {
+ const ImageBitmapSourceUnion& imageSource) {
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
+ // ImageDatas cannot be tainted by definition.
+ if (imageSource.isImageData())
+ return detectShapesOnImageData(resolver, imageSource.getAsImageData());
+
CanvasImageSource* canvasImageSource;
if (imageSource.isHTMLImageElement()) {
canvasImageSource = imageSource.getAsHTMLImageElement();
@@ -141,11 +145,29 @@ ScriptPromise ShapeDetector::detect(ScriptState* scriptState,
image->height());
}
+ScriptPromise ShapeDetector::detectShapesOnImageData(
+ ScriptPromiseResolver* resolver,
+ ImageData* imageData) {
+ ScriptPromise promise = resolver->promise();
+
+ uint8_t* const data = imageData->data()->data();
+ WTF::CheckedNumeric<int> allocationSize = imageData->size().area() * 4;
+
+ mojo::ScopedSharedBufferHandle sharedBufferHandle =
+ getSharedBufferOnData(resolver, data, allocationSize.ValueOrDefault(0));
+ if (!sharedBufferHandle->is_valid())
+ return promise;
+
+ return doDetect(resolver, std::move(sharedBufferHandle), imageData->width(),
+ imageData->height());
+}
+
ScriptPromise ShapeDetector::detectShapesOnImageElement(
ScriptPromiseResolver* resolver,
const HTMLImageElement* img) {
ScriptPromise promise = resolver->promise();
+ // TODO(mcasas): reconsider this resolve(), https://crbug.com/674306.
if (img->bitmapSourceSize().isZero()) {
resolver->resolve(HeapVector<Member<DOMRect>>());
return promise;
« no previous file with comments | « third_party/WebKit/Source/modules/shapedetection/ShapeDetector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698