| 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/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/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( | 27 ScriptPromise TextDetector::doDetect(ScriptPromiseResolver* resolver, |
| 28 ScriptPromiseResolver* resolver, | 28 skia::mojom::blink::BitmapPtr bitmap) { |
| 29 mojo::ScopedSharedBufferHandle sharedBufferHandle, | |
| 30 int imageWidth, | |
| 31 int imageHeight) { | |
| 32 ScriptPromise promise = resolver->promise(); | 29 ScriptPromise promise = resolver->promise(); |
| 33 if (!m_textService) { | 30 if (!m_textService) { |
| 34 resolver->reject(DOMException::create( | 31 resolver->reject(DOMException::create( |
| 35 NotSupportedError, "Text detection service unavailable.")); | 32 NotSupportedError, "Text detection service unavailable.")); |
| 36 return promise; | 33 return promise; |
| 37 } | 34 } |
| 38 m_textServiceRequests.insert(resolver); | 35 m_textServiceRequests.insert(resolver); |
| 39 m_textService->Detect(std::move(sharedBufferHandle), imageWidth, imageHeight, | 36 m_textService->Detect(std::move(bitmap), |
| 40 convertToBaseCallback(WTF::bind( | 37 convertToBaseCallback(WTF::bind( |
| 41 &TextDetector::onDetectText, wrapPersistent(this), | 38 &TextDetector::onDetectText, wrapPersistent(this), |
| 42 wrapPersistent(resolver)))); | 39 wrapPersistent(resolver)))); |
| 43 return promise; | 40 return promise; |
| 44 } | 41 } |
| 45 | 42 |
| 46 void TextDetector::onDetectText( | 43 void TextDetector::onDetectText( |
| 47 ScriptPromiseResolver* resolver, | 44 ScriptPromiseResolver* resolver, |
| 48 Vector<shape_detection::mojom::blink::TextDetectionResultPtr> | 45 Vector<shape_detection::mojom::blink::TextDetectionResultPtr> |
| 49 textDetectionResults) { | 46 textDetectionResults) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 70 m_textServiceRequests.clear(); | 67 m_textServiceRequests.clear(); |
| 71 m_textService.reset(); | 68 m_textService.reset(); |
| 72 } | 69 } |
| 73 | 70 |
| 74 DEFINE_TRACE(TextDetector) { | 71 DEFINE_TRACE(TextDetector) { |
| 75 ShapeDetector::trace(visitor); | 72 ShapeDetector::trace(visitor); |
| 76 visitor->trace(m_textServiceRequests); | 73 visitor->trace(m_textServiceRequests); |
| 77 } | 74 } |
| 78 | 75 |
| 79 } // namespace blink | 76 } // namespace blink |
| OLD | NEW |