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

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: Implemented Android spellchecker red underlining 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..bc295c2cc0edc3ff245ffbeb7ab5e3a9603ccd49 100644
--- a/chrome/browser/spellchecker/spellcheck_message_filter_platform_android.cc
+++ b/chrome/browser/spellchecker/spellcheck_message_filter_platform_android.cc
@@ -4,31 +4,156 @@
#include "chrome/browser/spellchecker/spellcheck_message_filter_platform.h"
+#include <algorithm>
+
+#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"
using content::BrowserThread;
+namespace{
+
+ bool CompareLocation(const SpellCheckResult& r1,
+ const SpellCheckResult& r2) {
+ return r1.location < r2.location;
+ }
+
+} // namespace
+
+class SpellingRequest {
+ public:
+ SpellingRequest(content::BrowserMessageFilter* destination,
+ int render_process_id);
+
+ void RequestCheck(const base::string16& text,
+ int route_id,
+ int identifier);
+ private:
+
+ // Request a check for |text_| from local spell checker.
+ void RequestLocalCheck();
+
+ // Check if all pending requests are done, send reply to render process if so.
+ void OnCheckCompleted();
+
+ // Called when local checking is complete.
+ void OnLocalCheckCompleted(const std::vector<SpellCheckResult>& results);
+
+ std::vector<SpellCheckResult> local_results_;
+
+ // Barrier closure for completion of both remote and local check.
+ base::Closure completion_barrier_;
+
+ content::BrowserMessageFilter* destination_; // ref-counted.
+ int render_process_id_;
+
+ base::string16 text_;
+ int route_id_;
+ int identifier_;
+};
+
+SpellingRequest::SpellingRequest(content::BrowserMessageFilter* destination,
+ int render_process_id)
+ : destination_(destination),
+ render_process_id_(render_process_id),
+ route_id_(-1),
+ identifier_(-1) {
+ destination_->AddRef();
+}
+
+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() {
+ spellcheck_platform::RequestTextCheck(
+ 0,
+ text_,
+ base::Bind(&SpellingRequest::OnLocalCheckCompleted,
+ base::Unretained(this)));
+}
+
+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|.
+}
+
+void SpellingRequest::OnLocalCheckCompleted(
+ const std::vector<SpellCheckResult>& results) {
+ // Local checking can happen on any thread - don't DCHECK thread.
+ local_results_ = results;
+ completion_barrier_.Run();
+}
+
SpellCheckMessageFilterPlatform::SpellCheckMessageFilterPlatform(
int render_process_id)
: BrowserMessageFilter(SpellCheckMsgStart),
render_process_id_(render_process_id) {
+ spellcheck_platform::InitializeJNIBridge();
}
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 +162,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 +187,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();
}

Powered by Google App Engine
This is Rietveld 408576698