OLD | NEW |
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 "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "chrome/browser/history/history.h" | 33 #include "chrome/browser/history/history.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" |
| 45 #endif |
43 #include "chrome/browser/spellchecker.h" | 46 #include "chrome/browser/spellchecker.h" |
44 #include "chrome/browser/visitedlink_master.h" | 47 #include "chrome/browser/visitedlink_master.h" |
45 #include "chrome/common/chrome_switches.h" | 48 #include "chrome/common/chrome_switches.h" |
46 #include "chrome/common/child_process_info.h" | 49 #include "chrome/common/child_process_info.h" |
47 #include "chrome/common/child_process_host.h" | 50 #include "chrome/common/child_process_host.h" |
48 #include "chrome/common/chrome_descriptors.h" | 51 #include "chrome/common/chrome_descriptors.h" |
49 #include "chrome/common/logging_chrome.h" | 52 #include "chrome/common/logging_chrome.h" |
50 #include "chrome/common/notification_service.h" | 53 #include "chrome/common/notification_service.h" |
51 #include "chrome/common/process_watcher.h" | 54 #include "chrome/common/process_watcher.h" |
52 #include "chrome/common/render_messages.h" | 55 #include "chrome/common/render_messages.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 visible_widgets_(0), | 199 visible_widgets_(0), |
197 backgrounded_(true), | 200 backgrounded_(true), |
198 ALLOW_THIS_IN_INITIALIZER_LIST(cached_dibs_cleaner_( | 201 ALLOW_THIS_IN_INITIALIZER_LIST(cached_dibs_cleaner_( |
199 base::TimeDelta::FromSeconds(5), | 202 base::TimeDelta::FromSeconds(5), |
200 this, &BrowserRenderProcessHost::ClearTransportDIBCache)), | 203 this, &BrowserRenderProcessHost::ClearTransportDIBCache)), |
201 zygote_child_(false) { | 204 zygote_child_(false) { |
202 widget_helper_ = new RenderWidgetHelper(); | 205 widget_helper_ = new RenderWidgetHelper(); |
203 | 206 |
204 registrar_.Add(this, NotificationType::USER_SCRIPTS_UPDATED, | 207 registrar_.Add(this, NotificationType::USER_SCRIPTS_UPDATED, |
205 NotificationService::AllSources()); | 208 NotificationService::AllSources()); |
| 209 #if defined(SPELLCHECKER_IN_RENDERER) |
| 210 registrar_.Add(this, NotificationType::SPELLCHECK_HOST_REINITIALIZED, |
| 211 NotificationService::AllSources()); |
| 212 registrar_.Add(this, NotificationType::SPELLCHECK_WORD_ADDED, |
| 213 NotificationService::AllSources()); |
| 214 |
| 215 PrefService* prefs = profile->GetPrefs(); |
| 216 prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this); |
| 217 #endif |
| 218 |
206 visited_link_updater_.reset(new VisitedLinkUpdater()); | 219 visited_link_updater_.reset(new VisitedLinkUpdater()); |
207 | 220 |
208 WebCacheManager::GetInstance()->Add(id()); | 221 WebCacheManager::GetInstance()->Add(id()); |
209 ChildProcessSecurityPolicy::GetInstance()->Add(id()); | 222 ChildProcessSecurityPolicy::GetInstance()->Add(id()); |
210 | 223 |
211 // Note: When we create the BrowserRenderProcessHost, it's technically | 224 // Note: When we create the BrowserRenderProcessHost, it's technically |
212 // backgrounded, because it has no visible listeners. But the process | 225 // backgrounded, because it has no visible listeners. But the process |
213 // doesn't actually exist yet, so we'll Background it later, after | 226 // doesn't actually exist yet, so we'll Background it later, after |
214 // creation. | 227 // creation. |
215 } | 228 } |
216 | 229 |
217 BrowserRenderProcessHost::~BrowserRenderProcessHost() { | 230 BrowserRenderProcessHost::~BrowserRenderProcessHost() { |
| 231 #if defined(SPELLCHECKER_IN_RENDERER) |
| 232 PrefService* prefs = profile()->GetPrefs(); |
| 233 prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this); |
| 234 #endif |
| 235 |
218 WebCacheManager::GetInstance()->Remove(id()); | 236 WebCacheManager::GetInstance()->Remove(id()); |
219 ChildProcessSecurityPolicy::GetInstance()->Remove(id()); | 237 ChildProcessSecurityPolicy::GetInstance()->Remove(id()); |
220 | 238 |
221 // We may have some unsent messages at this point, but that's OK. | 239 // We may have some unsent messages at this point, but that's OK. |
222 channel_.reset(); | 240 channel_.reset(); |
223 | 241 |
224 // Destroy the AudioRendererHost properly. | 242 // Destroy the AudioRendererHost properly. |
225 if (audio_renderer_host_.get()) | 243 if (audio_renderer_host_.get()) |
226 audio_renderer_host_->Destroy(); | 244 audio_renderer_host_->Destroy(); |
227 | 245 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 } | 359 } |
342 | 360 |
343 resource_message_filter->Init(); | 361 resource_message_filter->Init(); |
344 | 362 |
345 // Now that the process is created, set its backgrounding accordingly. | 363 // Now that the process is created, set its backgrounding accordingly. |
346 SetBackgrounded(backgrounded_); | 364 SetBackgrounded(backgrounded_); |
347 | 365 |
348 InitVisitedLinks(); | 366 InitVisitedLinks(); |
349 InitUserScripts(); | 367 InitUserScripts(); |
350 InitExtensions(); | 368 InitExtensions(); |
| 369 #if defined(SPELLCHECKER_IN_RENDERER) |
| 370 // We don't want to initialize the spellchecker unless SpellCheckHost has been |
| 371 // created. In InitSpellChecker(), we know if GetSpellCheckHost() is NULL |
| 372 // then the spellchecker has been turned off, but here, we don't know if |
| 373 // it's been turned off or just not loaded yet. |
| 374 if (profile()->GetSpellCheckHost()) |
| 375 InitSpellChecker(); |
| 376 #endif |
351 | 377 |
352 if (max_page_id_ != -1) | 378 if (max_page_id_ != -1) |
353 channel_->Send(new ViewMsg_SetNextPageID(max_page_id_ + 1)); | 379 channel_->Send(new ViewMsg_SetNextPageID(max_page_id_ + 1)); |
354 | 380 |
355 return true; | 381 return true; |
356 } | 382 } |
357 | 383 |
358 int BrowserRenderProcessHost::GetNextRoutingID() { | 384 int BrowserRenderProcessHost::GetNextRoutingID() { |
359 return widget_helper_->GetNextRoutingID(); | 385 return widget_helper_->GetNextRoutingID(); |
360 } | 386 } |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdatedCacheStats, | 832 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdatedCacheStats, |
807 OnUpdatedCacheStats) | 833 OnUpdatedCacheStats) |
808 IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged, | 834 IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged, |
809 SuddenTerminationChanged); | 835 SuddenTerminationChanged); |
810 IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionAddListener, | 836 IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionAddListener, |
811 OnExtensionAddListener) | 837 OnExtensionAddListener) |
812 IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionRemoveListener, | 838 IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionRemoveListener, |
813 OnExtensionRemoveListener) | 839 OnExtensionRemoveListener) |
814 IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionCloseChannel, | 840 IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionCloseChannel, |
815 OnExtensionCloseChannel) | 841 OnExtensionCloseChannel) |
| 842 #if defined(SPELLCHECKER_IN_RENDERER) |
| 843 IPC_MESSAGE_HANDLER(ViewHostMsg_SpellChecker_RequestDictionary, |
| 844 OnSpellCheckerRequestDictionary) |
| 845 #endif |
816 IPC_MESSAGE_UNHANDLED_ERROR() | 846 IPC_MESSAGE_UNHANDLED_ERROR() |
817 IPC_END_MESSAGE_MAP_EX() | 847 IPC_END_MESSAGE_MAP_EX() |
818 | 848 |
819 if (!msg_is_ok) { | 849 if (!msg_is_ok) { |
820 // The message had a handler, but its de-serialization failed. | 850 // The message had a handler, but its de-serialization failed. |
821 // We consider this a capital crime. Kill the renderer if we have one. | 851 // We consider this a capital crime. Kill the renderer if we have one. |
822 ReceivedBadMessage(msg.type()); | 852 ReceivedBadMessage(msg.type()); |
823 } | 853 } |
824 return; | 854 return; |
825 } | 855 } |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 const NotificationDetails& details) { | 1042 const NotificationDetails& details) { |
1013 switch (type.value) { | 1043 switch (type.value) { |
1014 case NotificationType::USER_SCRIPTS_UPDATED: { | 1044 case NotificationType::USER_SCRIPTS_UPDATED: { |
1015 base::SharedMemory* shared_memory = | 1045 base::SharedMemory* shared_memory = |
1016 Details<base::SharedMemory>(details).ptr(); | 1046 Details<base::SharedMemory>(details).ptr(); |
1017 if (shared_memory) { | 1047 if (shared_memory) { |
1018 SendUserScriptsUpdate(shared_memory); | 1048 SendUserScriptsUpdate(shared_memory); |
1019 } | 1049 } |
1020 break; | 1050 break; |
1021 } | 1051 } |
| 1052 #if defined(SPELLCHECKER_IN_RENDERER) |
| 1053 case NotificationType::SPELLCHECK_HOST_REINITIALIZED: { |
| 1054 InitSpellChecker(); |
| 1055 break; |
| 1056 } |
| 1057 case NotificationType::SPELLCHECK_WORD_ADDED: { |
| 1058 AddSpellCheckWord( |
| 1059 reinterpret_cast<const Source<SpellCheckHost>*>(&source)-> |
| 1060 ptr()->last_added_word()); |
| 1061 break; |
| 1062 } |
| 1063 case NotificationType::PREF_CHANGED: { |
| 1064 std::wstring* pref_name_in = Details<std::wstring>(details).ptr(); |
| 1065 PrefService* prefs = Source<PrefService>(source).ptr(); |
| 1066 DCHECK(pref_name_in && prefs); |
| 1067 if (*pref_name_in == prefs::kEnableAutoSpellCorrect) { |
| 1068 EnableAutoSpellCorrect( |
| 1069 prefs->GetBoolean(prefs::kEnableAutoSpellCorrect)); |
| 1070 break; |
| 1071 } |
| 1072 // Fall through. |
| 1073 } |
| 1074 #endif |
1022 default: { | 1075 default: { |
1023 NOTREACHED(); | 1076 NOTREACHED(); |
1024 break; | 1077 break; |
1025 } | 1078 } |
1026 } | 1079 } |
1027 } | 1080 } |
1028 | 1081 |
1029 void BrowserRenderProcessHost::OnExtensionAddListener( | 1082 void BrowserRenderProcessHost::OnExtensionAddListener( |
1030 const std::string& event_name) { | 1083 const std::string& event_name) { |
1031 if (profile()->GetExtensionMessageService()) { | 1084 if (profile()->GetExtensionMessageService()) { |
1032 profile()->GetExtensionMessageService()->AddEventListener( | 1085 profile()->GetExtensionMessageService()->AddEventListener( |
1033 event_name, id()); | 1086 event_name, id()); |
1034 } | 1087 } |
1035 } | 1088 } |
1036 | 1089 |
1037 void BrowserRenderProcessHost::OnExtensionRemoveListener( | 1090 void BrowserRenderProcessHost::OnExtensionRemoveListener( |
1038 const std::string& event_name) { | 1091 const std::string& event_name) { |
1039 if (profile()->GetExtensionMessageService()) { | 1092 if (profile()->GetExtensionMessageService()) { |
1040 profile()->GetExtensionMessageService()->RemoveEventListener( | 1093 profile()->GetExtensionMessageService()->RemoveEventListener( |
1041 event_name, id()); | 1094 event_name, id()); |
1042 } | 1095 } |
1043 } | 1096 } |
1044 | 1097 |
1045 void BrowserRenderProcessHost::OnExtensionCloseChannel(int port_id) { | 1098 void BrowserRenderProcessHost::OnExtensionCloseChannel(int port_id) { |
1046 if (profile()->GetExtensionMessageService()) { | 1099 if (profile()->GetExtensionMessageService()) { |
1047 profile()->GetExtensionMessageService()->CloseChannel(port_id); | 1100 profile()->GetExtensionMessageService()->CloseChannel(port_id); |
1048 } | 1101 } |
1049 } | 1102 } |
| 1103 |
| 1104 #if defined(SPELLCHECKER_IN_RENDERER) |
| 1105 void BrowserRenderProcessHost::OnSpellCheckerRequestDictionary() { |
| 1106 // We may have gotten multiple requests from different renderers. We don't |
| 1107 // want to initialize multiple times in this case, so we set |force| to false. |
| 1108 profile()->ReinitializeSpellCheckHost(false); |
| 1109 } |
| 1110 |
| 1111 void BrowserRenderProcessHost::AddSpellCheckWord(const std::string& word) { |
| 1112 channel_->Send(new ViewMsg_SpellChecker_WordAdded(word)); |
| 1113 } |
| 1114 |
| 1115 void BrowserRenderProcessHost::InitSpellChecker() { |
| 1116 SpellCheckHost* spellcheck_host = profile()->GetSpellCheckHost(); |
| 1117 if (spellcheck_host) { |
| 1118 PrefService* prefs = profile()->GetPrefs(); |
| 1119 channel_->Send(new ViewMsg_SpellChecker_Init( |
| 1120 spellcheck_host->bdict_fd(), spellcheck_host->custom_words(), |
| 1121 spellcheck_host->language(), |
| 1122 prefs->GetBoolean(prefs::kEnableAutoSpellCorrect))); |
| 1123 } else { |
| 1124 channel_->Send(new ViewMsg_SpellChecker_Init( |
| 1125 base::FileDescriptor(), std::vector<std::string>(), std::string(), |
| 1126 false)); |
| 1127 } |
| 1128 } |
| 1129 |
| 1130 void BrowserRenderProcessHost::EnableAutoSpellCorrect(bool enable) { |
| 1131 channel_->Send(new ViewMsg_SpellChecker_EnableAutoSpellCorrect(enable)); |
| 1132 } |
| 1133 #endif |
OLD | NEW |