Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3577)

Unified Diff: chrome/browser/spellchecker/spellchecker_session_bridge_android.cc

Issue 1275813002: Implemented typo recognition in Chrome for Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@4_remove_mac_redundancies
Patch Set: Added a clarifying comment about Locale to the java file Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/spellchecker/spellchecker_session_bridge_android.cc
diff --git a/chrome/browser/spellchecker/spellchecker_session_bridge_android.cc b/chrome/browser/spellchecker/spellchecker_session_bridge_android.cc
new file mode 100644
index 0000000000000000000000000000000000000000..729e9cf9e7175b60a9dd70363a6d3925a2f15525
--- /dev/null
+++ b/chrome/browser/spellchecker/spellchecker_session_bridge_android.cc
@@ -0,0 +1,65 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/spellchecker/spellchecker_session_bridge_android.h"
+
+#include "chrome/common/spellcheck_messages.h"
+#include "chrome/common/spellcheck_result.h"
+#include "content/public/browser/render_process_host.h"
+#include "jni/SpellCheckerSessionBridge_jni.h"
+
+SpellCheckerSessionBridge::SpellCheckerSessionBridge(int render_process_id)
+ : render_process_id_(render_process_id),
+ java_object_(Java_SpellCheckerSessionBridge_create(
+ base::android::AttachCurrentThread(),
+ reinterpret_cast<intptr_t>(this))) {}
+
+SpellCheckerSessionBridge::~SpellCheckerSessionBridge() {}
+
+// static
+bool SpellCheckerSessionBridge::RegisterSpellCheckerSessionBridge(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
newt (away) 2015/08/12 16:12:58 newline
dylanking 2015/08/13 02:10:03 Thanks, done.
+void SpellCheckerSessionBridge::RequestTextCheck(int route_id,
+ int identifier,
+ const base::string16& text) {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ Java_SpellCheckerSessionBridge_requestTextCheck(
+ env, java_object_.obj(), route_id, identifier,
+ base::android::ConvertUTF16ToJavaString(env, text).obj());
+}
+
+// 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
+// typos at specific offsets and of specific lengths in the text. Converts
+// these values into SpellCheckResults, which can then be sent to the renderer
+// to be rendered as red underlines.
+void SpellCheckerSessionBridge::ProcessSpellCheckResults(
+ JNIEnv* env,
+ jobject jobj,
+ jint route_id,
+ jint identifier,
+ jstring text,
+ jintArray offsetArray,
+ jintArray lengthArray) {
+ std::vector<int> offsets;
+ std::vector<int> lengths;
+
+ base::android::JavaIntArrayToIntVector(env, offsetArray, &offsets);
+ base::android::JavaIntArrayToIntVector(env, lengthArray, &lengths);
+
+ std::vector<SpellCheckResult> results;
+ 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.
+ results.push_back(
+ SpellCheckResult(SpellCheckResult::SPELLING, offsets[j], lengths[j]));
+ }
+
+ content::RenderProcessHost* sender =
+ content::RenderProcessHost::FromID(render_process_id_);
+
+ if (sender) {
+ sender->Send(new SpellCheckMsg_RespondTextCheck(
+ (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.
+ base::android::ConvertJavaStringToUTF16(env, text), results));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698