summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/spellchecker
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-14 18:17:08 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-14 18:17:08 +0000
commit8d97adeeabe5d28a50711423268168448bf56fd5 (patch)
tree9ef3250afc5c77c3425bb8c3789d7136cc99336b /chrome/renderer/spellchecker
parent9e611f644c8043f2cf957af5ed094b1280ee1459 (diff)
downloadchromium_src-8d97adeeabe5d28a50711423268168448bf56fd5.zip
chromium_src-8d97adeeabe5d28a50711423268168448bf56fd5.tar.gz
chromium_src-8d97adeeabe5d28a50711423268168448bf56fd5.tar.bz2
Move a bunch of Chrome specific code out of RenderThread, in preparation of moving it to content.
Review URL: http://codereview.chromium.org/6850003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81614 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/spellchecker')
-rw-r--r--chrome/renderer/spellchecker/spellcheck.cc60
-rw-r--r--chrome/renderer/spellchecker/spellcheck.h27
-rw-r--r--chrome/renderer/spellchecker/spellcheck_provider.cc19
-rw-r--r--chrome/renderer/spellchecker/spellcheck_provider.h7
-rw-r--r--chrome/renderer/spellchecker/spellcheck_unittest.cc6
5 files changed, 70 insertions, 49 deletions
diff --git a/chrome/renderer/spellchecker/spellcheck.cc b/chrome/renderer/spellchecker/spellcheck.cc
index 0ed18ce..ca14cbb 100644
--- a/chrome/renderer/spellchecker/spellcheck.cc
+++ b/chrome/renderer/spellchecker/spellcheck.cc
@@ -8,6 +8,7 @@
#include "base/metrics/histogram.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
+#include "chrome/common/render_messages.h"
#include "chrome/common/spellcheck_common.h"
#include "chrome/common/spellcheck_messages.h"
#include "chrome/renderer/render_thread.h"
@@ -26,6 +27,49 @@ SpellCheck::SpellCheck()
SpellCheck::~SpellCheck() {
}
+bool SpellCheck::OnControlMessageReceived(const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(SpellCheck, message)
+ IPC_MESSAGE_HANDLER(SpellCheckMsg_Init, OnInit)
+ IPC_MESSAGE_HANDLER(SpellCheckMsg_WordAdded, OnWordAdded)
+ IPC_MESSAGE_HANDLER(SpellCheckMsg_EnableAutoSpellCorrect,
+ OnEnableAutoSpellCorrect)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+
+ if (message.type() == ViewMsg_PurgeMemory::ID) {
+ delete this;
+ new SpellCheck();
+ }
+
+ return handled;
+}
+
+void SpellCheck::OnInit(IPC::PlatformFileForTransit bdict_file,
+ const std::vector<std::string>& custom_words,
+ const std::string& language,
+ bool auto_spell_correct) {
+ Init(IPC::PlatformFileForTransitToPlatformFile(bdict_file),
+ custom_words, language);
+ auto_spell_correct_turned_on_ = auto_spell_correct;
+}
+
+void SpellCheck::OnWordAdded(const std::string& word) {
+ if (is_using_platform_spelling_engine_)
+ return;
+
+ if (!hunspell_.get()) {
+ // Save it for later---add it when hunspell is initialized.
+ custom_words_.push_back(word);
+ } else {
+ AddWordToHunspell(word);
+ }
+}
+
+void SpellCheck::OnEnableAutoSpellCorrect(bool enable) {
+ auto_spell_correct_turned_on_ = enable;
+}
+
void SpellCheck::Init(base::PlatformFile file,
const std::vector<std::string>& custom_words,
const std::string& language) {
@@ -147,22 +191,6 @@ string16 SpellCheck::GetAutoCorrectionWord(const string16& word, int tag) {
return autocorrect_word;
}
-void SpellCheck::EnableAutoSpellCorrect(bool turn_on) {
- auto_spell_correct_turned_on_ = turn_on;
-}
-
-void SpellCheck::WordAdded(const std::string& word) {
- if (is_using_platform_spelling_engine_)
- return;
-
- if (!hunspell_.get()) {
- // Save it for later---add it when hunspell is initialized.
- custom_words_.push_back(word);
- } else {
- AddWordToHunspell(word);
- }
-}
-
void SpellCheck::InitializeHunspell() {
if (hunspell_.get())
return;
diff --git a/chrome/renderer/spellchecker/spellcheck.h b/chrome/renderer/spellchecker/spellcheck.h
index 29980b5..0af6ef8 100644
--- a/chrome/renderer/spellchecker/spellcheck.h
+++ b/chrome/renderer/spellchecker/spellcheck.h
@@ -9,11 +9,14 @@
#include <string>
#include <vector>
+#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/platform_file.h"
#include "base/string16.h"
#include "base/time.h"
#include "chrome/renderer/spellchecker/spellcheck_worditerator.h"
+#include "content/renderer/render_process_observer.h"
+#include "ipc/ipc_platform_file.h"
#include "unicode/uscript.h"
class Hunspell;
@@ -24,10 +27,9 @@ class MemoryMappedFile;
// TODO(morrita): Needs reorg with SpellCheckProvider.
// See http://crbug.com/73699.
-class SpellCheck {
+class SpellCheck : public RenderProcessObserver {
public:
SpellCheck();
-
~SpellCheck();
void Init(base::PlatformFile file,
@@ -59,14 +61,6 @@ class SpellCheck {
// behind its command line flag.
string16 GetAutoCorrectionWord(const string16& word, int tag);
- // Turn auto spell correct support ON or OFF.
- // |turn_on| = true means turn ON; false means turn OFF.
- void EnableAutoSpellCorrect(bool turn_on);
-
- // Add a word to the custom list. This may be called before or after
- // |hunspell_| has been initialized.
- void WordAdded(const std::string& word);
-
// Returns true if the spellchecker delegate checking to a system-provided
// checker on the browser process.
bool is_using_platform_spelling_engine() const {
@@ -74,6 +68,19 @@ class SpellCheck {
}
private:
+ FRIEND_TEST(SpellCheckTest, GetAutoCorrectionWord_EN_US);
+
+ // RenderProcessObserver implementation:
+ virtual bool OnControlMessageReceived(const IPC::Message& message);
+
+ // Message handlers.
+ void OnInit(IPC::PlatformFileForTransit bdict_file,
+ const std::vector<std::string>& custom_words,
+ const std::string& language,
+ bool auto_spell_correct);
+ void OnWordAdded(const std::string& word);
+ void OnEnableAutoSpellCorrect(bool enable);
+
// Initializes the Hunspell dictionary, or does nothing if |hunspell_| is
// non-null. This blocks.
void InitializeHunspell();
diff --git a/chrome/renderer/spellchecker/spellcheck_provider.cc b/chrome/renderer/spellchecker/spellcheck_provider.cc
index e0b262f..bb6edc9 100644
--- a/chrome/renderer/spellchecker/spellcheck_provider.cc
+++ b/chrome/renderer/spellchecker/spellcheck_provider.cc
@@ -7,7 +7,6 @@
#include "base/command_line.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/spellcheck_messages.h"
-#include "chrome/renderer/render_thread.h"
#include "chrome/renderer/spellchecker/spellcheck.h"
#include "content/renderer/render_view.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
@@ -31,6 +30,8 @@ SpellCheckProvider::SpellCheckProvider(RenderView* render_view,
document_tag_(0),
spelling_panel_visible_(false),
spellcheck_(spellcheck) {
+ if (render_view) // NULL in unit tests.
+ render_view->webview()->setSpellCheckClient(this);
}
SpellCheckProvider::~SpellCheckProvider() {
@@ -85,11 +86,10 @@ void SpellCheckProvider::spellCheck(
EnsureDocumentTag();
string16 word(text);
- RenderThread* thread = RenderThread::current();
// Will be NULL during unit tests.
- if (thread) {
+ if (spellcheck_) {
std::vector<string16> suggestions;
- thread->spellchecker()->SpellCheckWord(
+ spellcheck_->SpellCheckWord(
word.c_str(), word.size(), document_tag_,
&offset, &length, optional_suggestions ? & suggestions : NULL);
if (optional_suggestions)
@@ -97,12 +97,6 @@ void SpellCheckProvider::spellCheck(
}
}
-void SpellCheckProvider::spellCheck(const WebString& text,
- int& offset,
- int& length) {
- spellCheck(text, offset, length, NULL);
-}
-
void SpellCheckProvider::requestCheckingOfText(
const WebString& text,
WebTextCheckingCompletion* completion) {
@@ -113,10 +107,9 @@ WebString SpellCheckProvider::autoCorrectWord(const WebString& word) {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
EnsureDocumentTag();
- RenderThread* thread = RenderThread::current();
// Will be NULL during unit tests.
- if (thread)
- return thread->spellchecker()->GetAutoCorrectionWord(word, document_tag_);
+ if (spellcheck_)
+ return spellcheck_->GetAutoCorrectionWord(word, document_tag_);
}
return string16();
}
diff --git a/chrome/renderer/spellchecker/spellcheck_provider.h b/chrome/renderer/spellchecker/spellcheck_provider.h
index 0713d01..1e1f5a9 100644
--- a/chrome/renderer/spellchecker/spellcheck_provider.h
+++ b/chrome/renderer/spellchecker/spellcheck_provider.h
@@ -12,9 +12,6 @@
#include "content/renderer/render_view_observer.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSpellCheckClient.h"
-// TODO(jam): remove me once WEBSPELLCHECKCLIENT_HAS_SUGGESTIONS is rolled
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h"
-
class RenderView;
class SpellCheck;
@@ -62,10 +59,6 @@ class SpellCheckProvider : public RenderViewObserver,
int& offset,
int& length,
WebKit::WebVector<WebKit::WebString>* optional_suggestions);
- // TODO(jam): remove me once WEBSPELLCHECKCLIENT_HAS_SUGGESTIONS is rolled
- virtual void spellCheck(const WebKit::WebString& text,
- int& offset,
- int& length);
virtual void requestCheckingOfText(
const WebKit::WebString& text,
WebKit::WebTextCheckingCompletion* completion);
diff --git a/chrome/renderer/spellchecker/spellcheck_unittest.cc b/chrome/renderer/spellchecker/spellcheck_unittest.cc
index 75c24f2..9b31383 100644
--- a/chrome/renderer/spellchecker/spellcheck_unittest.cc
+++ b/chrome/renderer/spellchecker/spellcheck_unittest.cc
@@ -27,6 +27,8 @@ FilePath GetHunspellDirectory() {
return hunspell_directory;
}
+} // namespace
+
class SpellCheckTest : public testing::Test {
public:
SpellCheckTest() {
@@ -690,7 +692,7 @@ TEST_F(SpellCheckTest, GetAutoCorrectionWord_EN_US) {
{"noen", ""},
{"what", ""},
};
- spell_check()->EnableAutoSpellCorrect(true);
+ spell_check()->OnEnableAutoSpellCorrect(true);
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
string16 misspelled_word(UTF8ToUTF16(kTestCases[i].input));
@@ -703,5 +705,3 @@ TEST_F(SpellCheckTest, GetAutoCorrectionWord_EN_US) {
EXPECT_EQ(expected_autocorrect_word, autocorrect_word);
}
}
-
-} // namespace