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

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

Issue 2557513003: ShapeDetection: Eliminate DetectorType enum in ShapeDetector.cpp (Closed)
Patch Set: Move tainting logic into detect() 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
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 4a6c8572c9a4d42c17798510ef0efd5cd98cc493..fd0952b230ad67b9c46ea1dbb3e446b3c56507f9 100644
--- a/third_party/WebKit/Source/modules/shapedetection/FaceDetector.cpp
+++ b/third_party/WebKit/Source/modules/shapedetection/FaceDetector.cpp
@@ -5,9 +5,11 @@
#include "modules/shapedetection/FaceDetector.h"
#include "core/dom/DOMException.h"
+#include "core/dom/DOMRect.h"
#include "core/frame/LocalDOMWindow.h"
#include "core/frame/LocalFrame.h"
#include "core/html/canvas/CanvasImageSource.h"
+#include "public/platform/InterfaceProvider.h"
namespace blink {
@@ -18,16 +20,63 @@ FaceDetector* FaceDetector::create(Document& document,
FaceDetector::FaceDetector(LocalFrame& frame,
const FaceDetectorOptions& options)
- : ShapeDetector(frame, options) {}
+ : ShapeDetector(frame),
+ m_faceDetectorOptions(mojom::blink::FaceDetectorOptions::New()) {
+ frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_faceService));
+ m_faceService.set_connection_error_handler(convertToBaseCallback(WTF::bind(
+ &FaceDetector::onFaceServiceConnectionError, wrapWeakPersistent(this))));
+ m_faceDetectorOptions->max_detected_faces = options.maxDetectedFaces();
+ m_faceDetectorOptions->fast_mode = options.fastMode();
+}
+
+ScriptPromise FaceDetector::doDetect(
+ ScriptPromiseResolver* resolver,
+ mojo::ScopedSharedBufferHandle sharedBufferHandle,
+ int imageWidth,
+ int imageHeight) {
+ ScriptPromise promise = resolver->promise();
+ if (!m_faceService) {
+ resolver->reject(DOMException::create(
+ NotSupportedError, "Face detection service unavailable."));
+ return promise;
+ }
+ m_faceServiceRequests.add(resolver);
+ m_faceService->Detect(std::move(sharedBufferHandle), imageWidth, imageHeight,
+ m_faceDetectorOptions.Clone(),
+ convertToBaseCallback(WTF::bind(
+ &FaceDetector::onDetectFaces, wrapPersistent(this),
+ wrapPersistent(resolver))));
+ return promise;
+}
+
+void FaceDetector::onDetectFaces(
+ ScriptPromiseResolver* resolver,
+ mojom::blink::FaceDetectionResultPtr faceDetectionResult) {
+ DCHECK(m_faceServiceRequests.contains(resolver));
+ m_faceServiceRequests.remove(resolver);
+
+ HeapVector<Member<DOMRect>> detectedFaces;
+ for (const auto& boundingBox : faceDetectionResult->bounding_boxes) {
+ detectedFaces.append(DOMRect::create(boundingBox->x, boundingBox->y,
+ boundingBox->width,
+ boundingBox->height));
+ }
+
+ resolver->resolve(detectedFaces);
+}
-ScriptPromise FaceDetector::detect(ScriptState* scriptState,
- const CanvasImageSourceUnion& imageSource) {
- return detectShapes(scriptState, ShapeDetector::DetectorType::Face,
- imageSource);
+void FaceDetector::onFaceServiceConnectionError() {
+ for (const auto& request : m_faceServiceRequests) {
+ request->reject(DOMException::create(NotSupportedError,
+ "Face Detection not implemented."));
+ }
+ m_faceServiceRequests.clear();
+ m_faceService.reset();
}
DEFINE_TRACE(FaceDetector) {
ShapeDetector::trace(visitor);
+ visitor->trace(m_faceServiceRequests);
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698