OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/render_process_host_impl.h" | 8 #include "content/browser/renderer_host/render_process_host_impl.h" |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 71 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
72 #include "content/browser/gpu/compositor_util.h" | 72 #include "content/browser/gpu/compositor_util.h" |
73 #include "content/browser/gpu/gpu_data_manager_impl.h" | 73 #include "content/browser/gpu/gpu_data_manager_impl.h" |
74 #include "content/browser/gpu/gpu_process_host.h" | 74 #include "content/browser/gpu/gpu_process_host.h" |
75 #include "content/browser/gpu/shader_disk_cache.h" | 75 #include "content/browser/gpu/shader_disk_cache.h" |
76 #include "content/browser/histogram_message_filter.h" | 76 #include "content/browser/histogram_message_filter.h" |
77 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 77 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
78 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" | 78 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" |
79 #include "content/browser/loader/resource_message_filter.h" | 79 #include "content/browser/loader/resource_message_filter.h" |
80 #include "content/browser/loader/resource_scheduler_filter.h" | 80 #include "content/browser/loader/resource_scheduler_filter.h" |
| 81 #include "content/browser/loader/url_loader_factory_holder.h" |
81 #include "content/browser/media/capture/audio_mirroring_manager.h" | 82 #include "content/browser/media/capture/audio_mirroring_manager.h" |
82 #include "content/browser/media/capture/image_capture_impl.h" | 83 #include "content/browser/media/capture/image_capture_impl.h" |
83 #include "content/browser/media/media_internals.h" | 84 #include "content/browser/media/media_internals.h" |
84 #include "content/browser/media/midi_host.h" | 85 #include "content/browser/media/midi_host.h" |
85 #include "content/browser/memory/memory_message_filter.h" | 86 #include "content/browser/memory/memory_message_filter.h" |
86 #include "content/browser/message_port_message_filter.h" | 87 #include "content/browser/message_port_message_filter.h" |
87 #include "content/browser/mime_registry_impl.h" | 88 #include "content/browser/mime_registry_impl.h" |
88 #include "content/browser/mojo/mojo_child_connection.h" | 89 #include "content/browser/mojo/mojo_child_connection.h" |
89 #include "content/browser/notifications/notification_message_filter.h" | 90 #include "content/browser/notifications/notification_message_filter.h" |
90 #include "content/browser/notifications/platform_notification_context_impl.h" | 91 #include "content/browser/notifications/platform_notification_context_impl.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 #include "content/common/child_process_messages.h" | 127 #include "content/common/child_process_messages.h" |
127 #include "content/common/content_switches_internal.h" | 128 #include "content/common/content_switches_internal.h" |
128 #include "content/common/frame_messages.h" | 129 #include "content/common/frame_messages.h" |
129 #include "content/common/gpu_host_messages.h" | 130 #include "content/common/gpu_host_messages.h" |
130 #include "content/common/in_process_child_thread_params.h" | 131 #include "content/common/in_process_child_thread_params.h" |
131 #include "content/common/mojo/constants.h" | 132 #include "content/common/mojo/constants.h" |
132 #include "content/common/mojo/mojo_shell_connection_impl.h" | 133 #include "content/common/mojo/mojo_shell_connection_impl.h" |
133 #include "content/common/render_process_messages.h" | 134 #include "content/common/render_process_messages.h" |
134 #include "content/common/resource_messages.h" | 135 #include "content/common/resource_messages.h" |
135 #include "content/common/site_isolation_policy.h" | 136 #include "content/common/site_isolation_policy.h" |
| 137 #include "content/common/url_loader_factory.mojom.h" |
136 #include "content/common/view_messages.h" | 138 #include "content/common/view_messages.h" |
137 #include "content/public/browser/browser_context.h" | 139 #include "content/public/browser/browser_context.h" |
138 #include "content/public/browser/browser_thread.h" | 140 #include "content/public/browser/browser_thread.h" |
139 #include "content/public/browser/content_browser_client.h" | 141 #include "content/public/browser/content_browser_client.h" |
140 #include "content/public/browser/notification_service.h" | 142 #include "content/public/browser/notification_service.h" |
141 #include "content/public/browser/notification_types.h" | 143 #include "content/public/browser/notification_types.h" |
142 #include "content/public/browser/render_process_host_factory.h" | 144 #include "content/public/browser/render_process_host_factory.h" |
143 #include "content/public/browser/render_process_host_observer.h" | 145 #include "content/public/browser/render_process_host_observer.h" |
144 #include "content/public/browser/render_widget_host.h" | 146 #include "content/public/browser/render_widget_host.h" |
145 #include "content/public/browser/render_widget_host_iterator.h" | 147 #include "content/public/browser/render_widget_host_iterator.h" |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 << "in-process."; | 708 << "in-process."; |
707 } | 709 } |
708 } | 710 } |
709 | 711 |
710 void RenderProcessHostImpl::RegisterRendererMainThreadFactory( | 712 void RenderProcessHostImpl::RegisterRendererMainThreadFactory( |
711 RendererMainThreadFactoryFunction create) { | 713 RendererMainThreadFactoryFunction create) { |
712 g_renderer_main_thread_factory = create; | 714 g_renderer_main_thread_factory = create; |
713 } | 715 } |
714 | 716 |
715 RenderProcessHostImpl::~RenderProcessHostImpl() { | 717 RenderProcessHostImpl::~RenderProcessHostImpl() { |
| 718 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
716 #ifndef NDEBUG | 719 #ifndef NDEBUG |
717 DCHECK(is_self_deleted_) | 720 DCHECK(is_self_deleted_) |
718 << "RenderProcessHostImpl is destroyed by something other than itself"; | 721 << "RenderProcessHostImpl is destroyed by something other than itself"; |
719 #endif | 722 #endif |
720 | 723 |
721 // Make sure to clean up the in-process renderer before the channel, otherwise | 724 // Make sure to clean up the in-process renderer before the channel, otherwise |
722 // it may still run and have its IPCs fail, causing asserts. | 725 // it may still run and have its IPCs fail, causing asserts. |
723 in_process_renderer_.reset(); | 726 in_process_renderer_.reset(); |
724 | 727 |
725 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); | 728 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 GetStoragePartition()->GetMediaURLRequestContext()); | 954 GetStoragePartition()->GetMediaURLRequestContext()); |
952 | 955 |
953 ResourceMessageFilter::GetContextsCallback get_contexts_callback( | 956 ResourceMessageFilter::GetContextsCallback get_contexts_callback( |
954 base::Bind(&GetContexts, browser_context->GetResourceContext(), | 957 base::Bind(&GetContexts, browser_context->GetResourceContext(), |
955 request_context, media_request_context)); | 958 request_context, media_request_context)); |
956 | 959 |
957 // Several filters need the Blob storage context, so fetch it in advance. | 960 // Several filters need the Blob storage context, so fetch it in advance. |
958 scoped_refptr<ChromeBlobStorageContext> blob_storage_context = | 961 scoped_refptr<ChromeBlobStorageContext> blob_storage_context = |
959 ChromeBlobStorageContext::GetFor(browser_context); | 962 ChromeBlobStorageContext::GetFor(browser_context); |
960 | 963 |
961 ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter( | 964 resource_message_filter_ = new ResourceMessageFilter( |
962 GetID(), PROCESS_TYPE_RENDERER, | 965 GetID(), PROCESS_TYPE_RENDERER, |
963 storage_partition_impl_->GetAppCacheService(), | 966 storage_partition_impl_->GetAppCacheService(), blob_storage_context.get(), |
964 blob_storage_context.get(), | |
965 storage_partition_impl_->GetFileSystemContext(), | 967 storage_partition_impl_->GetFileSystemContext(), |
966 storage_partition_impl_->GetServiceWorkerContext(), | 968 storage_partition_impl_->GetServiceWorkerContext(), |
967 storage_partition_impl_->GetHostZoomLevelContext(), | 969 storage_partition_impl_->GetHostZoomLevelContext(), |
968 get_contexts_callback); | 970 get_contexts_callback); |
969 | 971 |
970 AddFilter(resource_message_filter); | 972 AddFilter(resource_message_filter_.get()); |
| 973 |
971 MediaStreamManager* media_stream_manager = | 974 MediaStreamManager* media_stream_manager = |
972 BrowserMainLoop::GetInstance()->media_stream_manager(); | 975 BrowserMainLoop::GetInstance()->media_stream_manager(); |
973 // The AudioInputRendererHost and AudioRendererHost needs to be available for | 976 // The AudioInputRendererHost and AudioRendererHost needs to be available for |
974 // lookup, so it's stashed in a member variable. | 977 // lookup, so it's stashed in a member variable. |
975 audio_input_renderer_host_ = new AudioInputRendererHost( | 978 audio_input_renderer_host_ = new AudioInputRendererHost( |
976 GetID(), base::GetProcId(GetHandle()), audio_manager, | 979 GetID(), base::GetProcId(GetHandle()), audio_manager, |
977 media_stream_manager, AudioMirroringManager::GetInstance(), | 980 media_stream_manager, AudioMirroringManager::GetInstance(), |
978 BrowserMainLoop::GetInstance()->user_input_monitor()); | 981 BrowserMainLoop::GetInstance()->user_input_monitor()); |
979 AddFilter(audio_input_renderer_host_.get()); | 982 AddFilter(audio_input_renderer_host_.get()); |
980 audio_renderer_host_ = new AudioRendererHost( | 983 audio_renderer_host_ = new AudioRendererHost( |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1163 | 1166 |
1164 // This is to support usage of WebSockets in cases in which there is no | 1167 // This is to support usage of WebSockets in cases in which there is no |
1165 // associated RenderFrame (e.g., Shared Workers). | 1168 // associated RenderFrame (e.g., Shared Workers). |
1166 registry->AddInterface( | 1169 registry->AddInterface( |
1167 base::Bind(&WebSocketManager::CreateWebSocket, GetID(), MSG_ROUTING_NONE), | 1170 base::Bind(&WebSocketManager::CreateWebSocket, GetID(), MSG_ROUTING_NONE), |
1168 ui_task_runner); | 1171 ui_task_runner); |
1169 | 1172 |
1170 GetContentClient()->browser()->ExposeInterfacesToRenderer(registry.get(), | 1173 GetContentClient()->browser()->ExposeInterfacesToRenderer(registry.get(), |
1171 this); | 1174 this); |
1172 | 1175 |
| 1176 registry->AddInterface(base::Bind( |
| 1177 &RenderProcessHostImpl::CreateURLLoaderFactory, base::Unretained(this))); |
| 1178 |
1173 MojoShellConnection* mojo_shell_connection = | 1179 MojoShellConnection* mojo_shell_connection = |
1174 BrowserContext::GetMojoShellConnectionFor(browser_context_); | 1180 BrowserContext::GetMojoShellConnectionFor(browser_context_); |
1175 std::unique_ptr<ConnectionFilterImpl> connection_filter( | 1181 std::unique_ptr<ConnectionFilterImpl> connection_filter( |
1176 new ConnectionFilterImpl(mojo_child_connection_->child_identity(), | 1182 new ConnectionFilterImpl(mojo_child_connection_->child_identity(), |
1177 std::move(registry))); | 1183 std::move(registry))); |
1178 connection_filter_ = connection_filter.get(); | 1184 connection_filter_ = connection_filter.get(); |
1179 mojo_shell_connection->AddConnectionFilter(std::move(connection_filter)); | 1185 mojo_shell_connection->AddConnectionFilter(std::move(connection_filter)); |
1180 } | 1186 } |
1181 | 1187 |
1182 void RenderProcessHostImpl::CreateStoragePartitionService( | 1188 void RenderProcessHostImpl::CreateStoragePartitionService( |
1183 mojo::InterfaceRequest<mojom::StoragePartitionService> request) { | 1189 mojo::InterfaceRequest<mojom::StoragePartitionService> request) { |
1184 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! | 1190 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! |
1185 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1191 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
1186 switches::kMojoLocalStorage)) { | 1192 switches::kMojoLocalStorage)) { |
1187 storage_partition_impl_->Bind(std::move(request)); | 1193 storage_partition_impl_->Bind(std::move(request)); |
1188 } | 1194 } |
1189 } | 1195 } |
1190 | 1196 |
| 1197 void RenderProcessHostImpl::CreateURLLoaderFactory( |
| 1198 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) { |
| 1199 url_loader_factory_holder_.reset( |
| 1200 new URLLoaderFactoryHolder(resource_message_filter_, std::move(request))); |
| 1201 } |
| 1202 |
1191 int RenderProcessHostImpl::GetNextRoutingID() { | 1203 int RenderProcessHostImpl::GetNextRoutingID() { |
1192 return widget_helper_->GetNextRoutingID(); | 1204 return widget_helper_->GetNextRoutingID(); |
1193 } | 1205 } |
1194 | 1206 |
1195 void RenderProcessHostImpl::ResumeDeferredNavigation( | 1207 void RenderProcessHostImpl::ResumeDeferredNavigation( |
1196 const GlobalRequestID& request_id) { | 1208 const GlobalRequestID& request_id) { |
1197 widget_helper_->ResumeDeferredNavigation(request_id); | 1209 widget_helper_->ResumeDeferredNavigation(request_id); |
1198 } | 1210 } |
1199 | 1211 |
1200 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { | 1212 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { |
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1909 | 1921 |
1910 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { | 1922 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { |
1911 ignore_input_events_ = ignore_input_events; | 1923 ignore_input_events_ = ignore_input_events; |
1912 } | 1924 } |
1913 | 1925 |
1914 bool RenderProcessHostImpl::IgnoreInputEvents() const { | 1926 bool RenderProcessHostImpl::IgnoreInputEvents() const { |
1915 return ignore_input_events_; | 1927 return ignore_input_events_; |
1916 } | 1928 } |
1917 | 1929 |
1918 void RenderProcessHostImpl::Cleanup() { | 1930 void RenderProcessHostImpl::Cleanup() { |
| 1931 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1919 // Keep the one renderer thread around forever in single process mode. | 1932 // Keep the one renderer thread around forever in single process mode. |
1920 if (run_renderer_in_process()) | 1933 if (run_renderer_in_process()) |
1921 return; | 1934 return; |
1922 | 1935 |
1923 // If within_process_died_observer_ is true, one of our observers performed an | 1936 // If within_process_died_observer_ is true, one of our observers performed an |
1924 // action that caused us to die (e.g. http://crbug.com/339504). Therefore, | 1937 // action that caused us to die (e.g. http://crbug.com/339504). Therefore, |
1925 // delay the destruction until all of the observer callbacks have been made, | 1938 // delay the destruction until all of the observer callbacks have been made, |
1926 // and guarantee that the RenderProcessHostDestroyed observer callback is | 1939 // and guarantee that the RenderProcessHostDestroyed observer callback is |
1927 // always the last callback fired. | 1940 // always the last callback fired. |
1928 if (within_process_died_observer_) { | 1941 if (within_process_died_observer_) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1999 | 2012 |
2000 // It's important not to wait for the DeleteTask to delete the channel | 2013 // It's important not to wait for the DeleteTask to delete the channel |
2001 // proxy. Kill it off now. That way, in case the profile is going away, the | 2014 // proxy. Kill it off now. That way, in case the profile is going away, the |
2002 // rest of the objects attached to this RenderProcessHost start going | 2015 // rest of the objects attached to this RenderProcessHost start going |
2003 // away first, since deleting the channel proxy will post a | 2016 // away first, since deleting the channel proxy will post a |
2004 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. | 2017 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. |
2005 channel_.reset(); | 2018 channel_.reset(); |
2006 | 2019 |
2007 // The following members should be cleared in ProcessDied() as well! | 2020 // The following members should be cleared in ProcessDied() as well! |
2008 message_port_message_filter_ = NULL; | 2021 message_port_message_filter_ = NULL; |
| 2022 url_loader_factory_holder_ = nullptr; |
2009 | 2023 |
2010 RemoveUserData(kSessionStorageHolderKey); | 2024 RemoveUserData(kSessionStorageHolderKey); |
2011 | 2025 |
2012 // Remove ourself from the list of renderer processes so that we can't be | 2026 // Remove ourself from the list of renderer processes so that we can't be |
2013 // reused in between now and when the Delete task runs. | 2027 // reused in between now and when the Delete task runs. |
2014 UnregisterHost(GetID()); | 2028 UnregisterHost(GetID()); |
2015 } | 2029 } |
2016 } | 2030 } |
2017 | 2031 |
2018 void RenderProcessHostImpl::AddPendingView() { | 2032 void RenderProcessHostImpl::AddPendingView() { |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2504 | 2518 |
2505 within_process_died_observer_ = true; | 2519 within_process_died_observer_ = true; |
2506 NotificationService::current()->Notify( | 2520 NotificationService::current()->Notify( |
2507 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), | 2521 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), |
2508 Details<RendererClosedDetails>(&details)); | 2522 Details<RendererClosedDetails>(&details)); |
2509 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, | 2523 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, |
2510 RenderProcessExited(this, status, exit_code)); | 2524 RenderProcessExited(this, status, exit_code)); |
2511 within_process_died_observer_ = false; | 2525 within_process_died_observer_ = false; |
2512 | 2526 |
2513 message_port_message_filter_ = NULL; | 2527 message_port_message_filter_ = NULL; |
| 2528 url_loader_factory_holder_ = nullptr; |
2514 RemoveUserData(kSessionStorageHolderKey); | 2529 RemoveUserData(kSessionStorageHolderKey); |
2515 | 2530 |
2516 IDMap<IPC::Listener>::iterator iter(&listeners_); | 2531 IDMap<IPC::Listener>::iterator iter(&listeners_); |
2517 while (!iter.IsAtEnd()) { | 2532 while (!iter.IsAtEnd()) { |
2518 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( | 2533 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( |
2519 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); | 2534 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); |
2520 iter.Advance(); | 2535 iter.Advance(); |
2521 } | 2536 } |
2522 | 2537 |
2523 // It's possible that one of the calls out to the observers might have caused | 2538 // It's possible that one of the calls out to the observers might have caused |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2828 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 2843 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
2829 | 2844 |
2830 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias | 2845 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias |
2831 // enough information here so that we can determine what the bad message was. | 2846 // enough information here so that we can determine what the bad message was. |
2832 base::debug::Alias(&error); | 2847 base::debug::Alias(&error); |
2833 bad_message::ReceivedBadMessage(process.get(), | 2848 bad_message::ReceivedBadMessage(process.get(), |
2834 bad_message::RPH_MOJO_PROCESS_ERROR); | 2849 bad_message::RPH_MOJO_PROCESS_ERROR); |
2835 } | 2850 } |
2836 | 2851 |
2837 } // namespace content | 2852 } // namespace content |
OLD | NEW |