| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/TextDetector.h" | 5 #include "modules/shapedetection/TextDetector.h" |
| 6 | 6 |
| 7 #include "core/dom/DOMException.h" | 7 #include "core/dom/DOMException.h" |
| 8 #include "core/geometry/DOMRect.h" | 8 #include "core/geometry/DOMRect.h" |
| 9 #include "core/html/canvas/CanvasImageSource.h" | 9 #include "core/html/canvas/CanvasImageSource.h" |
| 10 #include "modules/shapedetection/DetectedText.h" | 10 #include "modules/shapedetection/DetectedText.h" |
| 11 #include "public/platform/InterfaceProvider.h" | 11 #include "public/platform/InterfaceProvider.h" |
| 12 #include "public/platform/Platform.h" | 12 #include "public/platform/Platform.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 TextDetector* TextDetector::create() { | 16 TextDetector* TextDetector::create() { |
| 17 return new TextDetector(); | 17 return new TextDetector(); |
| 18 } | 18 } |
| 19 | 19 |
| 20 TextDetector::TextDetector() : ShapeDetector() { | 20 TextDetector::TextDetector() : ShapeDetector() { |
| 21 Platform::current()->interfaceProvider()->getInterface( | 21 Platform::current()->interfaceProvider()->getInterface( |
| 22 mojo::MakeRequest(&m_textService)); | 22 mojo::MakeRequest(&m_textService)); |
| 23 m_textService.set_connection_error_handler(convertToBaseCallback(WTF::bind( | 23 m_textService.set_connection_error_handler(convertToBaseCallback(WTF::bind( |
| 24 &TextDetector::onTextServiceConnectionError, wrapWeakPersistent(this)))); | 24 &TextDetector::onTextServiceConnectionError, wrapWeakPersistent(this)))); |
| 25 } | 25 } |
| 26 | 26 |
| 27 ScriptPromise TextDetector::doDetect(ScriptPromiseResolver* resolver, | 27 ScriptPromise TextDetector::doDetect( |
| 28 skia::mojom::blink::BitmapPtr bitmap) { | 28 ScriptPromiseResolver* resolver, |
| 29 mojo::ScopedSharedBufferHandle sharedBufferHandle, |
| 30 int imageWidth, |
| 31 int imageHeight) { |
| 29 ScriptPromise promise = resolver->promise(); | 32 ScriptPromise promise = resolver->promise(); |
| 30 if (!m_textService) { | 33 if (!m_textService) { |
| 31 resolver->reject(DOMException::create( | 34 resolver->reject(DOMException::create( |
| 32 NotSupportedError, "Text detection service unavailable.")); | 35 NotSupportedError, "Text detection service unavailable.")); |
| 33 return promise; | 36 return promise; |
| 34 } | 37 } |
| 35 m_textServiceRequests.insert(resolver); | 38 m_textServiceRequests.insert(resolver); |
| 36 m_textService->Detect(std::move(bitmap), | 39 m_textService->Detect(std::move(sharedBufferHandle), imageWidth, imageHeight, |
| 37 convertToBaseCallback(WTF::bind( | 40 convertToBaseCallback(WTF::bind( |
| 38 &TextDetector::onDetectText, wrapPersistent(this), | 41 &TextDetector::onDetectText, wrapPersistent(this), |
| 39 wrapPersistent(resolver)))); | 42 wrapPersistent(resolver)))); |
| 40 return promise; | 43 return promise; |
| 41 } | 44 } |
| 42 | 45 |
| 43 void TextDetector::onDetectText( | 46 void TextDetector::onDetectText( |
| 44 ScriptPromiseResolver* resolver, | 47 ScriptPromiseResolver* resolver, |
| 45 Vector<shape_detection::mojom::blink::TextDetectionResultPtr> | 48 Vector<shape_detection::mojom::blink::TextDetectionResultPtr> |
| 46 textDetectionResults) { | 49 textDetectionResults) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 67 m_textServiceRequests.clear(); | 70 m_textServiceRequests.clear(); |
| 68 m_textService.reset(); | 71 m_textService.reset(); |
| 69 } | 72 } |
| 70 | 73 |
| 71 DEFINE_TRACE(TextDetector) { | 74 DEFINE_TRACE(TextDetector) { |
| 72 ShapeDetector::trace(visitor); | 75 ShapeDetector::trace(visitor); |
| 73 visitor->trace(m_textServiceRequests); | 76 visitor->trace(m_textServiceRequests); |
| 74 } | 77 } |
| 75 | 78 |
| 76 } // namespace blink | 79 } // namespace blink |
| OLD | NEW |