Chromium Code Reviews| 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 #include "chrome/browser/spellchecker/spellchecker_session_bridge_android.h" | |
| 6 | |
| 7 #include "chrome/common/spellcheck_messages.h" | |
| 8 #include "chrome/common/spellcheck_result.h" | |
| 9 #include "content/public/browser/render_process_host.h" | |
| 10 #include "jni/SpellCheckerSessionBridge_jni.h" | |
| 11 | |
| 12 SpellCheckerSessionBridge::SpellCheckerSessionBridge(int render_process_id) | |
| 13 : render_process_id_(render_process_id), | |
| 14 java_object_(Java_SpellCheckerSessionBridge_create( | |
| 15 base::android::AttachCurrentThread(), | |
| 16 reinterpret_cast<intptr_t>(this))) {} | |
| 17 | |
| 18 SpellCheckerSessionBridge::~SpellCheckerSessionBridge() {} | |
| 19 | |
| 20 // static | |
| 21 bool SpellCheckerSessionBridge::RegisterSpellCheckerSessionBridge(JNIEnv* env) { | |
| 22 return RegisterNativesImpl(env); | |
| 23 } | |
|
newt (away)
2015/08/12 16:12:58
newline
dylanking
2015/08/13 02:10:03
Thanks, done.
| |
| 24 void SpellCheckerSessionBridge::RequestTextCheck(int route_id, | |
| 25 int identifier, | |
| 26 const base::string16& text) { | |
| 27 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 28 Java_SpellCheckerSessionBridge_requestTextCheck( | |
| 29 env, java_object_.obj(), route_id, identifier, | |
| 30 base::android::ConvertUTF16ToJavaString(env, text).obj()); | |
| 31 } | |
| 32 | |
| 33 // Receives the spellcheck results back from the Java side in the form of | |
|
newt (away)
2015/08/12 16:12:58
Put method-level comments in the .h file only. Imp
dylanking
2015/08/13 02:10:03
I had tried to elaborate a little bit more on the
| |
| 34 // typos at specific offsets and of specific lengths in the text. Converts | |
| 35 // these values into SpellCheckResults, which can then be sent to the renderer | |
| 36 // to be rendered as red underlines. | |
| 37 void SpellCheckerSessionBridge::ProcessSpellCheckResults( | |
| 38 JNIEnv* env, | |
| 39 jobject jobj, | |
| 40 jint route_id, | |
| 41 jint identifier, | |
| 42 jstring text, | |
| 43 jintArray offsetArray, | |
| 44 jintArray lengthArray) { | |
| 45 std::vector<int> offsets; | |
| 46 std::vector<int> lengths; | |
| 47 | |
| 48 base::android::JavaIntArrayToIntVector(env, offsetArray, &offsets); | |
| 49 base::android::JavaIntArrayToIntVector(env, lengthArray, &lengths); | |
| 50 | |
| 51 std::vector<SpellCheckResult> results; | |
| 52 for (unsigned int j = 0; j < offsets.size(); j++) { | |
|
newt (away)
2015/08/12 16:12:58
I believe this should be "size_t", not "unsigned i
dylanking
2015/08/13 02:10:03
Done, good catch. Thanks.
| |
| 53 results.push_back( | |
| 54 SpellCheckResult(SpellCheckResult::SPELLING, offsets[j], lengths[j])); | |
| 55 } | |
| 56 | |
| 57 content::RenderProcessHost* sender = | |
| 58 content::RenderProcessHost::FromID(render_process_id_); | |
| 59 | |
| 60 if (sender) { | |
| 61 sender->Send(new SpellCheckMsg_RespondTextCheck( | |
| 62 (int)route_id, (int)identifier, | |
|
newt (away)
2015/08/12 16:12:58
nit: use static_cast<int>() instead of (int). Howe
dylanking
2015/08/13 02:10:03
Removed the casts altogether.
| |
| 63 base::android::ConvertJavaStringToUTF16(env, text), results)); | |
| 64 } | |
| 65 } | |
| OLD | NEW |