summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/renderer/chrome_content_renderer_client.cc15
-rw-r--r--chrome/renderer/chrome_content_renderer_client.h4
-rw-r--r--chrome/renderer/spellchecker/cocoa_spelling_engine_mac.cc5
-rw-r--r--chrome/renderer/spellchecker/cocoa_spelling_engine_mac.h2
-rw-r--r--chrome/renderer/spellchecker/hunspell_engine.h4
-rw-r--r--chrome/renderer/spellchecker/spellcheck.cc29
-rw-r--r--chrome/renderer/spellchecker/spellcheck.h7
-rw-r--r--chrome/renderer/spellchecker/spellcheck_provider.cc87
-rw-r--r--chrome/renderer/spellchecker/spellcheck_provider_test.cc9
-rw-r--r--chrome/renderer/spellchecker/spellcheck_unittest.cc20
-rw-r--r--chrome/renderer/spellchecker/spelling_engine.h5
-rw-r--r--chrome/test/base/chrome_render_view_test.cc2
12 files changed, 95 insertions, 94 deletions
diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc
index 682e351..825c45e 100644
--- a/chrome/renderer/chrome_content_renderer_client.cc
+++ b/chrome/renderer/chrome_content_renderer_client.cc
@@ -979,20 +979,15 @@ bool ChromeContentRendererClient::CrossesExtensionExtents(
should_consider_workaround);
}
-void ChromeContentRendererClient::SetSpellcheck(SpellCheck* spellcheck) {
+void ChromeContentRendererClient::OnPurgeMemory() {
+ DVLOG(1) << "Resetting spellcheck in renderer client";
RenderThread* thread = RenderThread::Get();
- if (spellcheck_.get() && thread)
+ if (spellcheck_.get())
thread->RemoveObserver(spellcheck_.get());
- spellcheck_.reset(spellcheck);
+ spellcheck_.reset(new SpellCheck());
SpellCheckReplacer replacer(spellcheck_.get());
content::RenderView::ForEach(&replacer);
- if (thread)
- thread->AddObserver(spellcheck_.get());
-}
-
-void ChromeContentRendererClient::OnPurgeMemory() {
- DVLOG(1) << "Resetting spellcheck in renderer client";
- SetSpellcheck(new SpellCheck());
+ thread->AddObserver(spellcheck_.get());
}
bool ChromeContentRendererClient::IsAdblockInstalled() {
diff --git a/chrome/renderer/chrome_content_renderer_client.h b/chrome/renderer/chrome_content_renderer_client.h
index 9f5da32..bf34928 100644
--- a/chrome/renderer/chrome_content_renderer_client.h
+++ b/chrome/renderer/chrome_content_renderer_client.h
@@ -130,10 +130,6 @@ class ChromeContentRendererClient : public content::ContentRendererClient {
// For testing.
void SetExtensionDispatcher(extensions::Dispatcher* extension_dispatcher);
- // Sets a new |spellcheck|. Used for low-mem restart and testing only.
- // Takes ownership of |spellcheck|.
- void SetSpellcheck(SpellCheck* spellcheck);
-
// Called in low-memory conditions to dump the memory used by the spellchecker
// and start over.
void OnPurgeMemory();
diff --git a/chrome/renderer/spellchecker/cocoa_spelling_engine_mac.cc b/chrome/renderer/spellchecker/cocoa_spelling_engine_mac.cc
index 8030768..9c3ba9d 100644
--- a/chrome/renderer/spellchecker/cocoa_spelling_engine_mac.cc
+++ b/chrome/renderer/spellchecker/cocoa_spelling_engine_mac.cc
@@ -13,11 +13,6 @@ SpellingEngine* CreateNativeSpellingEngine() {
return new CocoaSpellingEngine();
}
-void CocoaSpellingEngine::Init(base::PlatformFile bdict_file,
- const std::vector<std::string>&) {
- DCHECK(bdict_file == base::kInvalidPlatformFileValue);
-}
-
bool CocoaSpellingEngine::InitializeIfNeeded() {
return false; // We never need to initialize.
}
diff --git a/chrome/renderer/spellchecker/cocoa_spelling_engine_mac.h b/chrome/renderer/spellchecker/cocoa_spelling_engine_mac.h
index f150648..1b5183b 100644
--- a/chrome/renderer/spellchecker/cocoa_spelling_engine_mac.h
+++ b/chrome/renderer/spellchecker/cocoa_spelling_engine_mac.h
@@ -10,8 +10,6 @@
class CocoaSpellingEngine : public SpellingEngine {
public:
- virtual void Init(base::PlatformFile bdict_file,
- const std::vector<std::string>& custom_words) OVERRIDE;
virtual bool InitializeIfNeeded() OVERRIDE;
virtual bool IsEnabled() OVERRIDE;
virtual bool CheckSpelling(const string16& word_to_check, int tag) OVERRIDE;
diff --git a/chrome/renderer/spellchecker/hunspell_engine.h b/chrome/renderer/spellchecker/hunspell_engine.h
index 6dd7581..0d91b24 100644
--- a/chrome/renderer/spellchecker/hunspell_engine.h
+++ b/chrome/renderer/spellchecker/hunspell_engine.h
@@ -21,8 +21,8 @@ class HunspellEngine : public SpellingEngine {
HunspellEngine();
virtual ~HunspellEngine();
- virtual void Init(base::PlatformFile file,
- const std::vector<std::string>& custom_words) OVERRIDE;
+ void Init(base::PlatformFile file,
+ const std::vector<std::string>& custom_words);
virtual bool InitializeIfNeeded() OVERRIDE;
virtual bool IsEnabled() OVERRIDE;
diff --git a/chrome/renderer/spellchecker/spellcheck.cc b/chrome/renderer/spellchecker/spellcheck.cc
index c470ac1..d289548 100644
--- a/chrome/renderer/spellchecker/spellcheck.cc
+++ b/chrome/renderer/spellchecker/spellcheck.cc
@@ -46,7 +46,6 @@ class SpellCheck::SpellcheckRequest {
};
SpellCheck::SpellCheck() : auto_spell_correct_turned_on_(false) {
- platform_spelling_engine_.reset(CreateNativeSpellingEngine());
}
SpellCheck::~SpellCheck() {
@@ -91,8 +90,19 @@ void SpellCheck::OnEnableAutoSpellCorrect(bool enable) {
void SpellCheck::Init(base::PlatformFile file,
const std::vector<std::string>& custom_words,
const std::string& language) {
- platform_spelling_engine_->Init(file, custom_words);
-
+ bool use_platform_spelling_engine =
+ file == base::kInvalidPlatformFileValue && !language.empty();
+
+ // Some tests under OSX still exercise hunspell. Only init native engine
+ // when no dictionary was specified.
+ // TODO(groby): Figure out if we can kill the hunspell dependency for OSX.
+ if (use_platform_spelling_engine) {
+ platform_spelling_engine_.reset(CreateNativeSpellingEngine());
+ } else {
+ HunspellEngine* engine = new HunspellEngine;
+ engine->Init(file, custom_words);
+ platform_spelling_engine_.reset(engine);
+ }
character_attributes_.SetDefaultLanguage(language);
text_iterator_.Reset();
contraction_iterator_.Reset();
@@ -271,8 +281,13 @@ void SpellCheck::RequestTextChecking(
}
#endif
+
bool SpellCheck::InitializeIfNeeded() {
- DCHECK(platform_spelling_engine_.get());
+ // TODO(groby): OSX creates a hunspell engine here, too. That seems
+ // wrong, but is (AFAICT) the existing flow. Fix that.
+ if (!platform_spelling_engine_.get())
+ platform_spelling_engine_.reset(new HunspellEngine);
+
return platform_spelling_engine_->InitializeIfNeeded();
}
@@ -344,8 +359,8 @@ bool SpellCheck::IsValidContraction(const string16& contraction, int tag) {
return true;
}
+#if !defined(OS_MACOSX)
void SpellCheck::CreateTextCheckingResults(
- ResultFilter filter,
int line_offset,
const string16& line_text,
const std::vector<SpellCheckResult>& spellcheck_results,
@@ -360,8 +375,7 @@ void SpellCheck::CreateTextCheckingResults(
static_cast<WebTextCheckingType>(spellcheck_results[i].type);
int word_location = spellcheck_results[i].location;
int word_length = spellcheck_results[i].length;
- if (type == WebKit::WebTextCheckingTypeSpelling &&
- filter == USE_NATIVE_CHECKER) {
+ if (type == WebKit::WebTextCheckingTypeSpelling) {
int misspelling_start = 0;
int misspelling_length = 0;
if (SpellCheckWord(text + word_location, word_length, 0,
@@ -376,3 +390,4 @@ void SpellCheck::CreateTextCheckingResults(
}
textcheck_results->swap(list);
}
+#endif
diff --git a/chrome/renderer/spellchecker/spellcheck.h b/chrome/renderer/spellchecker/spellcheck.h
index 05356bf..6292005 100644
--- a/chrome/renderer/spellchecker/spellcheck.h
+++ b/chrome/renderer/spellchecker/spellcheck.h
@@ -37,11 +37,6 @@ struct WebTextCheckingResult;
class SpellCheck : public content::RenderProcessObserver,
public base::SupportsWeakPtr<SpellCheck> {
public:
- enum ResultFilter {
- DO_NOT_MODIFY = 1, // Do not modify results.
- USE_NATIVE_CHECKER, // Use native checker to double-check.
- };
-
SpellCheck();
virtual ~SpellCheck();
@@ -94,14 +89,12 @@ class SpellCheck : public content::RenderProcessObserver,
// checks misspelled words returned by the Spelling service and changes the
// underline colors of contextually-misspelled words.
void CreateTextCheckingResults(
- ResultFilter filter,
int line_offset,
const string16& line_text,
const std::vector<SpellCheckResult>& spellcheck_results,
WebKit::WebVector<WebKit::WebTextCheckingResult>* textcheck_results);
private:
- friend class SpellCheckTest;
FRIEND_TEST_ALL_PREFIXES(SpellCheckTest, GetAutoCorrectionWord_EN_US);
FRIEND_TEST_ALL_PREFIXES(SpellCheckTest,
RequestSpellCheckMultipleTimesWithoutInitialization);
diff --git a/chrome/renderer/spellchecker/spellcheck_provider.cc b/chrome/renderer/spellchecker/spellcheck_provider.cc
index c71e415a..9f643b4 100644
--- a/chrome/renderer/spellchecker/spellcheck_provider.cc
+++ b/chrome/renderer/spellchecker/spellcheck_provider.cc
@@ -41,6 +41,28 @@ COMPILE_ASSERT(int(WebKit::WebTextCheckingTypeCorrection) ==
COMPILE_ASSERT(int(WebKit::WebTextCheckingTypeShowCorrectionPanel) ==
int(SpellCheckResult::SHOWCORRECTIONPANEL), mismatching_enums);
+namespace {
+
+// Converts a vector of SpellCheckResult objects (used by Chrome) to a vector of
+// WebTextCheckingResult objects (used by WebKit).
+void CreateTextCheckingResults(
+ int offset,
+ const std::vector<SpellCheckResult>& spellcheck_results,
+ WebKit::WebVector<WebKit::WebTextCheckingResult>* textcheck_results) {
+ size_t result_size = spellcheck_results.size();
+ WebKit::WebVector<WebKit::WebTextCheckingResult> list(result_size);
+ for (size_t i = 0; i < result_size; ++i) {
+ list[i] = WebTextCheckingResult(
+ static_cast<WebTextCheckingType>(spellcheck_results[i].type),
+ spellcheck_results[i].location + offset,
+ spellcheck_results[i].length,
+ spellcheck_results[i].replacement);
+ }
+ textcheck_results->swap(list);
+}
+
+} // namespace
+
SpellCheckProvider::SpellCheckProvider(
content::RenderView* render_view,
SpellCheck* spellcheck)
@@ -48,14 +70,14 @@ SpellCheckProvider::SpellCheckProvider(
content::RenderViewObserverTracker<SpellCheckProvider>(render_view),
spelling_panel_visible_(false),
spellcheck_(spellcheck) {
- DCHECK(spellcheck_);
if (render_view) // NULL in unit tests.
render_view->GetWebView()->setSpellCheckClient(this);
}
SpellCheckProvider::~SpellCheckProvider() {
#if defined(OS_MACOSX)
- Send(new SpellCheckHostMsg_DocumentClosed(routing_id(), routing_id()));
+ Send(new SpellCheckHostMsg_DocumentClosed(
+ routing_id(), routing_id()));
#endif
}
@@ -89,6 +111,7 @@ void SpellCheckProvider::RequestTextChecking(
last_request_.clear();
last_results_.assign(WebKit::WebVector<WebKit::WebTextCheckingResult>());
+
Send(new SpellCheckHostMsg_CallSpellingService(
routing_id(),
text_check_completions_.Add(completion),
@@ -140,16 +163,19 @@ void SpellCheckProvider::spellCheck(
int& length,
WebVector<WebString>* optional_suggestions) {
string16 word(text);
- std::vector<string16> suggestions;
- spellcheck_->SpellCheckWord(
- word.c_str(), word.size(), routing_id(),
- &offset, &length, optional_suggestions ? & suggestions : NULL);
- if (optional_suggestions)
- *optional_suggestions = suggestions;
- if (!optional_suggestions) {
- // If optional_suggestions is not requested, the API is called
- // for marking. So we use this for counting markable words.
- Send(new SpellCheckHostMsg_NotifyChecked(routing_id(), word, 0 < length));
+ // Will be NULL during unit tests.
+ if (spellcheck_) {
+ std::vector<string16> suggestions;
+ spellcheck_->SpellCheckWord(
+ word.c_str(), word.size(), routing_id(),
+ &offset, &length, optional_suggestions ? & suggestions : NULL);
+ if (optional_suggestions)
+ *optional_suggestions = suggestions;
+ if (!optional_suggestions) {
+ // If optional_suggestions is not requested, the API is called
+ // for marking. So we use this for counting markable words.
+ Send(new SpellCheckHostMsg_NotifyChecked(routing_id(), word, 0 < length));
+ }
}
}
@@ -166,6 +192,10 @@ void SpellCheckProvider::checkTextOfParagraph(
if (!(mask & WebKit::WebTextCheckingTypeSpelling))
return;
+ // Will be NULL during unit tets.
+ if (!spellcheck_)
+ return;
+
spellcheck_->SpellCheckParagraph(string16(text), results);
#endif
}
@@ -178,8 +208,12 @@ void SpellCheckProvider::requestCheckingOfText(
WebString SpellCheckProvider::autoCorrectWord(const WebString& word) {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
- if (command_line.HasSwitch(switches::kEnableSpellingAutoCorrect))
- return spellcheck_->GetAutoCorrectionWord(word, routing_id());
+ if (command_line.HasSwitch(switches::kEnableSpellingAutoCorrect)) {
+ // Will be NULL during unit tests.
+ if (spellcheck_) {
+ return spellcheck_->GetAutoCorrectionWord(word, routing_id());
+ }
+ }
return string16();
}
@@ -216,18 +250,22 @@ void SpellCheckProvider::OnRespondSpellingService(
// If |succeeded| is false, we use local spellcheck as a fallback.
if (!succeeded) {
- spellcheck_->RequestTextChecking(line, offset, completion);
- return;
+ // |spellcheck_| may be NULL in unit tests.
+ if (spellcheck_) {
+ spellcheck_->RequestTextChecking(line, offset, completion);
+ return;
+ }
}
// Double-check the returned spellchecking results with our spellchecker to
// visualize the differences between ours and the on-line spellchecker.
WebKit::WebVector<WebKit::WebTextCheckingResult> textcheck_results;
- spellcheck_->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER,
- offset,
- line,
- results,
- &textcheck_results);
+ if (spellcheck_) {
+ spellcheck_->CreateTextCheckingResults(
+ offset, line, results, &textcheck_results);
+ } else {
+ CreateTextCheckingResults(offset, results, &textcheck_results);
+ }
completion->didFinishCheckingText(textcheck_results);
// Cache the request and the converted results.
@@ -262,18 +300,13 @@ void SpellCheckProvider::OnAdvanceToNextMisspelling() {
void SpellCheckProvider::OnRespondTextCheck(
int identifier,
const std::vector<SpellCheckResult>& results) {
- DCHECK(spellcheck_);
WebTextCheckingCompletion* completion =
text_check_completions_.Lookup(identifier);
if (!completion)
return;
text_check_completions_.Remove(identifier);
WebKit::WebVector<WebKit::WebTextCheckingResult> textcheck_results;
- spellcheck_->CreateTextCheckingResults(SpellCheck::DO_NOT_MODIFY,
- 0,
- string16(),
- results,
- &textcheck_results);
+ CreateTextCheckingResults(0, results, &textcheck_results);
completion->didFinishCheckingText(textcheck_results);
}
diff --git a/chrome/renderer/spellchecker/spellcheck_provider_test.cc b/chrome/renderer/spellchecker/spellcheck_provider_test.cc
index 22bd6a2..0762899 100644
--- a/chrome/renderer/spellchecker/spellcheck_provider_test.cc
+++ b/chrome/renderer/spellchecker/spellcheck_provider_test.cc
@@ -6,12 +6,8 @@
#include "base/stl_util.h"
#include "chrome/common/spellcheck_messages.h"
-#include "chrome/renderer/spellchecker/spellcheck.h"
#include "ipc/ipc_message_macros.h"
-class MockSpellcheck: public SpellCheck {
-};
-
FakeTextCheckingCompletion::FakeTextCheckingCompletion()
: completion_count_(0),
cancellation_count_(0) {
@@ -31,13 +27,12 @@ void FakeTextCheckingCompletion::didCancelCheckingText() {
}
TestingSpellCheckProvider::TestingSpellCheckProvider()
- : SpellCheckProvider(NULL, new MockSpellcheck),
+ : SpellCheckProvider(NULL, NULL),
offset_(-1) {
}
TestingSpellCheckProvider::~TestingSpellCheckProvider() {
- STLDeleteContainerPointers(messages_.begin(), messages_.end());
- delete spellcheck_;
+ STLDeleteContainerPointers(messages_.begin(), messages_.end());
}
bool TestingSpellCheckProvider::Send(IPC::Message* message) {
diff --git a/chrome/renderer/spellchecker/spellcheck_unittest.cc b/chrome/renderer/spellchecker/spellcheck_unittest.cc
index 3b1609c..7f2c1b0 100644
--- a/chrome/renderer/spellchecker/spellcheck_unittest.cc
+++ b/chrome/renderer/spellchecker/spellcheck_unittest.cc
@@ -10,7 +10,6 @@
#include "base/platform_file.h"
#include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h"
-#include "chrome/renderer/spellchecker/hunspell_engine.h"
#include "chrome/renderer/spellchecker/spellcheck.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/spellcheck_common.h"
@@ -55,11 +54,6 @@ class SpellCheckTest : public testing::Test {
chrome::spellcheck_common::GetVersionedFileName(language,
hunspell_directory),
base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, NULL, NULL);
-#if defined(OS_MACOSX)
- // TODO(groby): Forcing spellcheck to use hunspell, even on OSX.
- // Instead, tests should exercise individual spelling engines.
- spell_check_->platform_spelling_engine_.reset(new HunspellEngine);
-#endif
spell_check_->Init(
file, std::vector<std::string>(), language);
}
@@ -1070,11 +1064,8 @@ TEST_F(SpellCheckTest, CreateTextCheckingResults) {
spellcheck_results.push_back(SpellCheckResult(
SpellCheckResult::SPELLING, 0, 2, string16()));
WebKit::WebVector<WebKit::WebTextCheckingResult> textcheck_results;
- spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER,
- 0,
- text,
- spellcheck_results,
- &textcheck_results);
+ spell_check()->CreateTextCheckingResults(
+ 0, text, spellcheck_results, &textcheck_results);
EXPECT_EQ(spellcheck_results.size(), textcheck_results.size());
EXPECT_EQ(WebKit::WebTextCheckingTypeSpelling, textcheck_results[0].type);
EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location);
@@ -1089,11 +1080,8 @@ TEST_F(SpellCheckTest, CreateTextCheckingResults) {
spellcheck_results.push_back(SpellCheckResult(
SpellCheckResult::SPELLING, 7, 4, string16()));
WebKit::WebVector<WebKit::WebTextCheckingResult> textcheck_results;
- spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER,
- 0,
- text,
- spellcheck_results,
- &textcheck_results);
+ spell_check()->CreateTextCheckingResults(
+ 0, text, spellcheck_results, &textcheck_results);
EXPECT_EQ(spellcheck_results.size(), textcheck_results.size());
EXPECT_EQ(WebKit::WebTextCheckingTypeGrammar, textcheck_results[0].type);
EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location);
diff --git a/chrome/renderer/spellchecker/spelling_engine.h b/chrome/renderer/spellchecker/spelling_engine.h
index af19a65..13d3b28 100644
--- a/chrome/renderer/spellchecker/spelling_engine.h
+++ b/chrome/renderer/spellchecker/spelling_engine.h
@@ -8,7 +8,6 @@
#include <string>
#include <vector>
-#include "base/platform_file.h"
#include "base/string16.h"
// Creates the platform's "native" spelling engine.
@@ -19,10 +18,6 @@ class SpellingEngine {
public:
virtual ~SpellingEngine() {}
- // Initialize spelling engine with browser-side info. Must be called before
- // any other functions are called.
- virtual void Init(base::PlatformFile bdict_file,
- const std::vector<std::string>& custom_words) = 0;
virtual bool InitializeIfNeeded() = 0;
virtual bool IsEnabled() = 0;
virtual bool CheckSpelling(const string16& word_to_check, int tag) = 0;
diff --git a/chrome/test/base/chrome_render_view_test.cc b/chrome/test/base/chrome_render_view_test.cc
index 9547e41..e9117be 100644
--- a/chrome/test/base/chrome_render_view_test.cc
+++ b/chrome/test/base/chrome_render_view_test.cc
@@ -15,7 +15,6 @@
#include "chrome/renderer/extensions/event_bindings.h"
#include "chrome/renderer/extensions/extension_custom_bindings.h"
#include "chrome/renderer/extensions/miscellaneous_bindings.h"
-#include "chrome/renderer/spellchecker/spellcheck.h"
#include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/common/renderer_preferences.h"
#include "content/public/renderer/render_view.h"
@@ -56,7 +55,6 @@ void ChromeRenderViewTest::SetUp() {
&chrome_content_renderer_client_);
extension_dispatcher_ = new extensions::Dispatcher();
chrome_content_renderer_client_.SetExtensionDispatcher(extension_dispatcher_);
- chrome_content_renderer_client_.SetSpellcheck(new SpellCheck());
chrome_render_thread_ = new ChromeMockRenderThread();
render_thread_.reset(chrome_render_thread_);