diff options
author | rouslan@chromium.org <rouslan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-20 08:26:46 +0000 |
---|---|---|
committer | rouslan@chromium.org <rouslan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-20 08:26:46 +0000 |
commit | 6cc4a844cc9caaf721728ba0097cff61bbf7fbeb (patch) | |
tree | e9cba89d5d28430f45e8053a274635006503386a /chrome/browser/spellchecker/spellcheck_service.cc | |
parent | 9687e5ef4025dca16d787afdef2bbda6c07e2272 (diff) | |
download | chromium_src-6cc4a844cc9caaf721728ba0097cff61bbf7fbeb.zip chromium_src-6cc4a844cc9caaf721728ba0097cff61bbf7fbeb.tar.gz chromium_src-6cc4a844cc9caaf721728ba0097cff61bbf7fbeb.tar.bz2 |
Enable users to alter their custom dictionary from an overlay on chrome://settings/editDictionary. This overlay can also be accessed through:
Settings
|_Show advanced settings...
..|_Language and spell-checker settings...
....|_Custom spelling dictionary
When a user types an unknown word into a textarea, the browser underlines this word as a misspelling. The user can right-click on this word and select "Add to Dictionary". If the user made a mistake, the user needs a way to remove a word from their custom dictionary. This CL provides this functionality.
Automated tests are in https://codereview.chromium.org/11280013/ and https://codereview.chromium.org/11308076/.
BUG=18238
Review URL: https://chromiumcodereview.appspot.com/11362063
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168760 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/spellchecker/spellcheck_service.cc')
-rw-r--r-- | chrome/browser/spellchecker/spellcheck_service.cc | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/chrome/browser/spellchecker/spellcheck_service.cc b/chrome/browser/spellchecker/spellcheck_service.cc index f0f76d1..62af03f 100644 --- a/chrome/browser/spellchecker/spellcheck_service.cc +++ b/chrome/browser/spellchecker/spellcheck_service.cc @@ -50,6 +50,7 @@ SpellcheckService::SpellcheckService(Profile* profile) hunspell_dictionary_->Load(); custom_dictionary_.reset(new SpellcheckCustomDictionary(profile_)); + custom_dictionary_->AddObserver(this); custom_dictionary_->Load(); registrar_.Add(weak_ptr_factory_.GetWeakPtr(), @@ -130,27 +131,22 @@ bool SpellcheckService::SignalStatusEvent( return true; } -// static -void SpellcheckService::AttachStatusEvent(base::WaitableEvent* status_event) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - g_status_event = status_event; -} - -// static -SpellcheckService::EventType SpellcheckService::WaitStatusEvent() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - if (g_status_event) - g_status_event->Wait(); - return g_status_type; -} - void SpellcheckService::StartRecordingMetrics(bool spellcheck_enabled) { metrics_.reset(new SpellCheckHostMetrics()); metrics_->RecordEnabledStats(spellcheck_enabled); } +void SpellcheckService::InitForAllRenderers() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + for (content::RenderProcessHost::iterator i( + content::RenderProcessHost::AllHostsIterator()); + !i.IsAtEnd(); i.Advance()) { + content::RenderProcessHost* process = i.GetCurrentValue(); + if (process) + InitForRenderer(process); + } +} + void SpellcheckService::InitForRenderer(content::RenderProcessHost* process) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -178,15 +174,21 @@ void SpellcheckService::InitForRenderer(content::RenderProcessHost* process) { #endif } - WordList custom_words = GetCustomDictionary()->GetCustomWords(); - process->Send(new SpellCheckMsg_Init( file, - custom_words, + custom_dictionary_->GetWords(), hunspell_dictionary_->GetLanguage(), prefs->GetBoolean(prefs::kEnableAutoSpellCorrect))); } +SpellCheckHostMetrics* SpellcheckService::GetMetrics() const { + return metrics_.get(); +} + +SpellcheckCustomDictionary* SpellcheckService::GetCustomDictionary() { + return custom_dictionary_.get(); +} + void SpellcheckService::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { @@ -201,7 +203,7 @@ void SpellcheckService::OnPreferenceChanged(PrefServiceBase* prefs, DCHECK(prefs); if (pref_name_in == prefs::kSpellCheckDictionary || pref_name_in == prefs::kEnableSpellCheck) { - InformProfileOfInitializationWithCustomWords(NULL); + InitForAllRenderers(); } else if (pref_name_in == prefs::kEnableAutoSpellCorrect) { bool enabled = prefs->GetBoolean(prefs::kEnableAutoSpellCorrect); for (content::RenderProcessHost::iterator i( @@ -213,28 +215,28 @@ void SpellcheckService::OnPreferenceChanged(PrefServiceBase* prefs, } } -SpellCheckHostMetrics* SpellcheckService::GetMetrics() const { - return metrics_.get(); +void SpellcheckService::OnCustomDictionaryLoaded() { + InitForAllRenderers(); } -SpellcheckCustomDictionary* SpellcheckService::GetCustomDictionary() { - return custom_dictionary_.get(); +void SpellcheckService::OnCustomDictionaryWordAdded(const std::string& word) { +} + +void SpellcheckService::OnCustomDictionaryWordRemoved(const std::string& word) { } -// TODO(rlp): rename to something more logical. -void SpellcheckService::InformProfileOfInitializationWithCustomWords( - WordList* custom_words) { +// static +void SpellcheckService::AttachStatusEvent(base::WaitableEvent* status_event) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (custom_words) { - GetCustomDictionary()->SetCustomWordList(custom_words); - } + g_status_event = status_event; +} - for (content::RenderProcessHost::iterator i( - content::RenderProcessHost::AllHostsIterator()); - !i.IsAtEnd(); i.Advance()) { - content::RenderProcessHost* process = i.GetCurrentValue(); - if (process) - InitForRenderer(process); - } +// static +SpellcheckService::EventType SpellcheckService::WaitStatusEvent() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + if (g_status_event) + g_status_event->Wait(); + return g_status_type; } |