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

Side by Side Diff: third_party/WebKit/Source/modules/shapedetection/BarcodeDetector.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 unified diff | Download patch
OLDNEW
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/frame/LocalDOMWindow.h" 9 #include "core/frame/LocalDOMWindow.h"
9 #include "core/frame/LocalFrame.h" 10 #include "core/frame/LocalFrame.h"
10 #include "core/html/canvas/CanvasImageSource.h" 11 #include "core/html/canvas/CanvasImageSource.h"
12 #include "modules/shapedetection/DetectedBarcode.h"
13 #include "public/platform/InterfaceProvider.h"
11 14
12 namespace blink { 15 namespace blink {
13 16
14 BarcodeDetector* BarcodeDetector::create(Document& document) { 17 BarcodeDetector* BarcodeDetector::create(Document& document) {
15 return new BarcodeDetector(*document.frame()); 18 return new BarcodeDetector(*document.frame());
16 } 19 }
17 20
18 BarcodeDetector::BarcodeDetector(LocalFrame& frame) : ShapeDetector(frame) {} 21 BarcodeDetector::BarcodeDetector(LocalFrame& frame) : ShapeDetector(frame) {
22 frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_barcodeService));
23 m_barcodeService.set_connection_error_handler(convertToBaseCallback(
24 WTF::bind(&BarcodeDetector::onBarcodeServiceConnectionError,
25 wrapWeakPersistent(this))));
26 }
19 27
20 ScriptPromise BarcodeDetector::detect( 28 ScriptPromise BarcodeDetector::doDetect(
21 ScriptState* scriptState, 29 ScriptPromiseResolver* resolver,
22 const CanvasImageSourceUnion& imageSource) { 30 mojo::ScopedSharedBufferHandle sharedBufferHandle,
23 return detectShapes(scriptState, ShapeDetector::DetectorType::Barcode, 31 int imageWidth,
24 imageSource); 32 int imageHeight) {
33 ScriptPromise promise = resolver->promise();
34 if (!m_barcodeService) {
35 resolver->reject(DOMException::create(
36 NotSupportedError, "Barcode detection service unavailable."));
37 return promise;
38 }
39 m_barcodeServiceRequests.add(resolver);
40 m_barcodeService->Detect(
41 std::move(sharedBufferHandle), imageWidth, imageHeight,
42 convertToBaseCallback(WTF::bind(&BarcodeDetector::onDetectBarcodes,
43 wrapPersistent(this),
44 wrapPersistent(resolver))));
45 return promise;
46 }
47
48 void BarcodeDetector::onDetectBarcodes(
49 ScriptPromiseResolver* resolver,
50 Vector<mojom::blink::BarcodeDetectionResultPtr> barcodeDetectionResults) {
51 DCHECK(m_barcodeServiceRequests.contains(resolver));
52 m_barcodeServiceRequests.remove(resolver);
53
54 HeapVector<Member<DetectedBarcode>> detectedBarcodes;
55 for (const auto& barcode : barcodeDetectionResults) {
56 detectedBarcodes.append(DetectedBarcode::create(
57 barcode->raw_value,
58 DOMRect::create(barcode->bounding_box->x, barcode->bounding_box->y,
59 barcode->bounding_box->width,
60 barcode->bounding_box->height)));
61 }
62
63 resolver->resolve(detectedBarcodes);
64 }
65
66 void BarcodeDetector::onBarcodeServiceConnectionError() {
67 for (const auto& request : m_barcodeServiceRequests) {
68 request->reject(DOMException::create(NotSupportedError,
69 "Barcode Detection not implemented."));
70 }
71 m_barcodeServiceRequests.clear();
72 m_barcodeService.reset();
25 } 73 }
26 74
27 DEFINE_TRACE(BarcodeDetector) { 75 DEFINE_TRACE(BarcodeDetector) {
28 ShapeDetector::trace(visitor); 76 ShapeDetector::trace(visitor);
77 visitor->trace(m_barcodeServiceRequests);
29 } 78 }
30 79
31 } // namespace blink 80 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698