| 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/BarcodeDetector.h" | 5 #include "modules/shapedetection/BarcodeDetector.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/html/canvas/CanvasImageSource.h" | 9 #include "core/html/canvas/CanvasImageSource.h" |
| 10 #include "modules/imagecapture/Point2D.h" | 10 #include "modules/imagecapture/Point2D.h" |
| 11 #include "modules/shapedetection/DetectedBarcode.h" | 11 #include "modules/shapedetection/DetectedBarcode.h" |
| 12 #include "public/platform/InterfaceProvider.h" | 12 #include "public/platform/InterfaceProvider.h" |
| 13 #include "public/platform/Platform.h" | 13 #include "public/platform/Platform.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 BarcodeDetector* BarcodeDetector::create() { | 17 BarcodeDetector* BarcodeDetector::create() { |
| 18 return new BarcodeDetector(); | 18 return new BarcodeDetector(); |
| 19 } | 19 } |
| 20 | 20 |
| 21 BarcodeDetector::BarcodeDetector() : ShapeDetector() { | 21 BarcodeDetector::BarcodeDetector() : ShapeDetector() { |
| 22 Platform::current()->interfaceProvider()->getInterface( | 22 Platform::current()->interfaceProvider()->getInterface( |
| 23 mojo::MakeRequest(&m_barcodeService)); | 23 mojo::MakeRequest(&m_barcodeService)); |
| 24 m_barcodeService.set_connection_error_handler(convertToBaseCallback( | 24 m_barcodeService.set_connection_error_handler(convertToBaseCallback( |
| 25 WTF::bind(&BarcodeDetector::onBarcodeServiceConnectionError, | 25 WTF::bind(&BarcodeDetector::onBarcodeServiceConnectionError, |
| 26 wrapWeakPersistent(this)))); | 26 wrapWeakPersistent(this)))); |
| 27 } | 27 } |
| 28 | 28 |
| 29 ScriptPromise BarcodeDetector::doDetect( | 29 ScriptPromise BarcodeDetector::doDetect(ScriptPromiseResolver* resolver, |
| 30 ScriptPromiseResolver* resolver, | 30 skia::mojom::blink::BitmapPtr bitmap) { |
| 31 mojo::ScopedSharedBufferHandle sharedBufferHandle, | |
| 32 int imageWidth, | |
| 33 int imageHeight) { | |
| 34 ScriptPromise promise = resolver->promise(); | 31 ScriptPromise promise = resolver->promise(); |
| 35 if (!m_barcodeService) { | 32 if (!m_barcodeService) { |
| 36 resolver->reject(DOMException::create( | 33 resolver->reject(DOMException::create( |
| 37 NotSupportedError, "Barcode detection service unavailable.")); | 34 NotSupportedError, "Barcode detection service unavailable.")); |
| 38 return promise; | 35 return promise; |
| 39 } | 36 } |
| 40 m_barcodeServiceRequests.insert(resolver); | 37 m_barcodeServiceRequests.insert(resolver); |
| 41 m_barcodeService->Detect( | 38 m_barcodeService->Detect( |
| 42 std::move(sharedBufferHandle), imageWidth, imageHeight, | 39 std::move(bitmap), convertToBaseCallback(WTF::bind( |
| 43 convertToBaseCallback(WTF::bind(&BarcodeDetector::onDetectBarcodes, | 40 &BarcodeDetector::onDetectBarcodes, |
| 44 wrapPersistent(this), | 41 wrapPersistent(this), wrapPersistent(resolver)))); |
| 45 wrapPersistent(resolver)))); | |
| 46 return promise; | 42 return promise; |
| 47 } | 43 } |
| 48 | 44 |
| 49 void BarcodeDetector::onDetectBarcodes( | 45 void BarcodeDetector::onDetectBarcodes( |
| 50 ScriptPromiseResolver* resolver, | 46 ScriptPromiseResolver* resolver, |
| 51 Vector<shape_detection::mojom::blink::BarcodeDetectionResultPtr> | 47 Vector<shape_detection::mojom::blink::BarcodeDetectionResultPtr> |
| 52 barcodeDetectionResults) { | 48 barcodeDetectionResults) { |
| 53 DCHECK(m_barcodeServiceRequests.contains(resolver)); | 49 DCHECK(m_barcodeServiceRequests.contains(resolver)); |
| 54 m_barcodeServiceRequests.erase(resolver); | 50 m_barcodeServiceRequests.erase(resolver); |
| 55 | 51 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 81 m_barcodeServiceRequests.clear(); | 77 m_barcodeServiceRequests.clear(); |
| 82 m_barcodeService.reset(); | 78 m_barcodeService.reset(); |
| 83 } | 79 } |
| 84 | 80 |
| 85 DEFINE_TRACE(BarcodeDetector) { | 81 DEFINE_TRACE(BarcodeDetector) { |
| 86 ShapeDetector::trace(visitor); | 82 ShapeDetector::trace(visitor); |
| 87 visitor->trace(m_barcodeServiceRequests); | 83 visitor->trace(m_barcodeServiceRequests); |
| 88 } | 84 } |
| 89 | 85 |
| 90 } // namespace blink | 86 } // namespace blink |
| OLD | NEW |