| Index: third_party/WebKit/Source/modules/shapedetection/BarcodeDetector.cpp
|
| diff --git a/third_party/WebKit/Source/modules/shapedetection/BarcodeDetector.cpp b/third_party/WebKit/Source/modules/shapedetection/BarcodeDetector.cpp
|
| index 969ff229b2bd7abce4cbc75cc1d2966aa5680880..b76da099e0b33f6c5b3a313b9a1beb3295acd430 100644
|
| --- a/third_party/WebKit/Source/modules/shapedetection/BarcodeDetector.cpp
|
| +++ b/third_party/WebKit/Source/modules/shapedetection/BarcodeDetector.cpp
|
| @@ -5,9 +5,12 @@
|
| #include "modules/shapedetection/BarcodeDetector.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 "modules/shapedetection/DetectedBarcode.h"
|
| +#include "public/platform/InterfaceProvider.h"
|
|
|
| namespace blink {
|
|
|
| @@ -15,17 +18,63 @@ BarcodeDetector* BarcodeDetector::create(Document& document) {
|
| return new BarcodeDetector(*document.frame());
|
| }
|
|
|
| -BarcodeDetector::BarcodeDetector(LocalFrame& frame) : ShapeDetector(frame) {}
|
| +BarcodeDetector::BarcodeDetector(LocalFrame& frame) : ShapeDetector(frame) {
|
| + frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_barcodeService));
|
| + m_barcodeService.set_connection_error_handler(convertToBaseCallback(
|
| + WTF::bind(&BarcodeDetector::onBarcodeServiceConnectionError,
|
| + wrapWeakPersistent(this))));
|
| +}
|
| +
|
| +ScriptPromise BarcodeDetector::doDetect(
|
| + ScriptPromiseResolver* resolver,
|
| + mojo::ScopedSharedBufferHandle sharedBufferHandle,
|
| + int imageWidth,
|
| + int imageHeight) {
|
| + ScriptPromise promise = resolver->promise();
|
| + if (!m_barcodeService) {
|
| + resolver->reject(DOMException::create(
|
| + NotSupportedError, "Barcode detection service unavailable."));
|
| + return promise;
|
| + }
|
| + m_barcodeServiceRequests.add(resolver);
|
| + m_barcodeService->Detect(
|
| + std::move(sharedBufferHandle), imageWidth, imageHeight,
|
| + convertToBaseCallback(WTF::bind(&BarcodeDetector::onDetectBarcodes,
|
| + wrapPersistent(this),
|
| + wrapPersistent(resolver))));
|
| + return promise;
|
| +}
|
| +
|
| +void BarcodeDetector::onDetectBarcodes(
|
| + ScriptPromiseResolver* resolver,
|
| + Vector<mojom::blink::BarcodeDetectionResultPtr> barcodeDetectionResults) {
|
| + DCHECK(m_barcodeServiceRequests.contains(resolver));
|
| + m_barcodeServiceRequests.remove(resolver);
|
| +
|
| + HeapVector<Member<DetectedBarcode>> detectedBarcodes;
|
| + for (const auto& barcode : barcodeDetectionResults) {
|
| + detectedBarcodes.append(DetectedBarcode::create(
|
| + barcode->raw_value,
|
| + DOMRect::create(barcode->bounding_box->x, barcode->bounding_box->y,
|
| + barcode->bounding_box->width,
|
| + barcode->bounding_box->height)));
|
| + }
|
| +
|
| + resolver->resolve(detectedBarcodes);
|
| +}
|
|
|
| -ScriptPromise BarcodeDetector::detect(
|
| - ScriptState* scriptState,
|
| - const CanvasImageSourceUnion& imageSource) {
|
| - return detectShapes(scriptState, ShapeDetector::DetectorType::Barcode,
|
| - imageSource);
|
| +void BarcodeDetector::onBarcodeServiceConnectionError() {
|
| + for (const auto& request : m_barcodeServiceRequests) {
|
| + request->reject(DOMException::create(NotSupportedError,
|
| + "Barcode Detection not implemented."));
|
| + }
|
| + m_barcodeServiceRequests.clear();
|
| + m_barcodeService.reset();
|
| }
|
|
|
| DEFINE_TRACE(BarcodeDetector) {
|
| ShapeDetector::trace(visitor);
|
| + visitor->trace(m_barcodeServiceRequests);
|
| }
|
|
|
| } // namespace blink
|
|
|