| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 68 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
| 69 #include "content/browser/gpu/compositor_util.h" | 69 #include "content/browser/gpu/compositor_util.h" |
| 70 #include "content/browser/gpu/gpu_data_manager_impl.h" | 70 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 71 #include "content/browser/gpu/gpu_process_host.h" | 71 #include "content/browser/gpu/gpu_process_host.h" |
| 72 #include "content/browser/gpu/shader_disk_cache.h" | 72 #include "content/browser/gpu/shader_disk_cache.h" |
| 73 #include "content/browser/histogram_message_filter.h" | 73 #include "content/browser/histogram_message_filter.h" |
| 74 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 74 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 75 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" | 75 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" |
| 76 #include "content/browser/loader/resource_message_filter.h" | 76 #include "content/browser/loader/resource_message_filter.h" |
| 77 #include "content/browser/loader/resource_scheduler_filter.h" | 77 #include "content/browser/loader/resource_scheduler_filter.h" |
| 78 #include "content/browser/loader/url_loader_factory_holder.h" |
| 78 #include "content/browser/media/capture/audio_mirroring_manager.h" | 79 #include "content/browser/media/capture/audio_mirroring_manager.h" |
| 79 #include "content/browser/media/capture/image_capture_impl.h" | 80 #include "content/browser/media/capture/image_capture_impl.h" |
| 80 #include "content/browser/media/media_internals.h" | 81 #include "content/browser/media/media_internals.h" |
| 81 #include "content/browser/media/midi_host.h" | 82 #include "content/browser/media/midi_host.h" |
| 82 #include "content/browser/memory/memory_message_filter.h" | 83 #include "content/browser/memory/memory_message_filter.h" |
| 83 #include "content/browser/message_port_message_filter.h" | 84 #include "content/browser/message_port_message_filter.h" |
| 84 #include "content/browser/mime_registry_impl.h" | 85 #include "content/browser/mime_registry_impl.h" |
| 85 #include "content/browser/mojo/constants.h" | 86 #include "content/browser/mojo/constants.h" |
| 86 #include "content/browser/mojo/mojo_child_connection.h" | 87 #include "content/browser/mojo/mojo_child_connection.h" |
| 87 #include "content/browser/notifications/notification_message_filter.h" | 88 #include "content/browser/notifications/notification_message_filter.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 #include "content/common/child_process_host_impl.h" | 124 #include "content/common/child_process_host_impl.h" |
| 124 #include "content/common/child_process_messages.h" | 125 #include "content/common/child_process_messages.h" |
| 125 #include "content/common/content_switches_internal.h" | 126 #include "content/common/content_switches_internal.h" |
| 126 #include "content/common/frame_messages.h" | 127 #include "content/common/frame_messages.h" |
| 127 #include "content/common/gpu_host_messages.h" | 128 #include "content/common/gpu_host_messages.h" |
| 128 #include "content/common/in_process_child_thread_params.h" | 129 #include "content/common/in_process_child_thread_params.h" |
| 129 #include "content/common/mojo/mojo_shell_connection_impl.h" | 130 #include "content/common/mojo/mojo_shell_connection_impl.h" |
| 130 #include "content/common/render_process_messages.h" | 131 #include "content/common/render_process_messages.h" |
| 131 #include "content/common/resource_messages.h" | 132 #include "content/common/resource_messages.h" |
| 132 #include "content/common/site_isolation_policy.h" | 133 #include "content/common/site_isolation_policy.h" |
| 134 #include "content/common/url_loader_factory.mojom.h" |
| 133 #include "content/common/view_messages.h" | 135 #include "content/common/view_messages.h" |
| 134 #include "content/public/browser/browser_context.h" | 136 #include "content/public/browser/browser_context.h" |
| 135 #include "content/public/browser/browser_thread.h" | 137 #include "content/public/browser/browser_thread.h" |
| 136 #include "content/public/browser/content_browser_client.h" | 138 #include "content/public/browser/content_browser_client.h" |
| 137 #include "content/public/browser/notification_service.h" | 139 #include "content/public/browser/notification_service.h" |
| 138 #include "content/public/browser/notification_types.h" | 140 #include "content/public/browser/notification_types.h" |
| 139 #include "content/public/browser/render_process_host_factory.h" | 141 #include "content/public/browser/render_process_host_factory.h" |
| 140 #include "content/public/browser/render_process_host_observer.h" | 142 #include "content/public/browser/render_process_host_observer.h" |
| 141 #include "content/public/browser/render_widget_host.h" | 143 #include "content/public/browser/render_widget_host.h" |
| 142 #include "content/public/browser/render_widget_host_iterator.h" | 144 #include "content/public/browser/render_widget_host_iterator.h" |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 << "in-process."; | 647 << "in-process."; |
| 646 } | 648 } |
| 647 } | 649 } |
| 648 | 650 |
| 649 void RenderProcessHostImpl::RegisterRendererMainThreadFactory( | 651 void RenderProcessHostImpl::RegisterRendererMainThreadFactory( |
| 650 RendererMainThreadFactoryFunction create) { | 652 RendererMainThreadFactoryFunction create) { |
| 651 g_renderer_main_thread_factory = create; | 653 g_renderer_main_thread_factory = create; |
| 652 } | 654 } |
| 653 | 655 |
| 654 RenderProcessHostImpl::~RenderProcessHostImpl() { | 656 RenderProcessHostImpl::~RenderProcessHostImpl() { |
| 657 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 655 #ifndef NDEBUG | 658 #ifndef NDEBUG |
| 656 DCHECK(is_self_deleted_) | 659 DCHECK(is_self_deleted_) |
| 657 << "RenderProcessHostImpl is destroyed by something other than itself"; | 660 << "RenderProcessHostImpl is destroyed by something other than itself"; |
| 658 #endif | 661 #endif |
| 659 | 662 |
| 660 // Make sure to clean up the in-process renderer before the channel, otherwise | 663 // Make sure to clean up the in-process renderer before the channel, otherwise |
| 661 // it may still run and have its IPCs fail, causing asserts. | 664 // it may still run and have its IPCs fail, causing asserts. |
| 662 in_process_renderer_.reset(); | 665 in_process_renderer_.reset(); |
| 663 | 666 |
| 664 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); | 667 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 GetStoragePartition()->GetMediaURLRequestContext()); | 890 GetStoragePartition()->GetMediaURLRequestContext()); |
| 888 | 891 |
| 889 ResourceMessageFilter::GetContextsCallback get_contexts_callback( | 892 ResourceMessageFilter::GetContextsCallback get_contexts_callback( |
| 890 base::Bind(&GetContexts, browser_context->GetResourceContext(), | 893 base::Bind(&GetContexts, browser_context->GetResourceContext(), |
| 891 request_context, media_request_context)); | 894 request_context, media_request_context)); |
| 892 | 895 |
| 893 // Several filters need the Blob storage context, so fetch it in advance. | 896 // Several filters need the Blob storage context, so fetch it in advance. |
| 894 scoped_refptr<ChromeBlobStorageContext> blob_storage_context = | 897 scoped_refptr<ChromeBlobStorageContext> blob_storage_context = |
| 895 ChromeBlobStorageContext::GetFor(browser_context); | 898 ChromeBlobStorageContext::GetFor(browser_context); |
| 896 | 899 |
| 897 ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter( | 900 resource_message_filter_ = new ResourceMessageFilter( |
| 898 GetID(), PROCESS_TYPE_RENDERER, | 901 GetID(), PROCESS_TYPE_RENDERER, |
| 899 storage_partition_impl_->GetAppCacheService(), | 902 storage_partition_impl_->GetAppCacheService(), blob_storage_context.get(), |
| 900 blob_storage_context.get(), | |
| 901 storage_partition_impl_->GetFileSystemContext(), | 903 storage_partition_impl_->GetFileSystemContext(), |
| 902 storage_partition_impl_->GetServiceWorkerContext(), | 904 storage_partition_impl_->GetServiceWorkerContext(), |
| 903 storage_partition_impl_->GetHostZoomLevelContext(), | 905 storage_partition_impl_->GetHostZoomLevelContext(), |
| 904 get_contexts_callback); | 906 get_contexts_callback); |
| 905 | 907 |
| 906 AddFilter(resource_message_filter); | 908 AddFilter(resource_message_filter_.get()); |
| 909 |
| 907 MediaStreamManager* media_stream_manager = | 910 MediaStreamManager* media_stream_manager = |
| 908 BrowserMainLoop::GetInstance()->media_stream_manager(); | 911 BrowserMainLoop::GetInstance()->media_stream_manager(); |
| 909 // The AudioInputRendererHost and AudioRendererHost needs to be available for | 912 // The AudioInputRendererHost and AudioRendererHost needs to be available for |
| 910 // lookup, so it's stashed in a member variable. | 913 // lookup, so it's stashed in a member variable. |
| 911 audio_input_renderer_host_ = new AudioInputRendererHost( | 914 audio_input_renderer_host_ = new AudioInputRendererHost( |
| 912 GetID(), base::GetProcId(GetHandle()), audio_manager, | 915 GetID(), base::GetProcId(GetHandle()), audio_manager, |
| 913 media_stream_manager, AudioMirroringManager::GetInstance(), | 916 media_stream_manager, AudioMirroringManager::GetInstance(), |
| 914 BrowserMainLoop::GetInstance()->user_input_monitor()); | 917 BrowserMainLoop::GetInstance()->user_input_monitor()); |
| 915 AddFilter(audio_input_renderer_host_.get()); | 918 AddFilter(audio_input_renderer_host_.get()); |
| 916 audio_renderer_host_ = new AudioRendererHost( | 919 audio_renderer_host_ = new AudioRendererHost( |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 GetInterfaceRegistry()->AddInterface( | 1088 GetInterfaceRegistry()->AddInterface( |
| 1086 base::Bind(&DeviceOrientationHost::Create), io_task_runner); | 1089 base::Bind(&DeviceOrientationHost::Create), io_task_runner); |
| 1087 GetInterfaceRegistry()->AddInterface( | 1090 GetInterfaceRegistry()->AddInterface( |
| 1088 base::Bind(&DeviceOrientationAbsoluteHost::Create), io_task_runner); | 1091 base::Bind(&DeviceOrientationAbsoluteHost::Create), io_task_runner); |
| 1089 | 1092 |
| 1090 #if defined(OS_ANDROID) | 1093 #if defined(OS_ANDROID) |
| 1091 ServiceRegistrarAndroid::RegisterProcessHostServices( | 1094 ServiceRegistrarAndroid::RegisterProcessHostServices( |
| 1092 mojo_child_connection_->service_registry_android()); | 1095 mojo_child_connection_->service_registry_android()); |
| 1093 #endif | 1096 #endif |
| 1094 | 1097 |
| 1098 GetInterfaceRegistry()->AddInterface(base::Bind( |
| 1099 &RenderProcessHostImpl::CreateURLLoaderFactory, base::Unretained(this))); |
| 1100 |
| 1095 GetContentClient()->browser()->ExposeInterfacesToRenderer( | 1101 GetContentClient()->browser()->ExposeInterfacesToRenderer( |
| 1096 GetInterfaceRegistry(), this); | 1102 GetInterfaceRegistry(), this); |
| 1097 } | 1103 } |
| 1098 | 1104 |
| 1099 void RenderProcessHostImpl::CreateStoragePartitionService( | 1105 void RenderProcessHostImpl::CreateStoragePartitionService( |
| 1100 mojo::InterfaceRequest<mojom::StoragePartitionService> request) { | 1106 mojo::InterfaceRequest<mojom::StoragePartitionService> request) { |
| 1101 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! | 1107 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! |
| 1102 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1108 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1103 switches::kMojoLocalStorage)) { | 1109 switches::kMojoLocalStorage)) { |
| 1104 storage_partition_impl_->Bind(std::move(request)); | 1110 storage_partition_impl_->Bind(std::move(request)); |
| 1105 } | 1111 } |
| 1106 } | 1112 } |
| 1107 | 1113 |
| 1114 void RenderProcessHostImpl::CreateURLLoaderFactory( |
| 1115 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) { |
| 1116 url_loader_factory_holder_.reset( |
| 1117 new URLLoaderFactoryHolder(resource_message_filter_, std::move(request))); |
| 1118 } |
| 1119 |
| 1108 int RenderProcessHostImpl::GetNextRoutingID() { | 1120 int RenderProcessHostImpl::GetNextRoutingID() { |
| 1109 return widget_helper_->GetNextRoutingID(); | 1121 return widget_helper_->GetNextRoutingID(); |
| 1110 } | 1122 } |
| 1111 | 1123 |
| 1112 void RenderProcessHostImpl::ResumeDeferredNavigation( | 1124 void RenderProcessHostImpl::ResumeDeferredNavigation( |
| 1113 const GlobalRequestID& request_id) { | 1125 const GlobalRequestID& request_id) { |
| 1114 widget_helper_->ResumeDeferredNavigation(request_id); | 1126 widget_helper_->ResumeDeferredNavigation(request_id); |
| 1115 } | 1127 } |
| 1116 | 1128 |
| 1117 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { | 1129 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { |
| (...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1852 | 1864 |
| 1853 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { | 1865 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { |
| 1854 ignore_input_events_ = ignore_input_events; | 1866 ignore_input_events_ = ignore_input_events; |
| 1855 } | 1867 } |
| 1856 | 1868 |
| 1857 bool RenderProcessHostImpl::IgnoreInputEvents() const { | 1869 bool RenderProcessHostImpl::IgnoreInputEvents() const { |
| 1858 return ignore_input_events_; | 1870 return ignore_input_events_; |
| 1859 } | 1871 } |
| 1860 | 1872 |
| 1861 void RenderProcessHostImpl::Cleanup() { | 1873 void RenderProcessHostImpl::Cleanup() { |
| 1874 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1862 // Keep the one renderer thread around forever in single process mode. | 1875 // Keep the one renderer thread around forever in single process mode. |
| 1863 if (run_renderer_in_process()) | 1876 if (run_renderer_in_process()) |
| 1864 return; | 1877 return; |
| 1865 | 1878 |
| 1866 // If within_process_died_observer_ is true, one of our observers performed an | 1879 // If within_process_died_observer_ is true, one of our observers performed an |
| 1867 // action that caused us to die (e.g. http://crbug.com/339504). Therefore, | 1880 // action that caused us to die (e.g. http://crbug.com/339504). Therefore, |
| 1868 // delay the destruction until all of the observer callbacks have been made, | 1881 // delay the destruction until all of the observer callbacks have been made, |
| 1869 // and guarantee that the RenderProcessHostDestroyed observer callback is | 1882 // and guarantee that the RenderProcessHostDestroyed observer callback is |
| 1870 // always the last callback fired. | 1883 // always the last callback fired. |
| 1871 if (within_process_died_observer_) { | 1884 if (within_process_died_observer_) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1935 | 1948 |
| 1936 // It's important not to wait for the DeleteTask to delete the channel | 1949 // It's important not to wait for the DeleteTask to delete the channel |
| 1937 // proxy. Kill it off now. That way, in case the profile is going away, the | 1950 // proxy. Kill it off now. That way, in case the profile is going away, the |
| 1938 // rest of the objects attached to this RenderProcessHost start going | 1951 // rest of the objects attached to this RenderProcessHost start going |
| 1939 // away first, since deleting the channel proxy will post a | 1952 // away first, since deleting the channel proxy will post a |
| 1940 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. | 1953 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. |
| 1941 channel_.reset(); | 1954 channel_.reset(); |
| 1942 | 1955 |
| 1943 // The following members should be cleared in ProcessDied() as well! | 1956 // The following members should be cleared in ProcessDied() as well! |
| 1944 message_port_message_filter_ = NULL; | 1957 message_port_message_filter_ = NULL; |
| 1958 url_loader_factory_holder_ = nullptr; |
| 1945 | 1959 |
| 1946 RemoveUserData(kSessionStorageHolderKey); | 1960 RemoveUserData(kSessionStorageHolderKey); |
| 1947 | 1961 |
| 1948 // Remove ourself from the list of renderer processes so that we can't be | 1962 // Remove ourself from the list of renderer processes so that we can't be |
| 1949 // reused in between now and when the Delete task runs. | 1963 // reused in between now and when the Delete task runs. |
| 1950 UnregisterHost(GetID()); | 1964 UnregisterHost(GetID()); |
| 1951 } | 1965 } |
| 1952 } | 1966 } |
| 1953 | 1967 |
| 1954 void RenderProcessHostImpl::AddPendingView() { | 1968 void RenderProcessHostImpl::AddPendingView() { |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2453 | 2467 |
| 2454 within_process_died_observer_ = true; | 2468 within_process_died_observer_ = true; |
| 2455 NotificationService::current()->Notify( | 2469 NotificationService::current()->Notify( |
| 2456 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), | 2470 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), |
| 2457 Details<RendererClosedDetails>(&details)); | 2471 Details<RendererClosedDetails>(&details)); |
| 2458 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, | 2472 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, |
| 2459 RenderProcessExited(this, status, exit_code)); | 2473 RenderProcessExited(this, status, exit_code)); |
| 2460 within_process_died_observer_ = false; | 2474 within_process_died_observer_ = false; |
| 2461 | 2475 |
| 2462 message_port_message_filter_ = NULL; | 2476 message_port_message_filter_ = NULL; |
| 2477 url_loader_factory_holder_ = nullptr; |
| 2463 RemoveUserData(kSessionStorageHolderKey); | 2478 RemoveUserData(kSessionStorageHolderKey); |
| 2464 | 2479 |
| 2465 IDMap<IPC::Listener>::iterator iter(&listeners_); | 2480 IDMap<IPC::Listener>::iterator iter(&listeners_); |
| 2466 while (!iter.IsAtEnd()) { | 2481 while (!iter.IsAtEnd()) { |
| 2467 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( | 2482 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( |
| 2468 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); | 2483 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); |
| 2469 iter.Advance(); | 2484 iter.Advance(); |
| 2470 } | 2485 } |
| 2471 | 2486 |
| 2472 // It's possible that one of the calls out to the observers might have caused | 2487 // It's possible that one of the calls out to the observers might have caused |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2846 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 2861 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
| 2847 | 2862 |
| 2848 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias | 2863 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias |
| 2849 // enough information here so that we can determine what the bad message was. | 2864 // enough information here so that we can determine what the bad message was. |
| 2850 base::debug::Alias(&error); | 2865 base::debug::Alias(&error); |
| 2851 bad_message::ReceivedBadMessage(process.get(), | 2866 bad_message::ReceivedBadMessage(process.get(), |
| 2852 bad_message::RPH_MOJO_PROCESS_ERROR); | 2867 bad_message::RPH_MOJO_PROCESS_ERROR); |
| 2853 } | 2868 } |
| 2854 | 2869 |
| 2855 } // namespace content | 2870 } // namespace content |
| OLD | NEW |