| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/shapedetection/FaceDetector.h" | 5 #include "modules/shapedetection/FaceDetector.h" |
| 6 | 6 |
| 7 #include "core/dom/DOMException.h" | 7 #include "core/dom/DOMException.h" |
| 8 #include "core/dom/DOMRect.h" | 8 #include "core/dom/DOMRect.h" |
| 9 #include "core/frame/LocalDOMWindow.h" | 9 #include "core/frame/LocalDOMWindow.h" |
| 10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
| 11 #include "core/html/canvas/CanvasImageSource.h" | 11 #include "core/html/canvas/CanvasImageSource.h" |
| 12 #include "modules/shapedetection/DetectedFace.h" |
| 12 #include "public/platform/InterfaceProvider.h" | 13 #include "public/platform/InterfaceProvider.h" |
| 13 | 14 |
| 14 namespace blink { | 15 namespace blink { |
| 15 | 16 |
| 16 FaceDetector* FaceDetector::create(Document& document, | 17 FaceDetector* FaceDetector::create(Document& document, |
| 17 const FaceDetectorOptions& options) { | 18 const FaceDetectorOptions& options) { |
| 18 return new FaceDetector(*document.frame(), options); | 19 return new FaceDetector(*document.frame(), options); |
| 19 } | 20 } |
| 20 | 21 |
| 21 FaceDetector::FaceDetector(LocalFrame& frame, | 22 FaceDetector::FaceDetector(LocalFrame& frame, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 48 wrapPersistent(resolver)))); | 49 wrapPersistent(resolver)))); |
| 49 return promise; | 50 return promise; |
| 50 } | 51 } |
| 51 | 52 |
| 52 void FaceDetector::onDetectFaces( | 53 void FaceDetector::onDetectFaces( |
| 53 ScriptPromiseResolver* resolver, | 54 ScriptPromiseResolver* resolver, |
| 54 mojom::blink::FaceDetectionResultPtr faceDetectionResult) { | 55 mojom::blink::FaceDetectionResultPtr faceDetectionResult) { |
| 55 DCHECK(m_faceServiceRequests.contains(resolver)); | 56 DCHECK(m_faceServiceRequests.contains(resolver)); |
| 56 m_faceServiceRequests.remove(resolver); | 57 m_faceServiceRequests.remove(resolver); |
| 57 | 58 |
| 58 HeapVector<Member<DOMRect>> detectedFaces; | 59 HeapVector<Member<DetectedFace>> detectedFaces; |
| 59 for (const auto& boundingBox : faceDetectionResult->bounding_boxes) { | 60 for (const auto& boundingBox : faceDetectionResult->bounding_boxes) { |
| 60 detectedFaces.append(DOMRect::create(boundingBox->x, boundingBox->y, | 61 detectedFaces.append(DetectedFace::create( |
| 61 boundingBox->width, | 62 DOMRect::create(boundingBox->x, boundingBox->y, boundingBox->width, |
| 62 boundingBox->height)); | 63 boundingBox->height))); |
| 63 } | 64 } |
| 64 | 65 |
| 65 resolver->resolve(detectedFaces); | 66 resolver->resolve(detectedFaces); |
| 66 } | 67 } |
| 67 | 68 |
| 68 void FaceDetector::onFaceServiceConnectionError() { | 69 void FaceDetector::onFaceServiceConnectionError() { |
| 69 for (const auto& request : m_faceServiceRequests) { | 70 for (const auto& request : m_faceServiceRequests) { |
| 70 request->reject(DOMException::create(NotSupportedError, | 71 request->reject(DOMException::create(NotSupportedError, |
| 71 "Face Detection not implemented.")); | 72 "Face Detection not implemented.")); |
| 72 } | 73 } |
| 73 m_faceServiceRequests.clear(); | 74 m_faceServiceRequests.clear(); |
| 74 m_faceService.reset(); | 75 m_faceService.reset(); |
| 75 } | 76 } |
| 76 | 77 |
| 77 DEFINE_TRACE(FaceDetector) { | 78 DEFINE_TRACE(FaceDetector) { |
| 78 ShapeDetector::trace(visitor); | 79 ShapeDetector::trace(visitor); |
| 79 visitor->trace(m_faceServiceRequests); | 80 visitor->trace(m_faceServiceRequests); |
| 80 } | 81 } |
| 81 | 82 |
| 82 } // namespace blink | 83 } // namespace blink |
| OLD | NEW |