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

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

Issue 2441953002: Shape Detection: Add two layout tests for face detection (Closed)
Patch Set: Use promise_test() instead of async_test() Created 4 years, 2 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: third_party/WebKit/Source/modules/shapedetection/FaceDetector.cpp
diff --git a/third_party/WebKit/Source/modules/shapedetection/FaceDetector.cpp b/third_party/WebKit/Source/modules/shapedetection/FaceDetector.cpp
index bb969d71c63d44b04e7969fcfa5c55999071a146..e1d427dfa32ba5cee1f10d19577361b97ef9fbc9 100644
--- a/third_party/WebKit/Source/modules/shapedetection/FaceDetector.cpp
+++ b/third_party/WebKit/Source/modules/shapedetection/FaceDetector.cpp
@@ -21,16 +21,20 @@ namespace blink {
namespace {
mojo::ScopedSharedBufferHandle getSharedBufferHandle(
- const HTMLImageElement* img) {
+ const HTMLImageElement* img,
+ ScriptPromiseResolver* resolver) {
ImageResource* const imageResource = img->cachedImage();
if (!imageResource) {
- DLOG(ERROR) << "Failed to convert HTMLImageElement to ImageSource.";
+ resolver->reject(DOMException::create(
+ InvalidStateError,
+ "Failed to acquire ImageResource from HTMLImageElement."));
return mojo::ScopedSharedBufferHandle();
}
Image* const blinkImage = imageResource->getImage();
mcasas 2016/10/21 23:43:16 I'm not 100% sure, but I think before doing this w
xianglu 2016/10/22 02:19:09 I agree. However, the testing image ("imported/wpt
if (!blinkImage) {
- DLOG(ERROR) << "Failed to convert ImageSource to blink::Image.";
+ resolver->reject(DOMException::create(
+ InvalidStateError, "Failed to get blink::Image from ImageResource."));
return mojo::ScopedSharedBufferHandle();
}
@@ -39,7 +43,9 @@ mojo::ScopedSharedBufferHandle getSharedBufferHandle(
DCHECK_EQ(img->naturalHeight(), image->height());
if (!image) {
- DLOG(ERROR) << "Failed to convert blink::Image to sk_sp<SkImage>.";
+ resolver->reject(DOMException::create(
+ InvalidStateError,
+ "Failed to convert blink::Image to sk_sp<SkImage>."));
return mojo::ScopedSharedBufferHandle();
}
@@ -51,9 +57,16 @@ mojo::ScopedSharedBufferHandle getSharedBufferHandle(
mojo::ScopedSharedBufferHandle sharedBufferHandle =
mojo::SharedBufferHandle::Create(allocationSize);
if (!sharedBufferHandle.is_valid()) {
- // TODO(xianglu): Do something when the image is too large.
- DLOG(ERROR) << "Failed to create a sharedBufferHandle. allocationSize = "
- << allocationSize << "bytes. limit = 16777216";
+ DLOG(ERROR) << "AllocationSize = " << allocationSize
+ << "bytes. limit = 16777216, referred from "
+ "https://cs.chromium.org/chromium/src/"
+ "mojo/edk/system/broker_host.cc?l=24";
+ // TODO(xianglu): For now we reject the promise if the image is too large.
+ // But consider resizing the image to remove restriction on the user side.
+ // Also, add layouttest for this case later.
+ resolver->reject(DOMException::create(
+ InvalidStateError,
+ "HTMLImageElement is too large to fit in mojo shared buffer."));
return mojo::ScopedSharedBufferHandle();
}
@@ -62,7 +75,9 @@ mojo::ScopedSharedBufferHandle getSharedBufferHandle(
const SkPixmap pixmap(skiaInfo, mappedBuffer.get(), skiaInfo.minRowBytes());
if (!image->readPixels(pixmap, 0, 0)) {
- DLOG(ERROR) << "Failed to read pixels from sk_sp<SkImage>.";
+ resolver->reject(DOMException::create(
+ InvalidStateError,
+ "Image is broken. Failed to read pixels from sk_sp<SkImage>."));
return mojo::ScopedSharedBufferHandle();
}
@@ -86,25 +101,28 @@ ScriptPromise FaceDetector::detect(ScriptState* scriptState,
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
- if (!m_service) {
+ // TODO(xianglu): Add test cases for cross-origin-images.
+ if (img->wouldTaintOrigin(
+ scriptState->getExecutionContext()->getSecurityOrigin())) {
resolver->reject(DOMException::create(
- NotFoundError, "Face detection service unavailable."));
+ SecurityError, "Image source from a different origin."));
return promise;
}
- if (!img) {
- resolver->reject(DOMException::create(
- SyntaxError, "The provided HTMLImageElement is empty."));
+ if (img->bitmapSourceSize().isZero()) {
+ resolver->reject(
+ DOMException::create(InvalidStateError, "HTMLImageElement is empty."));
return promise;
}
- // TODO(xianglu): Add security check when the spec is ready.
- // https://crbug.com/646083
mojo::ScopedSharedBufferHandle sharedBufferHandle =
- getSharedBufferHandle(img);
- if (!sharedBufferHandle->is_valid()) {
+ getSharedBufferHandle(img, resolver);
+ if (!sharedBufferHandle->is_valid())
+ return promise;
+
+ if (!m_service) {
resolver->reject(DOMException::create(
- SyntaxError, "Request for sharedBufferHandle failed."));
+ NotSupportedError, "Face detection service unavailable."));
return promise;
}

Powered by Google App Engine
This is Rietveld 408576698