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 "chrome/browser/spellchecker/spellchecker_session_bridge_android.h" | 5 #include "chrome/browser/spellchecker/spellchecker_session_bridge_android.h" |
6 | 6 |
7 #include "base/android/jni_array.h" | 7 #include "base/android/jni_array.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "chrome/common/spellcheck_messages.h" | 9 #include "chrome/common/spellcheck_messages.h" |
10 #include "chrome/common/spellcheck_result.h" | 10 #include "chrome/common/spellcheck_result.h" |
11 #include "content/public/browser/render_process_host.h" | 11 #include "content/public/browser/render_process_host.h" |
12 #include "jni/SpellCheckerSessionBridge_jni.h" | 12 #include "jni/SpellCheckerSessionBridge_jni.h" |
13 | 13 |
14 SpellCheckerSessionBridge::SpellCheckerSessionBridge(int render_process_id) | 14 SpellCheckerSessionBridge::SpellCheckerSessionBridge(int render_process_id) |
15 : render_process_id_(render_process_id) {} | 15 : render_process_id_(render_process_id) {} |
16 | 16 |
17 SpellCheckerSessionBridge::~SpellCheckerSessionBridge() {} | 17 SpellCheckerSessionBridge::~SpellCheckerSessionBridge() {} |
18 | 18 |
19 // static | 19 // static |
20 bool SpellCheckerSessionBridge::RegisterJNI(JNIEnv* env) { | 20 bool SpellCheckerSessionBridge::RegisterJNI(JNIEnv* env) { |
21 return RegisterNativesImpl(env); | 21 return RegisterNativesImpl(env); |
22 } | 22 } |
23 | 23 |
24 void SpellCheckerSessionBridge::RequestTextCheck(int route_id, | 24 void SpellCheckerSessionBridge::RequestTextCheck(int route_id, |
25 int identifier, | 25 int identifier, |
26 const base::string16& text) { | 26 const base::string16& text) { |
| 27 // SpellCheckerSessionBridge#create() will return null if spell checker |
| 28 // service is unavailable. |
| 29 if (java_object_initialization_failed_) |
| 30 return; |
| 31 |
27 // RequestTextCheck IPC arrives at the message filter before | 32 // RequestTextCheck IPC arrives at the message filter before |
28 // ToggleSpellCheck IPC when the user focuses an input field that already | 33 // ToggleSpellCheck IPC when the user focuses an input field that already |
29 // contains completed text. We need to initialize the spellchecker here | 34 // contains completed text. We need to initialize the spellchecker here |
30 // rather than in response to ToggleSpellCheck so that the existing text | 35 // rather than in response to ToggleSpellCheck so that the existing text |
31 // will be spellchecked immediately. | 36 // will be spellchecked immediately. |
32 if (java_object_.is_null()) { | 37 if (java_object_.is_null()) { |
33 java_object_.Reset(Java_SpellCheckerSessionBridge_create( | 38 java_object_.Reset(Java_SpellCheckerSessionBridge_create( |
34 base::android::AttachCurrentThread(), | 39 base::android::AttachCurrentThread(), |
35 reinterpret_cast<intptr_t>(this))); | 40 reinterpret_cast<intptr_t>(this))); |
| 41 if (java_object_.is_null()) { |
| 42 java_object_initialization_failed_ = true; |
| 43 return; |
| 44 } |
36 } | 45 } |
37 | 46 |
38 // Save incoming requests to run at the end of the currently active request. | 47 // Save incoming requests to run at the end of the currently active request. |
39 // If multiple requests arrive during one active request, only the most | 48 // If multiple requests arrive during one active request, only the most |
40 // recent request will run (the others get overwritten). | 49 // recent request will run (the others get overwritten). |
41 if (active_request_) { | 50 if (active_request_) { |
42 pending_request_.reset(new SpellingRequest(route_id, identifier, text)); | 51 pending_request_.reset(new SpellingRequest(route_id, identifier, text)); |
43 return; | 52 return; |
44 } | 53 } |
45 | 54 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 java_object_.Reset(); | 100 java_object_.Reset(); |
92 } | 101 } |
93 | 102 |
94 SpellCheckerSessionBridge::SpellingRequest::SpellingRequest( | 103 SpellCheckerSessionBridge::SpellingRequest::SpellingRequest( |
95 int route_id, | 104 int route_id, |
96 int identifier, | 105 int identifier, |
97 const base::string16& text) | 106 const base::string16& text) |
98 : route_id(route_id), identifier(identifier), text(text) {} | 107 : route_id(route_id), identifier(identifier), text(text) {} |
99 | 108 |
100 SpellCheckerSessionBridge::SpellingRequest::~SpellingRequest() {} | 109 SpellCheckerSessionBridge::SpellingRequest::~SpellingRequest() {} |
OLD | NEW |