OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/renderer_host/browser_render_process_host.h" | 8 #include "content/browser/renderer_host/browser_render_process_host.h" |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "base/threading/thread_restrictions.h" | 28 #include "base/threading/thread_restrictions.h" |
29 #include "chrome/browser/browser_process.h" | 29 #include "chrome/browser/browser_process.h" |
30 #include "chrome/browser/history/history.h" | 30 #include "chrome/browser/history/history.h" |
31 #include "chrome/browser/io_thread.h" | 31 #include "chrome/browser/io_thread.h" |
32 #include "chrome/browser/net/resolve_proxy_msg_helper.h" | 32 #include "chrome/browser/net/resolve_proxy_msg_helper.h" |
33 #include "chrome/browser/platform_util.h" | 33 #include "chrome/browser/platform_util.h" |
34 #include "chrome/browser/prefs/pref_service.h" | 34 #include "chrome/browser/prefs/pref_service.h" |
35 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
36 #include "chrome/browser/renderer_host/web_cache_manager.h" | 36 #include "chrome/browser/renderer_host/web_cache_manager.h" |
37 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 37 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
38 #include "chrome/browser/spellcheck_host.h" | |
39 #include "chrome/common/chrome_paths.h" | 38 #include "chrome/common/chrome_paths.h" |
40 #include "chrome/common/chrome_switches.h" | 39 #include "chrome/common/chrome_switches.h" |
41 #include "chrome/common/logging_chrome.h" | 40 #include "chrome/common/logging_chrome.h" |
42 #include "chrome/common/pref_names.h" | 41 #include "chrome/common/pref_names.h" |
43 #include "chrome/common/render_messages.h" | 42 #include "chrome/common/render_messages.h" |
44 #include "chrome/common/safe_browsing/safebrowsing_messages.h" | 43 #include "chrome/common/safe_browsing/safebrowsing_messages.h" |
45 #include "chrome/common/spellcheck_messages.h" | |
46 #include "content/browser/appcache/appcache_dispatcher_host.h" | 44 #include "content/browser/appcache/appcache_dispatcher_host.h" |
47 #include "content/browser/browser_child_process_host.h" | 45 #include "content/browser/browser_child_process_host.h" |
48 #include "content/browser/child_process_security_policy.h" | 46 #include "content/browser/child_process_security_policy.h" |
49 #include "content/browser/content_browser_client.h" | 47 #include "content/browser/content_browser_client.h" |
50 #include "content/browser/device_orientation/message_filter.h" | 48 #include "content/browser/device_orientation/message_filter.h" |
51 #include "content/browser/geolocation/geolocation_dispatcher_host.h" | 49 #include "content/browser/geolocation/geolocation_dispatcher_host.h" |
52 #include "content/browser/gpu_data_manager.h" | 50 #include "content/browser/gpu_data_manager.h" |
53 #include "content/browser/gpu_process_host.h" | 51 #include "content/browser/gpu_process_host.h" |
54 #include "content/browser/in_process_webkit/dom_storage_message_filter.h" | 52 #include "content/browser/in_process_webkit/dom_storage_message_filter.h" |
55 #include "content/browser/in_process_webkit/indexed_db_dispatcher_host.h" | 53 #include "content/browser/in_process_webkit/indexed_db_dispatcher_host.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 visible_widgets_(0), | 194 visible_widgets_(0), |
197 backgrounded_(true), | 195 backgrounded_(true), |
198 ALLOW_THIS_IN_INITIALIZER_LIST(cached_dibs_cleaner_( | 196 ALLOW_THIS_IN_INITIALIZER_LIST(cached_dibs_cleaner_( |
199 base::TimeDelta::FromSeconds(5), | 197 base::TimeDelta::FromSeconds(5), |
200 this, &BrowserRenderProcessHost::ClearTransportDIBCache)), | 198 this, &BrowserRenderProcessHost::ClearTransportDIBCache)), |
201 accessibility_enabled_(false), | 199 accessibility_enabled_(false), |
202 extension_process_(false), | 200 extension_process_(false), |
203 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 201 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
204 widget_helper_ = new RenderWidgetHelper(); | 202 widget_helper_ = new RenderWidgetHelper(); |
205 | 203 |
206 registrar_.Add(this, NotificationType::SPELLCHECK_HOST_REINITIALIZED, | |
207 NotificationService::AllSources()); | |
208 registrar_.Add(this, NotificationType::SPELLCHECK_WORD_ADDED, | |
209 NotificationService::AllSources()); | |
210 registrar_.Add(this, NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED, | |
211 NotificationService::AllSources()); | |
212 | |
213 WebCacheManager::GetInstance()->Add(id()); | 204 WebCacheManager::GetInstance()->Add(id()); |
214 ChildProcessSecurityPolicy::GetInstance()->Add(id()); | 205 ChildProcessSecurityPolicy::GetInstance()->Add(id()); |
215 | 206 |
216 // Grant most file permissions to this renderer. | 207 // Grant most file permissions to this renderer. |
217 // PLATFORM_FILE_TEMPORARY, PLATFORM_FILE_HIDDEN and | 208 // PLATFORM_FILE_TEMPORARY, PLATFORM_FILE_HIDDEN and |
218 // PLATFORM_FILE_DELETE_ON_CLOSE are not granted, because no existing API | 209 // PLATFORM_FILE_DELETE_ON_CLOSE are not granted, because no existing API |
219 // requests them. | 210 // requests them. |
220 ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( | 211 ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( |
221 id(), profile->GetPath().Append( | 212 id(), profile->GetPath().Append( |
222 fileapi::SandboxMountPointProvider::kFileSystemDirectory), | 213 fileapi::SandboxMountPointProvider::kFileSystemDirectory), |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 if (msg.routing_id() == MSG_ROUTING_CONTROL) { | 808 if (msg.routing_id() == MSG_ROUTING_CONTROL) { |
818 // Dispatch control messages. | 809 // Dispatch control messages. |
819 bool msg_is_ok = true; | 810 bool msg_is_ok = true; |
820 IPC_BEGIN_MESSAGE_MAP_EX(BrowserRenderProcessHost, msg, msg_is_ok) | 811 IPC_BEGIN_MESSAGE_MAP_EX(BrowserRenderProcessHost, msg, msg_is_ok) |
821 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdatedCacheStats, | 812 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdatedCacheStats, |
822 OnUpdatedCacheStats) | 813 OnUpdatedCacheStats) |
823 IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged, | 814 IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged, |
824 SuddenTerminationChanged) | 815 SuddenTerminationChanged) |
825 IPC_MESSAGE_HANDLER(ViewHostMsg_UserMetricsRecordAction, | 816 IPC_MESSAGE_HANDLER(ViewHostMsg_UserMetricsRecordAction, |
826 OnUserMetricsRecordAction) | 817 OnUserMetricsRecordAction) |
827 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_RequestDictionary, | |
828 OnSpellCheckerRequestDictionary) | |
829 IPC_MESSAGE_UNHANDLED_ERROR() | 818 IPC_MESSAGE_UNHANDLED_ERROR() |
830 IPC_END_MESSAGE_MAP_EX() | 819 IPC_END_MESSAGE_MAP_EX() |
831 | 820 |
832 if (!msg_is_ok) { | 821 if (!msg_is_ok) { |
833 // The message had a handler, but its de-serialization failed. | 822 // The message had a handler, but its de-serialization failed. |
834 // We consider this a capital crime. Kill the renderer if we have one. | 823 // We consider this a capital crime. Kill the renderer if we have one. |
835 LOG(ERROR) << "bad message " << msg.type() << " terminating renderer."; | 824 LOG(ERROR) << "bad message " << msg.type() << " terminating renderer."; |
836 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_BRPH")); | 825 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_BRPH")); |
837 ReceivedBadMessage(); | 826 ReceivedBadMessage(); |
838 } | 827 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 // intercepted the stack is messed up on return from the interceptor | 927 // intercepted the stack is messed up on return from the interceptor |
939 // which causes random crashes in the browser process. Our hack for now | 928 // which causes random crashes in the browser process. Our hack for now |
940 // is to not invoke the SetPriorityClass API if the dll is loaded. | 929 // is to not invoke the SetPriorityClass API if the dll is loaded. |
941 if (GetModuleHandle(L"cbstext.dll")) | 930 if (GetModuleHandle(L"cbstext.dll")) |
942 return; | 931 return; |
943 #endif // OS_WIN | 932 #endif // OS_WIN |
944 | 933 |
945 child_process_launcher_->SetProcessBackgrounded(backgrounded); | 934 child_process_launcher_->SetProcessBackgrounded(backgrounded); |
946 } | 935 } |
947 | 936 |
948 void BrowserRenderProcessHost::Observe(NotificationType type, | |
949 const NotificationSource& source, | |
950 const NotificationDetails& details) { | |
951 switch (type.value) { | |
952 case NotificationType::SPELLCHECK_HOST_REINITIALIZED: { | |
953 InitSpellChecker(); | |
954 break; | |
955 } | |
956 case NotificationType::SPELLCHECK_WORD_ADDED: { | |
957 AddSpellCheckWord( | |
958 reinterpret_cast<const Source<SpellCheckHost>*>(&source)-> | |
959 ptr()->GetLastAddedFile()); | |
960 break; | |
961 } | |
962 case NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED: { | |
963 PrefService* prefs = profile()->GetPrefs(); | |
964 EnableAutoSpellCorrect( | |
965 prefs->GetBoolean(prefs::kEnableAutoSpellCorrect)); | |
966 break; | |
967 } | |
968 default: { | |
969 NOTREACHED(); | |
970 break; | |
971 } | |
972 } | |
973 } | |
974 | |
975 void BrowserRenderProcessHost::OnProcessLaunched() { | 937 void BrowserRenderProcessHost::OnProcessLaunched() { |
976 if (child_process_launcher_.get()) | 938 if (child_process_launcher_.get()) |
977 child_process_launcher_->SetProcessBackgrounded(backgrounded_); | 939 child_process_launcher_->SetProcessBackgrounded(backgrounded_); |
978 | 940 |
979 Send(new ViewMsg_SetIsIncognitoProcess(profile()->IsOffTheRecord())); | 941 Send(new ViewMsg_SetIsIncognitoProcess(profile()->IsOffTheRecord())); |
980 | 942 |
981 // We don't want to initialize the spellchecker unless SpellCheckHost has been | |
982 // created. In InitSpellChecker(), we know if GetSpellCheckHost() is NULL | |
983 // then the spellchecker has been turned off, but here, we don't know if | |
984 // it's been turned off or just not loaded yet. | |
985 if (profile()->GetSpellCheckHost()) | |
986 InitSpellChecker(); | |
987 | |
988 InitClientSidePhishingDetection(); | 943 InitClientSidePhishingDetection(); |
989 | 944 |
990 if (max_page_id_ != -1) | 945 if (max_page_id_ != -1) |
991 Send(new ViewMsg_SetNextPageID(max_page_id_ + 1)); | 946 Send(new ViewMsg_SetNextPageID(max_page_id_ + 1)); |
992 | 947 |
993 // NOTE: This needs to be before sending queued messages because | 948 // NOTE: This needs to be before sending queued messages because |
994 // ExtensionService uses this notification to initialize the renderer process | 949 // ExtensionService uses this notification to initialize the renderer process |
995 // with state that must be there before any JavaScript executes. | 950 // with state that must be there before any JavaScript executes. |
996 // | 951 // |
997 // The queued messages contain such things as "navigate". If this notification | 952 // The queued messages contain such things as "navigate". If this notification |
998 // was after, we can end up executing JavaScript before the initialization | 953 // was after, we can end up executing JavaScript before the initialization |
999 // happens. | 954 // happens. |
1000 NotificationService::current()->Notify( | 955 NotificationService::current()->Notify( |
1001 NotificationType::RENDERER_PROCESS_CREATED, | 956 NotificationType::RENDERER_PROCESS_CREATED, |
1002 Source<RenderProcessHost>(this), NotificationService::NoDetails()); | 957 Source<RenderProcessHost>(this), NotificationService::NoDetails()); |
1003 | 958 |
1004 while (!queued_messages_.empty()) { | 959 while (!queued_messages_.empty()) { |
1005 Send(queued_messages_.front()); | 960 Send(queued_messages_.front()); |
1006 queued_messages_.pop(); | 961 queued_messages_.pop(); |
1007 } | 962 } |
1008 } | 963 } |
1009 | 964 |
1010 void BrowserRenderProcessHost::OnUserMetricsRecordAction( | 965 void BrowserRenderProcessHost::OnUserMetricsRecordAction( |
1011 const std::string& action) { | 966 const std::string& action) { |
1012 UserMetrics::RecordComputedAction(action); | 967 UserMetrics::RecordComputedAction(action); |
1013 } | 968 } |
1014 | 969 |
1015 void BrowserRenderProcessHost::OnSpellCheckerRequestDictionary() { | |
1016 if (profile()->GetSpellCheckHost()) { | |
1017 // The spellchecker initialization already started and finished; just send | |
1018 // it to the renderer. | |
1019 InitSpellChecker(); | |
1020 } else { | |
1021 // We may have gotten multiple requests from different renderers. We don't | |
1022 // want to initialize multiple times in this case, so we set |force| to | |
1023 // false. | |
1024 profile()->ReinitializeSpellCheckHost(false); | |
1025 } | |
1026 } | |
1027 | |
1028 void BrowserRenderProcessHost::AddSpellCheckWord(const std::string& word) { | |
1029 Send(new SpellCheckMsg_WordAdded(word)); | |
1030 } | |
1031 | |
1032 void BrowserRenderProcessHost::InitSpellChecker() { | |
1033 SpellCheckHost* spellcheck_host = profile()->GetSpellCheckHost(); | |
1034 if (spellcheck_host) { | |
1035 PrefService* prefs = profile()->GetPrefs(); | |
1036 IPC::PlatformFileForTransit file; | |
1037 | |
1038 if (spellcheck_host->GetDictionaryFile() != | |
1039 base::kInvalidPlatformFileValue) { | |
1040 #if defined(OS_POSIX) | |
1041 file = base::FileDescriptor(spellcheck_host->GetDictionaryFile(), false); | |
1042 #elif defined(OS_WIN) | |
1043 ::DuplicateHandle(::GetCurrentProcess(), | |
1044 spellcheck_host->GetDictionaryFile(), | |
1045 GetHandle(), | |
1046 &file, | |
1047 0, | |
1048 false, | |
1049 DUPLICATE_SAME_ACCESS); | |
1050 #endif | |
1051 } | |
1052 | |
1053 Send(new SpellCheckMsg_Init( | |
1054 file, | |
1055 spellcheck_host->GetCustomWords(), | |
1056 spellcheck_host->GetLanguage(), | |
1057 prefs->GetBoolean(prefs::kEnableAutoSpellCorrect))); | |
1058 } else { | |
1059 Send(new SpellCheckMsg_Init( | |
1060 IPC::InvalidPlatformFileForTransit(), | |
1061 std::vector<std::string>(), | |
1062 std::string(), | |
1063 false)); | |
1064 } | |
1065 } | |
1066 | |
1067 void BrowserRenderProcessHost::EnableAutoSpellCorrect(bool enable) { | |
1068 Send(new SpellCheckMsg_EnableAutoSpellCorrect(enable)); | |
1069 } | |
1070 | |
1071 void BrowserRenderProcessHost::InitClientSidePhishingDetection() { | 970 void BrowserRenderProcessHost::InitClientSidePhishingDetection() { |
1072 if (g_browser_process->safe_browsing_detection_service()) { | 971 if (g_browser_process->safe_browsing_detection_service()) { |
1073 // The BrowserRenderProcessHost object might get deleted before the | 972 // The BrowserRenderProcessHost object might get deleted before the |
1074 // safe browsing client-side detection service class is done with opening | 973 // safe browsing client-side detection service class is done with opening |
1075 // the model file. To avoid crashing we use the callback factory which will | 974 // the model file. To avoid crashing we use the callback factory which will |
1076 // cancel the callback if |this| is destroyed. | 975 // cancel the callback if |this| is destroyed. |
1077 g_browser_process->safe_browsing_detection_service()->GetModelFile( | 976 g_browser_process->safe_browsing_detection_service()->GetModelFile( |
1078 callback_factory_.NewCallback( | 977 callback_factory_.NewCallback( |
1079 &BrowserRenderProcessHost::OpenPhishingModelDone)); | 978 &BrowserRenderProcessHost::OpenPhishingModelDone)); |
1080 } | 979 } |
1081 } | 980 } |
1082 | 981 |
1083 void BrowserRenderProcessHost::OpenPhishingModelDone( | 982 void BrowserRenderProcessHost::OpenPhishingModelDone( |
1084 base::PlatformFile model_file) { | 983 base::PlatformFile model_file) { |
1085 if (model_file != base::kInvalidPlatformFileValue) { | 984 if (model_file != base::kInvalidPlatformFileValue) { |
1086 IPC::PlatformFileForTransit file; | 985 IPC::PlatformFileForTransit file; |
1087 #if defined(OS_POSIX) | 986 #if defined(OS_POSIX) |
1088 file = base::FileDescriptor(model_file, false); | 987 file = base::FileDescriptor(model_file, false); |
1089 #elif defined(OS_WIN) | 988 #elif defined(OS_WIN) |
1090 ::DuplicateHandle(::GetCurrentProcess(), model_file, GetHandle(), &file, 0, | 989 ::DuplicateHandle(::GetCurrentProcess(), model_file, GetHandle(), &file, 0, |
1091 false, DUPLICATE_SAME_ACCESS); | 990 false, DUPLICATE_SAME_ACCESS); |
1092 #endif | 991 #endif |
1093 Send(new SafeBrowsingMsg_SetPhishingModel(file)); | 992 Send(new SafeBrowsingMsg_SetPhishingModel(file)); |
1094 } | 993 } |
1095 } | 994 } |
OLD | NEW |