Index: chrome/renderer/spellchecker/spellcheck.cc |
diff --git a/chrome/renderer/spellchecker/spellcheck.cc b/chrome/renderer/spellchecker/spellcheck.cc |
index 4daac84fbd54b287e721460504a5b71d44a71485..ea5b40f0a5cf84adb938aed48c129a283ef432c1 100644 |
--- a/chrome/renderer/spellchecker/spellcheck.cc |
+++ b/chrome/renderer/spellchecker/spellcheck.cc |
@@ -12,7 +12,10 @@ |
#include "chrome/common/spellcheck_messages.h" |
#include "chrome/common/spellcheck_result.h" |
#include "chrome/renderer/spellchecker/hunspell_engine.h" |
+#include "chrome/renderer/spellchecker/spellcheck_provider.h" |
#include "chrome/renderer/spellchecker/spelling_engine.h" |
+#include "content/public/renderer/render_view.h" |
+#include "content/public/renderer/render_view_visitor.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingCompletion.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult.h" |
@@ -21,6 +24,24 @@ using WebKit::WebVector; |
using WebKit::WebTextCheckingResult; |
using WebKit::WebTextCheckingType; |
+class UpdateSpellcheckEnabled : public content::RenderViewVisitor { |
brettw
2012/12/11 18:38:58
IS it possible to put this in an anon. namespace?
groby-ooo-7-16
2012/12/11 20:19:55
Done.
|
+ public: |
+ explicit UpdateSpellcheckEnabled(bool enabled) : enabled_(enabled) {} |
+ virtual bool Visit(content::RenderView* render_view) OVERRIDE; |
+ |
+ private: |
+ bool enabled_; // New spellcheck-enabled state. |
+ DISALLOW_COPY_AND_ASSIGN(UpdateSpellcheckEnabled); |
+}; |
+ |
+bool UpdateSpellcheckEnabled::Visit(content::RenderView* render_view) { |
+ SpellCheckProvider* provider = SpellCheckProvider::Get(render_view); |
+ DCHECK(provider); |
+ provider->EnableSpellCheck(enabled_); |
+ return true; |
+} |
+ |
+ |
class SpellCheck::SpellcheckRequest { |
public: |
SpellcheckRequest(const string16& text, |
@@ -45,7 +66,24 @@ class SpellCheck::SpellcheckRequest { |
DISALLOW_COPY_AND_ASSIGN(SpellcheckRequest); |
}; |
-SpellCheck::SpellCheck() : auto_spell_correct_turned_on_(false) { |
+ |
+// Initializes SpellCheck object. |
+// spellcheck_enabled_ currently MUST be set to true, due to peculiarities of |
+// the initialization sequence. |
+// Since it defaults to true, newly created SpellCheckProviders will enable |
+// spellchecking. After the first word is typed, the provider requests a check, |
+// which in turn triggers the delayed initialization sequence in SpellCheck. |
+// This does send a message to the browser side, which triggers the creation |
+// of the SpellcheckService. That does create the observer for the preference |
+// responsible for enabling/disabling checking, which allows subsequent changes |
+// to that preference to be sent to all SpellCheckProviders. |
+// Setting |spellcheck_enabled_| to false by default prevents that mechanism, |
+// and as such the SpellCheckProviders will never be notified of different |
+// values. |
+// TODO(groby): Simplify this. |
+SpellCheck::SpellCheck() |
+ : auto_spell_correct_turned_on_(false), |
+ spellcheck_enabled_(true) { |
platform_spelling_engine_.reset(CreateNativeSpellingEngine()); |
} |
@@ -60,6 +98,7 @@ bool SpellCheck::OnControlMessageReceived(const IPC::Message& message) { |
IPC_MESSAGE_HANDLER(SpellCheckMsg_WordRemoved, OnWordRemoved) |
IPC_MESSAGE_HANDLER(SpellCheckMsg_EnableAutoSpellCorrect, |
OnEnableAutoSpellCorrect) |
+ IPC_MESSAGE_HANDLER(SpellCheckMsg_EnableSpellCheck, OnEnableSpellCheck) |
IPC_MESSAGE_UNHANDLED(handled = false) |
IPC_END_MESSAGE_MAP() |
@@ -92,6 +131,12 @@ void SpellCheck::OnEnableAutoSpellCorrect(bool enable) { |
auto_spell_correct_turned_on_ = enable; |
} |
+void SpellCheck::OnEnableSpellCheck(bool enable) { |
+ spellcheck_enabled_ = enable; |
+ UpdateSpellcheckEnabled updater(enable); |
+ content::RenderView::ForEach(&updater); |
+} |
+ |
// TODO(groby): Make sure we always have a spelling engine, even before Init() |
// is called. |
void SpellCheck::Init(base::PlatformFile file, |