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

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

Issue 1244443005: Patch 5: Implemented android message filter and platform. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@4_remove_mac_redundancies
Patch Set: 1:1 SpellingRequest/JavaObject relationship, slow when spammed 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/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..dd426976d63c4d4c6fa8d452916f80346a980d31 100644
--- a/chrome/browser/spellchecker/spellcheck_message_filter_platform_android.cc
+++ b/chrome/browser/spellchecker/spellcheck_message_filter_platform_android.cc
@@ -4,11 +4,113 @@
#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;
+/*
+namespace{
+
+ bool CompareLocation(const SpellCheckResult& r1,
+ const SpellCheckResult& r2) {
+ return r1.location < r2.location;
+ }
+
+} // namespace
+*/
+
+SpellingRequest::SpellingRequest(content::BrowserMessageFilter* destination,
+ int render_process_id)
+ : destination_(destination),
+ render_process_id_(render_process_id),
+ route_id_(-1),
+ identifier_(-1) {
+ destination_->AddRef();
+ JNIEnv* env = base::android::AttachCurrentThread();
+ java_object_.Reset(
+ Java_SpellCheckerSessionBridge_create(env, reinterpret_cast<intptr_t>(this)));
+}
+
+//static
+bool SpellingRequest::RegisterSpellingRequest(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+void SpellingRequest::GetSpellcheckInfo(JNIEnv* env, jobject jobj, jobjectArray suggestionsArray,
+ jintArray offsetArray, jintArray lengthArray){
+
+ LOG(ERROR) << "DYLANKING In Native GetSpellcheckInfo";
+ //std::vector<base::string16> optional_suggestions;
+ //base::android::AppendJavaStringArrayToStringVector(env, suggestionsArray, &optional_suggestions);
+
+ /*for(unsigned int i = 0; i < optional_suggestions.size(); i++){
+ LOG(ERROR) << "DYLANKING " << optional_suggestions[i];
+ } */
+ std::vector<int> offsets;
+ std::vector<int> lengths;
+ base::android::JavaIntArrayToIntVector(env, offsetArray, &offsets);
+ base::android::JavaIntArrayToIntVector(env, lengthArray, &lengths);
+
+ for(unsigned int j = 0; j < offsets.size(); j++){
+ //LOG(ERROR) << "DYLANKING offset: " << offsets[j] << " length: " << lengths[j];
+ local_results_.push_back(SpellCheckResult(SpellCheckResult::SPELLING,offsets[j],lengths[j]));
+ }
+
+ completion_barrier_.Run();
+}
+
+void SpellingRequest::RequestCheck(
+ const base::string16& text,
+ int route_id,
+ int identifier) {
+ DCHECK(!text.empty());
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+
+ text_ = text;
+ route_id_ = route_id;
+ identifier_ = identifier;
+
+ // The barrier owns |this|, ensuring it is deleted
+ // after completion.
+ completion_barrier_ =
+ BarrierClosure(1,
+ base::Bind(&SpellingRequest::OnCheckCompleted,
+ base::Owned(this)));
+ RequestLocalCheck();
+}
+
+void SpellingRequest::RequestLocalCheck() {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ Java_SpellCheckerSessionBridge_checkSpelling(env, java_object_.obj(),
+ base::android::ConvertUTF16ToJavaString(env, text_).obj());
+}
+
+void SpellingRequest::OnCheckCompleted() {
+ // Final completion can happen on any thread - don't DCHECK thread.
+ const std::vector<SpellCheckResult>* check_results = &local_results_;
+ //std::sort(local_results_.begin(), local_results_.end(), CompareLocation);
+
+ destination_->Send(
+ new SpellCheckMsg_RespondTextCheck(
+ route_id_,
+ identifier_,
+ text_,
+ *check_results));
+ destination_->Release();
+
+ // Object is self-managed - at this point, its life span is over.
+ // No need to delete, since the OnCheckCompleted callback owns |this|.
+}
SpellCheckMessageFilterPlatform::SpellCheckMessageFilterPlatform(
int render_process_id)
@@ -18,17 +120,34 @@ SpellCheckMessageFilterPlatform::SpellCheckMessageFilterPlatform(
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;
+ LOG(ERROR) << "DYLANKING OnMessageReceived";
+ IPC_BEGIN_MESSAGE_MAP(SpellCheckMessageFilterPlatform, message)
+ IPC_MESSAGE_HANDLER(SpellCheckHostMsg_CheckSpelling,
+ 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
void SpellCheckMessageFilterPlatform::CombineResults(
std::vector<SpellCheckResult>* remote_results,
const std::vector<SpellCheckResult>& local_results) {
+ LOG(ERROR) << "DYLANKING OnMessageReceived1";
}
SpellCheckMessageFilterPlatform::~SpellCheckMessageFilterPlatform() {}
@@ -37,18 +156,24 @@ void SpellCheckMessageFilterPlatform::OnCheckSpelling(
const base::string16& word,
int route_id,
bool* correct) {
+ *correct = spellcheck_platform::CheckSpelling(word, 0);
+ LOG(ERROR) << "DYLANKING OnCheckSpelling" << *correct;
}
void SpellCheckMessageFilterPlatform::OnFillSuggestionList(
const base::string16& word,
std::vector<base::string16>* suggestions) {
+ LOG(ERROR) << "DYLANKING OnMessageReceived2";
+ spellcheck_platform::FillSuggestionList(word, suggestions);
}
void SpellCheckMessageFilterPlatform::OnShowSpellingPanel(bool show) {
+ LOG(ERROR) << "DYLANKING OnMessageReceived3";
}
void SpellCheckMessageFilterPlatform::OnUpdateSpellingPanelWithMisspelledWord(
const base::string16& word) {
+ LOG(ERROR) << "DYLANKING OnMessageReceived4";
}
void SpellCheckMessageFilterPlatform::OnRequestTextCheck(
@@ -56,13 +181,28 @@ void SpellCheckMessageFilterPlatform::OnRequestTextCheck(
int identifier,
const base::string16& text,
std::vector<SpellCheckMarker> markers) {
+
+ /*if(!spellcheck_platform::SpellCheckerAvailable()){
+ return;
+ }*/
+
+ DCHECK(!text.empty());
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+
+ SpellingRequest* request =
+ new SpellingRequest(this, render_process_id_);
+ request->RequestCheck(
+ text, route_id, identifier);
+ LOG(ERROR) << "DYLANKING OnMessageReceived5 ";
}
int SpellCheckMessageFilterPlatform::ToDocumentTag(int route_id) {
- NOTREACHED();
- return -1;
+ LOG(ERROR) << "DYLANKING OnMessageReceived6";
+ NOTREACHED();
+ return -1;
}
void SpellCheckMessageFilterPlatform::RetireDocumentTag(int route_id) {
- NOTREACHED();
+ LOG(ERROR) << "DYLANKING OnMessageReceived7";
+ NOTREACHED();
}
« no previous file with comments | « chrome/browser/spellchecker/spellcheck_message_filter_platform.h ('k') | chrome/browser/spellchecker/spellcheck_platform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698