OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/spellchecker/spellcheck_platform.h" | 5 #include "chrome/browser/spellchecker/spellcheck_platform.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | |
8 #include "base/android/jni_array.h" | |
9 #include "base/android/jni_string.h" | |
7 #include "base/callback.h" | 10 #include "base/callback.h" |
8 #include "base/command_line.h" | 11 #include "base/command_line.h" |
9 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/spellcheck_result.h" | |
14 #include "jni/SpellCheckerSessionBridge_jni.h" | |
15 | |
16 namespace { | |
17 std::vector<int> offsets; | |
18 std::vector<int> lengths; | |
19 base::android::ScopedJavaGlobalRef<jobject> java_object_; | |
20 base::Callback<void(const std::vector<SpellCheckResult>&)> callback_; | |
please use gerrit instead
2015/08/04 22:04:26
Don't use shared variables like this, as it will n
| |
21 } // namespace | |
10 | 22 |
11 namespace spellcheck_platform { | 23 namespace spellcheck_platform { |
12 | 24 |
13 void GetAvailableLanguages(std::vector<std::string>* spellcheck_languages) { | 25 void GetAvailableLanguages(std::vector<std::string>* spellcheck_languages) { |
14 } | 26 } |
15 | 27 |
16 bool SpellCheckerAvailable() { | 28 bool SpellCheckerAvailable() { |
17 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 29 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
18 switches::kEnableAndroidSpellChecker); | 30 switches::kEnableAndroidSpellChecker); |
19 } | 31 } |
20 | 32 |
21 bool SpellCheckerProvidesPanel() { | 33 bool SpellCheckerProvidesPanel() { |
22 return false; | 34 return false; |
23 } | 35 } |
24 | 36 |
25 bool SpellingPanelVisible() { | 37 bool SpellingPanelVisible() { |
26 return false; | 38 return false; |
27 } | 39 } |
28 | 40 |
29 void ShowSpellingPanel(bool show) { | 41 void ShowSpellingPanel(bool show) { |
30 } | 42 } |
31 | 43 |
32 void UpdateSpellingPanelWithMisspelledWord(const base::string16& word) { | 44 void UpdateSpellingPanelWithMisspelledWord(const base::string16& word) { |
33 } | 45 } |
34 | 46 |
35 bool PlatformSupportsLanguage(const std::string& current_language) { | 47 bool PlatformSupportsLanguage(const std::string& current_language) { |
36 return true; | 48 return true; |
37 } | 49 } |
38 | 50 |
39 void SetLanguage(const std::string& lang_to_set) { | 51 void SetLanguage(const std::string& lang_to_set) { |
40 } | 52 } |
41 | 53 |
42 bool CheckSpelling(const base::string16& word_to_check, int tag) { | 54 bool CheckSpelling(const base::string16& word_to_check, int tag) { |
43 return true; | 55 return true; |
44 } | 56 } |
45 | 57 |
46 void FillSuggestionList(const base::string16& wrong_word, | 58 void FillSuggestionList(const base::string16& wrong_word, |
47 std::vector<base::string16>* optional_suggestions) { | 59 std::vector<base::string16>* optional_suggestions) { |
48 } | 60 } |
49 | 61 |
50 void AddWord(const base::string16& word) { | 62 void AddWord(const base::string16& word) { |
51 } | 63 } |
52 | 64 |
53 void RemoveWord(const base::string16& word) { | 65 void RemoveWord(const base::string16& word) { |
54 } | 66 } |
55 | 67 |
56 int GetDocumentTag() { | 68 int GetDocumentTag() { |
57 return 1; | 69 return 1; |
58 } | 70 } |
59 | 71 |
60 void IgnoreWord(const base::string16& word) { | 72 void IgnoreWord(const base::string16& word) { |
61 } | 73 } |
62 | 74 |
63 void CloseDocumentWithTag(int tag) { | 75 void CloseDocumentWithTag(int tag) { |
64 } | 76 } |
65 | 77 |
66 void RequestTextCheck(int document_tag, | 78 void RequestTextCheck(int document_tag, |
67 const base::string16& text, | 79 const base::string16& text, |
68 TextCheckCompleteCallback callback) { | 80 TextCheckCompleteCallback callback) { |
81 JNIEnv* env = base::android::AttachCurrentThread(); | |
82 callback_ = callback; | |
83 LOG(ERROR) << "DYLANKING RequestTextCheck on " << text; | |
84 Java_SpellCheckerSessionBridge_checkSpelling(env, java_object_.obj(), | |
85 base::android::ConvertUTF16ToJavaString(env, text).obj()); | |
86 } | |
69 | 87 |
88 void InitializeJNIBridge() { | |
89 JNIEnv* env = base::android::AttachCurrentThread(); | |
90 java_object_.Reset( | |
91 Java_SpellCheckerSessionBridge_create(env)); | |
92 } | |
93 | |
94 //static | |
95 bool RegisterSpellcheckPlatformAndroid(JNIEnv* env) { | |
96 return RegisterNativesImpl(env); | |
97 } | |
98 | |
99 //static | |
100 void GetSpellcheckInfo(JNIEnv* env, jobject jobj, jobjectArray suggestionsArray, | |
101 jintArray offsetArray, jintArray lengthArray){ | |
102 | |
103 LOG(ERROR) << "DYLANKING In Native GetSpellcheckInfo"; | |
104 std::vector<SpellCheckResult> check_results; | |
105 std::vector<base::string16> optional_suggestions; | |
106 base::android::AppendJavaStringArrayToStringVector(env, suggestionsArray, &opt ional_suggestions); | |
107 | |
108 /*for(unsigned int i = 0; i < optional_suggestions.size(); i++){ | |
109 LOG(ERROR) << "DYLANKING " << optional_suggestions[i]; | |
110 } */ | |
111 | |
112 base::android::JavaIntArrayToIntVector(env, offsetArray, &offsets); | |
113 base::android::JavaIntArrayToIntVector(env, lengthArray, &lengths); | |
114 | |
115 for(unsigned int j = 0; j < offsets.size(); j++){ | |
116 LOG(ERROR) << "DYLANKING offset: " << offsets[j] << " length: " << lengths[j ]; | |
117 check_results.push_back(SpellCheckResult(SpellCheckResult::SPELLING,offsets[ j],lengths[j])); | |
118 } | |
119 | |
120 callback_.Run(check_results); | |
please use gerrit instead
2015/08/04 22:04:26
All this code should be in spellcheck_message_filt
| |
70 } | 121 } |
71 | 122 |
72 } // namespace spellcheck_platform | 123 } // namespace spellcheck_platform |
OLD | NEW |