OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_SPELLCHECKER_SPELLCHECKER_SESSION_BRIDGE_ANDROID_H_ | |
6 #define CHROME_BROWSER_SPELLCHECKER_SPELLCHECKER_SESSION_BRIDGE_ANDROID_H_ | |
7 | |
8 #include <jni.h> | |
9 | |
10 #include <memory> | |
11 | |
12 #include "base/android/scoped_java_ref.h" | |
13 #include "base/macros.h" | |
14 #include "base/strings/string16.h" | |
15 | |
16 // A class used to interface between the Java class of the same name and the | |
17 // android message filter. This class receives text to be spellchecked | |
18 // from the message filter, sends that text to the Java side via JNI to be | |
19 // spellchecked, and then sends those results to the renderer. | |
20 class SpellCheckerSessionBridge { | |
21 public: | |
22 explicit SpellCheckerSessionBridge(int render_process_id); | |
23 ~SpellCheckerSessionBridge(); | |
24 static bool RegisterJNI(JNIEnv* env); | |
25 | |
26 // Receives text to be checked from the message filter and sends it to Java | |
27 // to be spellchecked. | |
28 void RequestTextCheck(int route_id, | |
29 int identifier, | |
30 const base::string16& text); | |
31 | |
32 // Receives information from Java side about the typos in a given string | |
33 // of text, processes these and sends them to the renderer. | |
34 void ProcessSpellCheckResults( | |
35 JNIEnv* env, | |
36 const base::android::JavaParamRef<jobject>& jobj, | |
37 const base::android::JavaParamRef<jintArray>& offset_array, | |
38 const base::android::JavaParamRef<jintArray>& length_array); | |
39 | |
40 // Sets the handle to the Java SpellCheckerSessionBridge object to null, | |
41 // marking the Java object for garbage collection. | |
42 void DisconnectSession(); | |
43 | |
44 private: | |
45 struct SpellingRequest { | |
46 SpellingRequest(int route_id, int identifier, const base::string16& text); | |
47 ~SpellingRequest(); | |
48 | |
49 int route_id; | |
50 int identifier; | |
51 base::string16 text; | |
52 }; | |
53 | |
54 int render_process_id_; | |
55 | |
56 std::unique_ptr<SpellingRequest> active_request_; | |
57 std::unique_ptr<SpellingRequest> pending_request_; | |
58 | |
59 base::android::ScopedJavaGlobalRef<jobject> java_object_; | |
60 bool java_object_initialization_failed_; | |
61 | |
62 DISALLOW_COPY_AND_ASSIGN(SpellCheckerSessionBridge); | |
63 }; | |
64 | |
65 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECKER_SESSION_BRIDGE_ANDROID_H_ | |
OLD | NEW |