Chromium Code Reviews| Index: chrome/browser/spellchecker/spellcheck_message_filter_platform_android.cc |
| diff --git a/chrome/browser/spellchecker/spellcheck_message_filter_platform_android.cc b/chrome/browser/spellchecker/spellcheck_message_filter_platform_android.cc |
| index 4c7a6c8c2239632cf080c976e6c18a63d524d54b..7b4ce4efb2ec77ef57d588930c10eaede5fdea5f 100644 |
| --- a/chrome/browser/spellchecker/spellcheck_message_filter_platform_android.cc |
| +++ b/chrome/browser/spellchecker/spellcheck_message_filter_platform_android.cc |
| @@ -4,9 +4,18 @@ |
| #include "chrome/browser/spellchecker/spellcheck_message_filter_platform.h" |
| +#include <algorithm> |
| + |
| +#include "base/android/jni_android.h" |
| +#include "base/android/jni_array.h" |
| +#include "base/android/jni_string.h" |
| +#include "base/barrier_closure.h" |
| +#include "base/bind.h" |
| +#include "chrome/browser/spellchecker/spellcheck_platform.h" |
| #include "chrome/common/spellcheck_messages.h" |
| #include "chrome/common/spellcheck_result.h" |
| #include "content/public/browser/browser_thread.h" |
| +#include "jni/SpellCheckerSessionBridge_jni.h" |
| using content::BrowserThread; |
| @@ -14,18 +23,37 @@ SpellCheckMessageFilterPlatform::SpellCheckMessageFilterPlatform( |
| int render_process_id) |
| : BrowserMessageFilter(SpellCheckMsgStart), |
| render_process_id_(render_process_id) { |
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + java_object_.Reset( |
| + Java_SpellCheckerSessionBridge_create(env, reinterpret_cast<intptr_t>(this))); |
| + |
| } |
| void SpellCheckMessageFilterPlatform::OverrideThreadForMessage( |
| const IPC::Message& message, BrowserThread::ID* thread) { |
| + if (message.type() == SpellCheckHostMsg_RequestTextCheck::ID) |
| + *thread = BrowserThread::UI; |
| } |
| bool SpellCheckMessageFilterPlatform::OnMessageReceived( |
| const IPC::Message& message) { |
| - return true; |
| + bool handled = true; |
| + IPC_BEGIN_MESSAGE_MAP(SpellCheckMessageFilterPlatform, message) |
| + IPC_MESSAGE_HANDLER(SpellCheckHostMsg_CheckSpelling, |
|
please use gerrit instead
2015/08/06 16:58:28
Only OnRequestTextCheck does any work, so let's no
dylanking
2015/08/07 03:33:53
Done.
|
| + OnCheckSpelling) |
| + IPC_MESSAGE_HANDLER(SpellCheckHostMsg_FillSuggestionList, |
| + OnFillSuggestionList) |
| + IPC_MESSAGE_HANDLER(SpellCheckHostMsg_ShowSpellingPanel, |
| + OnShowSpellingPanel) |
| + IPC_MESSAGE_HANDLER(SpellCheckHostMsg_UpdateSpellingPanelWithMisspelledWord, |
| + OnUpdateSpellingPanelWithMisspelledWord) |
| + IPC_MESSAGE_HANDLER(SpellCheckHostMsg_RequestTextCheck, |
| + OnRequestTextCheck) |
| + IPC_MESSAGE_UNHANDLED(handled = false) |
| + IPC_END_MESSAGE_MAP() |
| + return handled; |
| } |
| -// static |
|
please use gerrit instead
2015/08/06 16:58:28
It's Chrome convention to put // static above defi
dylanking
2015/08/07 03:33:53
Done.
|
| void SpellCheckMessageFilterPlatform::CombineResults( |
| std::vector<SpellCheckResult>* remote_results, |
| const std::vector<SpellCheckResult>& local_results) { |
| @@ -56,13 +84,49 @@ void SpellCheckMessageFilterPlatform::OnRequestTextCheck( |
| int identifier, |
| const base::string16& text, |
| std::vector<SpellCheckMarker> markers) { |
| + |
|
groby-ooo-7-16
2015/08/06 22:10:08
No empty line, please
dylanking
2015/08/07 03:33:54
Done.
|
| + DCHECK(!text.empty()); |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + |
| + route_id_ = route_id; |
| + identifier_ = identifier; |
| + |
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + Java_SpellCheckerSessionBridge_checkSpelling(env, java_object_.obj(), |
| + base::android::ConvertUTF16ToJavaString(env, text).obj()); |
| +} |
| + |
| +//static |
| +bool SpellCheckMessageFilterPlatform::RegisterSpellCheckMessageFilterPlatform(JNIEnv* env) { |
|
groby-ooo-7-16
2015/08/06 22:10:08
It's not static in the header.
dylanking
2015/08/07 03:33:54
It is now :)
|
| + return RegisterNativesImpl(env); |
| +} |
| + |
| +void SpellCheckMessageFilterPlatform::GetSpellcheckInfo(JNIEnv* env, |
| + jobject jobj, jstring text, |
| + jintArray offsetArray, jintArray lengthArray){ |
| + |
| + std::vector<int> offsets; |
| + std::vector<int> lengths; |
| + std::vector<SpellCheckResult> local_results; |
| + base::android::JavaIntArrayToIntVector(env, offsetArray, &offsets); |
| + base::android::JavaIntArrayToIntVector(env, lengthArray, &lengths); |
| + |
| + for(unsigned int j = 0; j < offsets.size(); j++){ |
| + local_results.push_back(SpellCheckResult(SpellCheckResult::SPELLING,offsets[j],lengths[j])); |
| + } |
| + |
| + Send(new SpellCheckMsg_RespondTextCheck( |
| + route_id_, |
| + identifier_, |
| + base::android::ConvertJavaStringToUTF16(env, text), |
| + local_results)); |
| } |
| int SpellCheckMessageFilterPlatform::ToDocumentTag(int route_id) { |
| - NOTREACHED(); |
| - return -1; |
| + NOTREACHED(); |
| + return -1; |
| } |
| void SpellCheckMessageFilterPlatform::RetireDocumentTag(int route_id) { |
| - NOTREACHED(); |
| + NOTREACHED(); |
| } |