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

Side by Side 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: #ifdef declaration in message filter to have mac compile 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 unified diff | Download patch
OLDNEW
(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 "base/android/jni_array.h"
8 #include "base/android/jni_string.h"
9 #include "chrome/common/spellcheck_messages.h"
10 #include "chrome/common/spellcheck_result.h"
11 #include "content/public/browser/render_process_host.h"
12 #include "jni/SpellCheckerSessionBridge_jni.h"
13
14 SpellCheckerSessionBridge::SpellingRequest::SpellingRequest(
please use gerrit instead 2015/08/17 21:29:46 Match the order of methods in the header and the s
dylanking 2015/08/18 01:21:31 Good point, done.
15 int new_route_id,
please use gerrit instead 2015/08/17 21:29:46 Name your parameters the same in both header and s
dylanking 2015/08/18 01:21:31 Ah, I didn't know the compiler would be ok with th
16 int new_identifier,
17 const base::string16& new_text)
18 : route_id(new_route_id), identifier(new_identifier), text(new_text) {}
19
20 SpellCheckerSessionBridge::SpellCheckerSessionBridge(int render_process_id)
21 : render_process_id_(render_process_id),
22 java_object_(Java_SpellCheckerSessionBridge_create(
23 base::android::AttachCurrentThread(),
24 reinterpret_cast<intptr_t>(this))) {}
25
26 SpellCheckerSessionBridge::~SpellCheckerSessionBridge() {}
27
28 // static
29 bool SpellCheckerSessionBridge::RegisterJNI(JNIEnv* env) {
30 return RegisterNativesImpl(env);
31 }
32
33 void SpellCheckerSessionBridge::RequestTextCheck(int route_id,
34 int identifier,
35 const base::string16& text) {
36 if (java_object_.is_null()) {
please use gerrit instead 2015/08/17 21:29:46 C++ style (unlike Java style) says do not put curl
dylanking 2015/08/18 01:21:31 Done.
37 return;
38 }
39
40 // Save incoming requests to run at the end of the currently active request.
41 // If multiple requests arrive during one active request, only the most
42 // recent request will run (the others get overwritten).
43 if (active_request_) {
44 pending_request_.reset(new SpellingRequest(route_id, identifier, text));
45 return;
46 }
47
48 active_request_.reset(new SpellingRequest(route_id, identifier, text));
49
50 JNIEnv* env = base::android::AttachCurrentThread();
51 Java_SpellCheckerSessionBridge_requestTextCheck(
52 env, java_object_.obj(),
53 base::android::ConvertUTF16ToJavaString(env, text).obj());
54 }
55
56 void SpellCheckerSessionBridge::ProcessSpellCheckResults(
57 JNIEnv* env,
58 jobject jobj,
59 jintArray offset_array,
60 jintArray length_array) {
61 std::vector<int> offsets;
62 std::vector<int> lengths;
63
64 base::android::JavaIntArrayToIntVector(env, offset_array, &offsets);
65 base::android::JavaIntArrayToIntVector(env, length_array, &lengths);
66
67 // Convert specific offset/length pairs into SpellCheckResults, which can be
68 // sent to the renderer to be drawn as red underlines.
please use gerrit instead 2015/08/17 21:29:46 It's obvious what this code is doing. Remove this
dylanking 2015/08/18 01:21:31 Removed.
69 std::vector<SpellCheckResult> results;
70 for (size_t i = 0; i < offsets.size(); i++) {
71 results.push_back(
72 SpellCheckResult(SpellCheckResult::SPELLING, offsets[i], lengths[i]));
73 }
74
75 content::RenderProcessHost* sender =
76 content::RenderProcessHost::FromID(render_process_id_);
77
78 if (sender != nullptr) {
79 sender->Send(new SpellCheckMsg_RespondTextCheck(
80 active_request_->route_id, active_request_->identifier,
81 active_request_->text, results));
82 }
83
84 // If any pending requests arrived during the execution of this active
85 // request, the most recently arrived pending request will become the active
86 // request and be run.
please use gerrit instead 2015/08/17 21:29:46 It's clear what the code is doing. Remove this com
dylanking 2015/08/18 01:21:31 Removed.
87 active_request_ = pending_request_.Pass();
88 if (active_request_) {
89 JNIEnv* env = base::android::AttachCurrentThread();
90 Java_SpellCheckerSessionBridge_requestTextCheck(
91 env, java_object_.obj(),
92 base::android::ConvertUTF16ToJavaString(env, active_request_->text)
93 .obj());
94 }
95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698