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 "components/spellcheck/browser/spellchecker_session_bridge_android.h" | 5 #include "components/spellcheck/browser/spellchecker_session_bridge_android.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 87 |
88 JNIEnv* env = base::android::AttachCurrentThread(); | 88 JNIEnv* env = base::android::AttachCurrentThread(); |
89 Java_SpellCheckerSessionBridge_requestTextCheck( | 89 Java_SpellCheckerSessionBridge_requestTextCheck( |
90 env, java_object_, base::android::ConvertUTF16ToJavaString(env, text)); | 90 env, java_object_, base::android::ConvertUTF16ToJavaString(env, text)); |
91 } | 91 } |
92 | 92 |
93 void SpellCheckerSessionBridge::ProcessSpellCheckResults( | 93 void SpellCheckerSessionBridge::ProcessSpellCheckResults( |
94 JNIEnv* env, | 94 JNIEnv* env, |
95 const JavaParamRef<jobject>& jobj, | 95 const JavaParamRef<jobject>& jobj, |
96 const JavaParamRef<jintArray>& offset_array, | 96 const JavaParamRef<jintArray>& offset_array, |
97 const JavaParamRef<jintArray>& length_array) { | 97 const JavaParamRef<jintArray>& length_array, |
| 98 const JavaParamRef<jobjectArray>& suggestions_array) { |
98 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 99 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
99 std::vector<int> offsets; | 100 std::vector<int> offsets; |
100 std::vector<int> lengths; | 101 std::vector<int> lengths; |
101 | 102 |
102 base::android::JavaIntArrayToIntVector(env, offset_array, &offsets); | 103 base::android::JavaIntArrayToIntVector(env, offset_array, &offsets); |
103 base::android::JavaIntArrayToIntVector(env, length_array, &lengths); | 104 base::android::JavaIntArrayToIntVector(env, length_array, &lengths); |
104 | 105 |
105 std::vector<SpellCheckResult> results; | 106 std::vector<SpellCheckResult> results; |
106 for (size_t i = 0; i < offsets.size(); i++) { | 107 for (size_t i = 0; i < offsets.size(); i++) { |
107 results.push_back( | 108 base::android::ScopedJavaLocalRef<jobjectArray> suggestions_for_word_array( |
108 SpellCheckResult(SpellCheckResult::SPELLING, offsets[i], lengths[i])); | 109 env, static_cast<jobjectArray>( |
| 110 env->GetObjectArrayElement(suggestions_array, i))); |
| 111 std::vector<base::string16> suggestions_for_word; |
| 112 base::android::AppendJavaStringArrayToStringVector( |
| 113 env, suggestions_for_word_array.obj(), &suggestions_for_word); |
| 114 results.push_back(SpellCheckResult(SpellCheckResult::SPELLING, offsets[i], |
| 115 lengths[i], suggestions_for_word)); |
109 } | 116 } |
110 | 117 |
111 content::RenderProcessHost* sender = | 118 content::RenderProcessHost* sender = |
112 content::RenderProcessHost::FromID(render_process_id_); | 119 content::RenderProcessHost::FromID(render_process_id_); |
113 | 120 |
114 if (sender != nullptr) { | 121 if (sender != nullptr) { |
115 sender->Send(new SpellCheckMsg_RespondTextCheck( | 122 sender->Send(new SpellCheckMsg_RespondTextCheck( |
116 active_request_->route_id, active_request_->identifier, | 123 active_request_->route_id, active_request_->identifier, |
117 active_request_->text, results)); | 124 active_request_->text, results)); |
118 } | 125 } |
(...skipping 23 matching lines...) Expand all Loading... |
142 } | 149 } |
143 } | 150 } |
144 | 151 |
145 SpellCheckerSessionBridge::SpellingRequest::SpellingRequest( | 152 SpellCheckerSessionBridge::SpellingRequest::SpellingRequest( |
146 int route_id, | 153 int route_id, |
147 int identifier, | 154 int identifier, |
148 const base::string16& text) | 155 const base::string16& text) |
149 : route_id(route_id), identifier(identifier), text(text) {} | 156 : route_id(route_id), identifier(identifier), text(text) {} |
150 | 157 |
151 SpellCheckerSessionBridge::SpellingRequest::~SpellingRequest() {} | 158 SpellCheckerSessionBridge::SpellingRequest::~SpellingRequest() {} |
OLD | NEW |