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

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: Several style changes 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
« no previous file with comments | « chrome/browser/spellchecker/spellchecker_session_bridge_android.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..25a62a3057dc004207d8822e2553e562fdd34bb9
--- /dev/null
+++ b/chrome/browser/spellchecker/spellchecker_session_bridge_android.cc
@@ -0,0 +1,91 @@
+// 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 "base/android/jni_array.h"
+#include "base/android/jni_string.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::RegisterJNI(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+void SpellCheckerSessionBridge::RequestTextCheck(int route_id,
+ int identifier,
+ const base::string16& text) {
+ if (java_object_.is_null())
+ return;
+
+ // Save incoming requests to run at the end of the currently active request.
+ // If multiple requests arrive during one active request, only the most
+ // recent request will run (the others get overwritten).
+ if (active_request_) {
+ pending_request_.reset(new SpellingRequest(route_id, identifier, text));
+ return;
+ }
+
+ active_request_.reset(new SpellingRequest(route_id, identifier, text));
+
+ JNIEnv* env = base::android::AttachCurrentThread();
+ Java_SpellCheckerSessionBridge_requestTextCheck(
+ env, java_object_.obj(),
+ base::android::ConvertUTF16ToJavaString(env, text).obj());
+}
+
+void SpellCheckerSessionBridge::ProcessSpellCheckResults(
+ JNIEnv* env,
+ jobject jobj,
+ jintArray offset_array,
+ jintArray length_array) {
+ std::vector<int> offsets;
+ std::vector<int> lengths;
+
+ base::android::JavaIntArrayToIntVector(env, offset_array, &offsets);
+ base::android::JavaIntArrayToIntVector(env, length_array, &lengths);
+
+ std::vector<SpellCheckResult> results;
+ for (size_t i = 0; i < offsets.size(); i++) {
+ results.push_back(
+ SpellCheckResult(SpellCheckResult::SPELLING, offsets[i], lengths[i]));
+ }
+
+ content::RenderProcessHost* sender =
+ content::RenderProcessHost::FromID(render_process_id_);
+
+ if (sender != nullptr) {
+ sender->Send(new SpellCheckMsg_RespondTextCheck(
+ active_request_->route_id, active_request_->identifier,
+ active_request_->text, results));
+ }
+
+ active_request_ = pending_request_.Pass();
+ if (active_request_) {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ Java_SpellCheckerSessionBridge_requestTextCheck(
+ env, java_object_.obj(),
+ base::android::ConvertUTF16ToJavaString(env, active_request_->text)
+ .obj());
+ }
+}
+
+SpellCheckerSessionBridge::SpellingRequest::SpellingRequest(
+ int route_id,
+ int identifier,
+ const base::string16& text)
+ : route_id(route_id), identifier(identifier), text(text) {}
+
+SpellCheckerSessionBridge::SpellingRequest::~SpellingRequest() {}
« no previous file with comments | « chrome/browser/spellchecker/spellchecker_session_bridge_android.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698