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

Side by Side Diff: chrome/browser/renderer_host/browser_render_process_host.cc

Issue 395007: Move Mac to using renderer spellchecker. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: ui test fix Created 11 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Represents the browser side of the browser <--> renderer communication 5 // Represents the browser side of the browser <--> renderer communication
6 // channel. There will be one RenderProcessHost per renderer process. 6 // channel. There will be one RenderProcessHost per renderer process.
7 7
8 #include "chrome/browser/renderer_host/browser_render_process_host.h" 8 #include "chrome/browser/renderer_host/browser_render_process_host.h"
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 22 matching lines...) Expand all
33 #include "chrome/browser/net/url_request_context_getter.h" 33 #include "chrome/browser/net/url_request_context_getter.h"
34 #include "chrome/browser/plugin_service.h" 34 #include "chrome/browser/plugin_service.h"
35 #include "chrome/browser/profile.h" 35 #include "chrome/browser/profile.h"
36 #include "chrome/browser/renderer_host/audio_renderer_host.h" 36 #include "chrome/browser/renderer_host/audio_renderer_host.h"
37 #include "chrome/browser/renderer_host/render_view_host.h" 37 #include "chrome/browser/renderer_host/render_view_host.h"
38 #include "chrome/browser/renderer_host/render_view_host_delegate.h" 38 #include "chrome/browser/renderer_host/render_view_host_delegate.h"
39 #include "chrome/browser/renderer_host/render_widget_helper.h" 39 #include "chrome/browser/renderer_host/render_widget_helper.h"
40 #include "chrome/browser/renderer_host/render_widget_host.h" 40 #include "chrome/browser/renderer_host/render_widget_host.h"
41 #include "chrome/browser/renderer_host/resource_message_filter.h" 41 #include "chrome/browser/renderer_host/resource_message_filter.h"
42 #include "chrome/browser/renderer_host/web_cache_manager.h" 42 #include "chrome/browser/renderer_host/web_cache_manager.h"
43 #if defined(SPELLCHECKER_IN_RENDERER)
44 #include "chrome/browser/spellcheck_host.h" 43 #include "chrome/browser/spellcheck_host.h"
45 #endif
46 #include "chrome/browser/spellchecker.h"
47 #include "chrome/browser/visitedlink_master.h" 44 #include "chrome/browser/visitedlink_master.h"
48 #include "chrome/common/chrome_switches.h" 45 #include "chrome/common/chrome_switches.h"
49 #include "chrome/common/child_process_info.h" 46 #include "chrome/common/child_process_info.h"
50 #include "chrome/common/child_process_host.h" 47 #include "chrome/common/child_process_host.h"
51 #include "chrome/common/logging_chrome.h" 48 #include "chrome/common/logging_chrome.h"
52 #include "chrome/common/notification_service.h" 49 #include "chrome/common/notification_service.h"
50 #include "chrome/common/pref_names.h"
51 #include "chrome/common/process_watcher.h"
53 #include "chrome/common/render_messages.h" 52 #include "chrome/common/render_messages.h"
54 #include "chrome/common/result_codes.h" 53 #include "chrome/common/result_codes.h"
55 #include "chrome/renderer/render_process.h" 54 #include "chrome/renderer/render_process.h"
56 #include "chrome/renderer/render_thread.h" 55 #include "chrome/renderer/render_thread.h"
57 #include "grit/generated_resources.h" 56 #include "grit/generated_resources.h"
58 #include "ipc/ipc_logging.h" 57 #include "ipc/ipc_logging.h"
59 #include "ipc/ipc_message.h" 58 #include "ipc/ipc_message.h"
60 #include "ipc/ipc_platform_file.h" 59 #include "ipc/ipc_platform_file.h"
61 #include "ipc/ipc_switches.h" 60 #include "ipc/ipc_switches.h"
62 61
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 visible_widgets_(0), 191 visible_widgets_(0),
193 backgrounded_(true), 192 backgrounded_(true),
194 ALLOW_THIS_IN_INITIALIZER_LIST(cached_dibs_cleaner_( 193 ALLOW_THIS_IN_INITIALIZER_LIST(cached_dibs_cleaner_(
195 base::TimeDelta::FromSeconds(5), 194 base::TimeDelta::FromSeconds(5),
196 this, &BrowserRenderProcessHost::ClearTransportDIBCache)), 195 this, &BrowserRenderProcessHost::ClearTransportDIBCache)),
197 extension_process_(false) { 196 extension_process_(false) {
198 widget_helper_ = new RenderWidgetHelper(); 197 widget_helper_ = new RenderWidgetHelper();
199 198
200 registrar_.Add(this, NotificationType::USER_SCRIPTS_UPDATED, 199 registrar_.Add(this, NotificationType::USER_SCRIPTS_UPDATED,
201 NotificationService::AllSources()); 200 NotificationService::AllSources());
202 #if defined(SPELLCHECKER_IN_RENDERER)
203 registrar_.Add(this, NotificationType::SPELLCHECK_HOST_REINITIALIZED, 201 registrar_.Add(this, NotificationType::SPELLCHECK_HOST_REINITIALIZED,
204 NotificationService::AllSources()); 202 NotificationService::AllSources());
205 registrar_.Add(this, NotificationType::SPELLCHECK_WORD_ADDED, 203 registrar_.Add(this, NotificationType::SPELLCHECK_WORD_ADDED,
206 NotificationService::AllSources()); 204 NotificationService::AllSources());
207 205 registrar_.Add(this, NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED,
208 PrefService* prefs = profile->GetPrefs(); 206 NotificationService::AllSources());
209 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
210 #endif
211 207
212 visited_link_updater_.reset(new VisitedLinkUpdater()); 208 visited_link_updater_.reset(new VisitedLinkUpdater());
213 209
214 WebCacheManager::GetInstance()->Add(id()); 210 WebCacheManager::GetInstance()->Add(id());
215 ChildProcessSecurityPolicy::GetInstance()->Add(id()); 211 ChildProcessSecurityPolicy::GetInstance()->Add(id());
216 212
217 // Note: When we create the BrowserRenderProcessHost, it's technically 213 // Note: When we create the BrowserRenderProcessHost, it's technically
218 // backgrounded, because it has no visible listeners. But the process 214 // backgrounded, because it has no visible listeners. But the process
219 // doesn't actually exist yet, so we'll Background it later, after 215 // doesn't actually exist yet, so we'll Background it later, after
220 // creation. 216 // creation.
221 } 217 }
222 218
223 BrowserRenderProcessHost::~BrowserRenderProcessHost() { 219 BrowserRenderProcessHost::~BrowserRenderProcessHost() {
224 #if defined(SPELLCHECKER_IN_RENDERER)
225 PrefService* prefs = profile()->GetPrefs();
226 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
227 #endif
228
229 WebCacheManager::GetInstance()->Remove(id()); 220 WebCacheManager::GetInstance()->Remove(id());
230 ChildProcessSecurityPolicy::GetInstance()->Remove(id()); 221 ChildProcessSecurityPolicy::GetInstance()->Remove(id());
231 222
232 // We may have some unsent messages at this point, but that's OK. 223 // We may have some unsent messages at this point, but that's OK.
233 channel_.reset(); 224 channel_.reset();
234 while (!queued_messages_.empty()) { 225 while (!queued_messages_.empty()) {
235 delete queued_messages_.front(); 226 delete queued_messages_.front();
236 queued_messages_.pop(); 227 queued_messages_.pop();
237 } 228 }
238 229
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 audio_renderer_host_ = new AudioRendererHost(); 261 audio_renderer_host_ = new AudioRendererHost();
271 262
272 scoped_refptr<ResourceMessageFilter> resource_message_filter = 263 scoped_refptr<ResourceMessageFilter> resource_message_filter =
273 new ResourceMessageFilter(g_browser_process->resource_dispatcher_host(), 264 new ResourceMessageFilter(g_browser_process->resource_dispatcher_host(),
274 id(), 265 id(),
275 audio_renderer_host_.get(), 266 audio_renderer_host_.get(),
276 PluginService::GetInstance(), 267 PluginService::GetInstance(),
277 g_browser_process->print_job_manager(), 268 g_browser_process->print_job_manager(),
278 profile(), 269 profile(),
279 widget_helper_, 270 widget_helper_,
280 profile()->GetSpellChecker(),
281 request_context); 271 request_context);
282 272
283 // Find the renderer before creating the channel so if this fails early we 273 // Find the renderer before creating the channel so if this fails early we
284 // return without creating the channel. 274 // return without creating the channel.
285 FilePath renderer_path = ChildProcessHost::GetChildPath(); 275 FilePath renderer_path = ChildProcessHost::GetChildPath();
286 if (renderer_path.empty()) 276 if (renderer_path.empty())
287 return false; 277 return false;
288 278
289 // Setup the IPC channel. 279 // Setup the IPC channel.
290 const std::string channel_id = 280 const std::string channel_id =
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 377
388 DCHECK_EQ(backgrounded_, (visible_widgets_ == 0)); 378 DCHECK_EQ(backgrounded_, (visible_widgets_ == 0));
389 visible_widgets_--; 379 visible_widgets_--;
390 DCHECK_GE(visible_widgets_, 0); 380 DCHECK_GE(visible_widgets_, 0);
391 if (visible_widgets_ == 0) { 381 if (visible_widgets_ == 0) {
392 DCHECK(!backgrounded_); 382 DCHECK(!backgrounded_);
393 SetBackgrounded(true); 383 SetBackgrounded(true);
394 } 384 }
395 } 385 }
396 386
397 void BrowserRenderProcessHost::AddWord(const string16& word) {
398 SpellChecker* spellchecker = profile()->GetSpellChecker();
399 if (spellchecker) {
400 ChromeThread::PostTask(
401 ChromeThread::IO, FROM_HERE,
402 NewRunnableMethod(spellchecker, &SpellChecker::AddWord, word));
403 }
404 }
405
406 void BrowserRenderProcessHost::SendVisitedLinkTable( 387 void BrowserRenderProcessHost::SendVisitedLinkTable(
407 base::SharedMemory* table_memory) { 388 base::SharedMemory* table_memory) {
408 // Check if the process is still starting and we don't have a handle for it 389 // Check if the process is still starting and we don't have a handle for it
409 // yet, in which case this will happen later when InitVisitedLinks is called. 390 // yet, in which case this will happen later when InitVisitedLinks is called.
410 if (!run_renderer_in_process() && 391 if (!run_renderer_in_process() &&
411 (!child_process_.get() || child_process_->IsStarting())) { 392 (!child_process_.get() || child_process_->IsStarting())) {
412 return; 393 return;
413 } 394 }
414 395
415 base::SharedMemoryHandle handle_for_process; 396 base::SharedMemoryHandle handle_for_process;
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdatedCacheStats, 736 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdatedCacheStats,
756 OnUpdatedCacheStats) 737 OnUpdatedCacheStats)
757 IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged, 738 IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged,
758 SuddenTerminationChanged); 739 SuddenTerminationChanged);
759 IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionAddListener, 740 IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionAddListener,
760 OnExtensionAddListener) 741 OnExtensionAddListener)
761 IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionRemoveListener, 742 IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionRemoveListener,
762 OnExtensionRemoveListener) 743 OnExtensionRemoveListener)
763 IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionCloseChannel, 744 IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionCloseChannel,
764 OnExtensionCloseChannel) 745 OnExtensionCloseChannel)
765 #if defined(SPELLCHECKER_IN_RENDERER)
766 IPC_MESSAGE_HANDLER(ViewHostMsg_SpellChecker_RequestDictionary, 746 IPC_MESSAGE_HANDLER(ViewHostMsg_SpellChecker_RequestDictionary,
767 OnSpellCheckerRequestDictionary) 747 OnSpellCheckerRequestDictionary)
768 #endif
769 IPC_MESSAGE_UNHANDLED_ERROR() 748 IPC_MESSAGE_UNHANDLED_ERROR()
770 IPC_END_MESSAGE_MAP_EX() 749 IPC_END_MESSAGE_MAP_EX()
771 750
772 if (!msg_is_ok) { 751 if (!msg_is_ok) {
773 // The message had a handler, but its de-serialization failed. 752 // The message had a handler, but its de-serialization failed.
774 // We consider this a capital crime. Kill the renderer if we have one. 753 // We consider this a capital crime. Kill the renderer if we have one.
775 ReceivedBadMessage(msg.type()); 754 ReceivedBadMessage(msg.type());
776 } 755 }
777 return; 756 return;
778 } 757 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 const NotificationDetails& details) { 872 const NotificationDetails& details) {
894 switch (type.value) { 873 switch (type.value) {
895 case NotificationType::USER_SCRIPTS_UPDATED: { 874 case NotificationType::USER_SCRIPTS_UPDATED: {
896 base::SharedMemory* shared_memory = 875 base::SharedMemory* shared_memory =
897 Details<base::SharedMemory>(details).ptr(); 876 Details<base::SharedMemory>(details).ptr();
898 if (shared_memory) { 877 if (shared_memory) {
899 SendUserScriptsUpdate(shared_memory); 878 SendUserScriptsUpdate(shared_memory);
900 } 879 }
901 break; 880 break;
902 } 881 }
903 #if defined(SPELLCHECKER_IN_RENDERER)
904 case NotificationType::SPELLCHECK_HOST_REINITIALIZED: { 882 case NotificationType::SPELLCHECK_HOST_REINITIALIZED: {
905 InitSpellChecker(); 883 InitSpellChecker();
906 break; 884 break;
907 } 885 }
908 case NotificationType::SPELLCHECK_WORD_ADDED: { 886 case NotificationType::SPELLCHECK_WORD_ADDED: {
909 AddSpellCheckWord( 887 AddSpellCheckWord(
910 reinterpret_cast<const Source<SpellCheckHost>*>(&source)-> 888 reinterpret_cast<const Source<SpellCheckHost>*>(&source)->
911 ptr()->last_added_word()); 889 ptr()->last_added_word());
912 break; 890 break;
913 } 891 }
914 case NotificationType::PREF_CHANGED: { 892 case NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED: {
915 std::wstring* pref_name_in = Details<std::wstring>(details).ptr(); 893 PrefService* prefs = profile()->GetPrefs();
916 PrefService* prefs = Source<PrefService>(source).ptr(); 894 EnableAutoSpellCorrect(
917 DCHECK(pref_name_in && prefs); 895 prefs->GetBoolean(prefs::kEnableAutoSpellCorrect));
918 if (*pref_name_in == prefs::kEnableAutoSpellCorrect) { 896 break;
919 EnableAutoSpellCorrect(
920 prefs->GetBoolean(prefs::kEnableAutoSpellCorrect));
921 break;
922 }
923 // Fall through.
924 } 897 }
925 #endif
926 default: { 898 default: {
927 NOTREACHED(); 899 NOTREACHED();
928 break; 900 break;
929 } 901 }
930 } 902 }
931 } 903 }
932 904
933 void BrowserRenderProcessHost::OnProcessLaunched() { 905 void BrowserRenderProcessHost::OnProcessLaunched() {
934 // Now that the process is created, set its backgrounding accordingly. 906 // Now that the process is created, set its backgrounding accordingly.
935 SetBackgrounded(backgrounded_); 907 SetBackgrounded(backgrounded_);
936 908
937 InitVisitedLinks(); 909 InitVisitedLinks();
938 InitUserScripts(); 910 InitUserScripts();
939 InitExtensions(); 911 InitExtensions();
940 #if defined(SPELLCHECKER_IN_RENDERER)
941 // We don't want to initialize the spellchecker unless SpellCheckHost has been 912 // We don't want to initialize the spellchecker unless SpellCheckHost has been
942 // created. In InitSpellChecker(), we know if GetSpellCheckHost() is NULL 913 // created. In InitSpellChecker(), we know if GetSpellCheckHost() is NULL
943 // then the spellchecker has been turned off, but here, we don't know if 914 // then the spellchecker has been turned off, but here, we don't know if
944 // it's been turned off or just not loaded yet. 915 // it's been turned off or just not loaded yet.
945 if (profile()->GetSpellCheckHost()) 916 if (profile()->GetSpellCheckHost())
946 InitSpellChecker(); 917 InitSpellChecker();
947 #endif
948 918
949 if (max_page_id_ != -1) 919 if (max_page_id_ != -1)
950 Send(new ViewMsg_SetNextPageID(max_page_id_ + 1)); 920 Send(new ViewMsg_SetNextPageID(max_page_id_ + 1));
951 921
952 while (!queued_messages_.empty()) { 922 while (!queued_messages_.empty()) {
953 Send(queued_messages_.front()); 923 Send(queued_messages_.front());
954 queued_messages_.pop(); 924 queued_messages_.pop();
955 } 925 }
956 926
957 NotificationService::current()->Notify( 927 NotificationService::current()->Notify(
(...skipping 16 matching lines...) Expand all
974 event_name, id()); 944 event_name, id());
975 } 945 }
976 } 946 }
977 947
978 void BrowserRenderProcessHost::OnExtensionCloseChannel(int port_id) { 948 void BrowserRenderProcessHost::OnExtensionCloseChannel(int port_id) {
979 if (profile()->GetExtensionMessageService()) { 949 if (profile()->GetExtensionMessageService()) {
980 profile()->GetExtensionMessageService()->CloseChannel(port_id); 950 profile()->GetExtensionMessageService()->CloseChannel(port_id);
981 } 951 }
982 } 952 }
983 953
984 #if defined(SPELLCHECKER_IN_RENDERER)
985 void BrowserRenderProcessHost::OnSpellCheckerRequestDictionary() { 954 void BrowserRenderProcessHost::OnSpellCheckerRequestDictionary() {
986 // We may have gotten multiple requests from different renderers. We don't 955 // We may have gotten multiple requests from different renderers. We don't
987 // want to initialize multiple times in this case, so we set |force| to false. 956 // want to initialize multiple times in this case, so we set |force| to false.
988 profile()->ReinitializeSpellCheckHost(false); 957 profile()->ReinitializeSpellCheckHost(false);
989 } 958 }
990 959
991 void BrowserRenderProcessHost::AddSpellCheckWord(const std::string& word) { 960 void BrowserRenderProcessHost::AddSpellCheckWord(const std::string& word) {
992 Send(new ViewMsg_SpellChecker_WordAdded(word)); 961 Send(new ViewMsg_SpellChecker_WordAdded(word));
993 } 962 }
994 963
995 void BrowserRenderProcessHost::InitSpellChecker() { 964 void BrowserRenderProcessHost::InitSpellChecker() {
996 SpellCheckHost* spellcheck_host = profile()->GetSpellCheckHost(); 965 SpellCheckHost* spellcheck_host = profile()->GetSpellCheckHost();
997 if (spellcheck_host) { 966 if (spellcheck_host) {
998 PrefService* prefs = profile()->GetPrefs(); 967 PrefService* prefs = profile()->GetPrefs();
999 IPC::PlatformFileForTransit file; 968 IPC::PlatformFileForTransit file;
969
970 if (spellcheck_host->bdict_file() != base::kInvalidPlatformFileValue) {
1000 #if defined(OS_POSIX) 971 #if defined(OS_POSIX)
1001 file = base::FileDescriptor(spellcheck_host->bdict_file(), false); 972 file = base::FileDescriptor(spellcheck_host->bdict_file(), false);
1002 #elif defined(OS_WIN) 973 #elif defined(OS_WIN)
1003 ::DuplicateHandle(::GetCurrentProcess(), spellcheck_host->bdict_file(), 974 ::DuplicateHandle(::GetCurrentProcess(), spellcheck_host->bdict_file(),
1004 GetHandle(), &file, 0, false, DUPLICATE_SAME_ACCESS); 975 GetHandle(), &file, 0, false, DUPLICATE_SAME_ACCESS);
1005 #endif 976 #endif
977 }
978
1006 Send(new ViewMsg_SpellChecker_Init( 979 Send(new ViewMsg_SpellChecker_Init(
1007 file, 980 file,
1008 spellcheck_host->custom_words(), 981 spellcheck_host->custom_words(),
1009 spellcheck_host->language(), 982 spellcheck_host->language(),
1010 prefs->GetBoolean(prefs::kEnableAutoSpellCorrect))); 983 prefs->GetBoolean(prefs::kEnableAutoSpellCorrect)));
1011 } else { 984 } else {
1012 Send(new ViewMsg_SpellChecker_Init( 985 Send(new ViewMsg_SpellChecker_Init(
1013 IPC::PlatformFileForTransit(), 986 IPC::PlatformFileForTransit(),
1014 std::vector<std::string>(), 987 std::vector<std::string>(),
1015 std::string(), 988 std::string(),
1016 false)); 989 false));
1017 } 990 }
1018 } 991 }
1019 992
1020 void BrowserRenderProcessHost::EnableAutoSpellCorrect(bool enable) { 993 void BrowserRenderProcessHost::EnableAutoSpellCorrect(bool enable) {
1021 Send(new ViewMsg_SpellChecker_EnableAutoSpellCorrect(enable)); 994 Send(new ViewMsg_SpellChecker_EnableAutoSpellCorrect(enable));
1022 } 995 }
1023 #endif
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/browser_render_process_host.h ('k') | chrome/browser/renderer_host/render_process_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698