Commit 6058f825 authored by Minoru Chikamune's avatar Minoru Chikamune Committed by Commit Bot

Migrate TextDetector to use GC mojo wrappers.

No behavior change. This CL reduces potential risks of use-after-free bugs.

Bug: 1049056
Change-Id: I5e86464399de6553de95300992a7582ecf63eaf5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2132076Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Minoru Chikamune <chikamune@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756081}
parent c6becf74
...@@ -22,7 +22,7 @@ TextDetector* TextDetector::Create(ExecutionContext* context) { ...@@ -22,7 +22,7 @@ TextDetector* TextDetector::Create(ExecutionContext* context) {
return MakeGarbageCollected<TextDetector>(context); return MakeGarbageCollected<TextDetector>(context);
} }
TextDetector::TextDetector(ExecutionContext* context) : ShapeDetector() { TextDetector::TextDetector(ExecutionContext* context) : text_service_(context) {
// See https://bit.ly/2S0zRAS for task types. // See https://bit.ly/2S0zRAS for task types.
auto task_runner = context->GetTaskRunner(TaskType::kMiscPlatformAPI); auto task_runner = context->GetTaskRunner(TaskType::kMiscPlatformAPI);
context->GetBrowserInterfaceBroker().GetInterface( context->GetBrowserInterfaceBroker().GetInterface(
...@@ -35,7 +35,7 @@ TextDetector::TextDetector(ExecutionContext* context) : ShapeDetector() { ...@@ -35,7 +35,7 @@ TextDetector::TextDetector(ExecutionContext* context) : ShapeDetector() {
ScriptPromise TextDetector::DoDetect(ScriptPromiseResolver* resolver, ScriptPromise TextDetector::DoDetect(ScriptPromiseResolver* resolver,
SkBitmap bitmap) { SkBitmap bitmap) {
ScriptPromise promise = resolver->Promise(); ScriptPromise promise = resolver->Promise();
if (!text_service_) { if (!text_service_.is_bound()) {
resolver->Reject(MakeGarbageCollected<DOMException>( resolver->Reject(MakeGarbageCollected<DOMException>(
DOMExceptionCode::kNotSupportedError, DOMExceptionCode::kNotSupportedError,
"Text detection service unavailable.")); "Text detection service unavailable."));
...@@ -90,6 +90,7 @@ void TextDetector::OnTextServiceConnectionError() { ...@@ -90,6 +90,7 @@ void TextDetector::OnTextServiceConnectionError() {
void TextDetector::Trace(Visitor* visitor) { void TextDetector::Trace(Visitor* visitor) {
ShapeDetector::Trace(visitor); ShapeDetector::Trace(visitor);
visitor->Trace(text_service_);
visitor->Trace(text_service_requests_); visitor->Trace(text_service_requests_);
} }
......
...@@ -5,13 +5,14 @@ ...@@ -5,13 +5,14 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_SHAPEDETECTION_TEXT_DETECTOR_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_SHAPEDETECTION_TEXT_DETECTOR_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_SHAPEDETECTION_TEXT_DETECTOR_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_SHAPEDETECTION_TEXT_DETECTOR_H_
#include "mojo/public/cpp/bindings/remote.h"
#include "services/shape_detection/public/mojom/textdetection.mojom-blink.h" #include "services/shape_detection/public/mojom/textdetection.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d.h" #include "third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d.h"
#include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/modules/shapedetection/shape_detector.h" #include "third_party/blink/renderer/modules/shapedetection/shape_detector.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_remote.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_wrapper_mode.h"
namespace blink { namespace blink {
...@@ -36,7 +37,9 @@ class MODULES_EXPORT TextDetector final : public ShapeDetector { ...@@ -36,7 +37,9 @@ class MODULES_EXPORT TextDetector final : public ShapeDetector {
Vector<shape_detection::mojom::blink::TextDetectionResultPtr>); Vector<shape_detection::mojom::blink::TextDetectionResultPtr>);
void OnTextServiceConnectionError(); void OnTextServiceConnectionError();
mojo::Remote<shape_detection::mojom::blink::TextDetection> text_service_; HeapMojoRemote<shape_detection::mojom::blink::TextDetection,
HeapMojoWrapperMode::kWithoutContextObserver>
text_service_;
HeapHashSet<Member<ScriptPromiseResolver>> text_service_requests_; HeapHashSet<Member<ScriptPromiseResolver>> text_service_requests_;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment