1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SPELLCHECKER_SPELLCHECKER_SESSION_BRIDGE_ANDROID_H_
6 #define CHROME_BROWSER_SPELLCHECKER_SPELLCHECKER_SESSION_BRIDGE_ANDROID_H_
10 #include "base/android/scoped_java_ref.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string16.h"
14 // A class used to interface between the Java class of the same name and the
15 // android message filter. This class receives text to be spellchecked
16 // from the message filter, sends that text to the Java side via JNI to be
17 // spellchecked, and then sends those results to the renderer.
18 class SpellCheckerSessionBridge
{
20 explicit SpellCheckerSessionBridge(int render_process_id
);
21 ~SpellCheckerSessionBridge();
22 static bool RegisterJNI(JNIEnv
* env
);
24 // Receives text to be checked from the message filter and sends it to Java
25 // to be spellchecked.
26 void RequestTextCheck(int route_id
,
28 const base::string16
& text
);
30 // Receives information from Java side about the typos in a given string
31 // of text, processes these and sends them to the renderer.
32 void ProcessSpellCheckResults(JNIEnv
* env
,
34 jintArray offset_array
,
35 jintArray length_array
);
37 // Sets the handle to the Java SpellCheckerSessionBridge object to null,
38 // marking the Java object for garbage collection.
39 void DisconnectSession();
42 struct SpellingRequest
{
43 SpellingRequest(int route_id
, int identifier
, const base::string16
& text
);
51 int render_process_id_
;
53 scoped_ptr
<SpellingRequest
> active_request_
;
54 scoped_ptr
<SpellingRequest
> pending_request_
;
56 base::android::ScopedJavaGlobalRef
<jobject
> java_object_
;
57 bool java_object_initialization_failed_
;
59 DISALLOW_COPY_AND_ASSIGN(SpellCheckerSessionBridge
);
62 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECKER_SESSION_BRIDGE_ANDROID_H_