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

Unified Diff: chrome/browser/spellcheck_host_impl.cc

Issue 6880320: Move code that talks to spellchecking out of content. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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
« no previous file with comments | « chrome/browser/spellcheck_host_impl.h ('k') | chrome/browser/spellcheck_message_filter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/spellcheck_host_impl.cc
===================================================================
--- chrome/browser/spellcheck_host_impl.cc (revision 83517)
+++ chrome/browser/spellcheck_host_impl.cc (working copy)
@@ -12,11 +12,16 @@
#include "base/string_split.h"
#include "base/threading/thread_restrictions.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/spellcheck_host_observer.h"
#include "chrome/browser/spellchecker_platform_engine.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
+#include "chrome/common/pref_names.h"
#include "chrome/common/spellcheck_common.h"
+#include "chrome/common/spellcheck_messages.h"
+#include "content/browser/renderer_host/render_process_host.h"
#include "content/common/notification_service.h"
#include "googleurl/src/gurl.h"
#include "net/url_request/url_request_context_getter.h"
@@ -90,6 +95,9 @@
PathService::Get(chrome::DIR_USER_DATA, &personal_file_directory);
custom_dictionary_file_ =
personal_file_directory.Append(chrome::kCustomDictionaryFileName);
+
+ registrar_.Add(this, NotificationType::RENDERER_PROCESS_CREATED,
+ NotificationService::AllSources());
}
SpellCheckHostImpl::~SpellCheckHostImpl() {
@@ -126,8 +134,36 @@
observer_ = NULL;
request_context_getter_ = NULL;
fetcher_.reset();
+ registrar_.RemoveAll();
}
+void SpellCheckHostImpl::InitForRenderer(RenderProcessHost* process) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ PrefService* prefs = process->profile()->GetPrefs();
+ IPC::PlatformFileForTransit file;
+
+ if (GetDictionaryFile() != base::kInvalidPlatformFileValue) {
+#if defined(OS_POSIX)
+ file = base::FileDescriptor(GetDictionaryFile(), false);
+#elif defined(OS_WIN)
+ ::DuplicateHandle(::GetCurrentProcess(),
+ GetDictionaryFile(),
+ process->GetHandle(),
+ &file,
+ 0,
+ false,
+ DUPLICATE_SAME_ACCESS);
+#endif
+ }
+
+ process->Send(new SpellCheckMsg_Init(
+ file,
+ GetCustomWords(),
+ GetLanguage(),
+ prefs->GetBoolean(prefs::kEnableAutoSpellCorrect)));
+}
+
void SpellCheckHostImpl::AddWord(const std::string& word) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -135,9 +171,11 @@
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
NewRunnableMethod(this,
&SpellCheckHostImpl::WriteWordToCustomDictionary, word));
- NotificationService::current()->Notify(
- NotificationType::SPELLCHECK_WORD_ADDED,
- Source<SpellCheckHost>(this), NotificationService::NoDetails());
+
+ for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
+ !i.IsAtEnd(); i.Advance()) {
+ i.GetCurrentValue()->Send(new SpellCheckMsg_WordAdded(GetLastAddedFile()));
+ }
}
void SpellCheckHostImpl::InitializeDictionaryLocation() {
@@ -211,6 +249,11 @@
if (observer_)
observer_->SpellCheckHostInitialized();
+
+ for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
+ !i.IsAtEnd(); i.Advance()) {
+ InitForRenderer(i.GetCurrentValue());
+ }
}
void SpellCheckHostImpl::DownloadDictionary() {
@@ -281,6 +324,14 @@
NewRunnableMethod(this, &SpellCheckHostImpl::SaveDictionaryData));
}
+void SpellCheckHostImpl::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ DCHECK(type == NotificationType::RENDERER_PROCESS_CREATED);
+ RenderProcessHost* process = Source<RenderProcessHost>(source).ptr();
+ InitForRenderer(process);
+}
+
void SpellCheckHostImpl::SaveDictionaryData() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
« no previous file with comments | « chrome/browser/spellcheck_host_impl.h ('k') | chrome/browser/spellcheck_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698