| 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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 << "in-process."; | 654 << "in-process."; |
| 653 } | 655 } |
| 654 } | 656 } |
| 655 | 657 |
| 656 void RenderProcessHostImpl::RegisterRendererMainThreadFactory( | 658 void RenderProcessHostImpl::RegisterRendererMainThreadFactory( |
| 657 RendererMainThreadFactoryFunction create) { | 659 RendererMainThreadFactoryFunction create) { |
| 658 g_renderer_main_thread_factory = create; | 660 g_renderer_main_thread_factory = create; |
| 659 } | 661 } |
| 660 | 662 |
| 661 RenderProcessHostImpl::~RenderProcessHostImpl() { | 663 RenderProcessHostImpl::~RenderProcessHostImpl() { |
| 664 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 662 #ifndef NDEBUG | 665 #ifndef NDEBUG |
| 663 DCHECK(is_self_deleted_) | 666 DCHECK(is_self_deleted_) |
| 664 << "RenderProcessHostImpl is destroyed by something other than itself"; | 667 << "RenderProcessHostImpl is destroyed by something other than itself"; |
| 665 #endif | 668 #endif |
| 666 | 669 |
| 667 // Make sure to clean up the in-process renderer before the channel, otherwise | 670 // Make sure to clean up the in-process renderer before the channel, otherwise |
| 668 // it may still run and have its IPCs fail, causing asserts. | 671 // it may still run and have its IPCs fail, causing asserts. |
| 669 in_process_renderer_.reset(); | 672 in_process_renderer_.reset(); |
| 670 | 673 |
| 671 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); | 674 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 GetStoragePartition()->GetMediaURLRequestContext()); | 896 GetStoragePartition()->GetMediaURLRequestContext()); |
| 894 | 897 |
| 895 ResourceMessageFilter::GetContextsCallback get_contexts_callback( | 898 ResourceMessageFilter::GetContextsCallback get_contexts_callback( |
| 896 base::Bind(&GetContexts, browser_context->GetResourceContext(), | 899 base::Bind(&GetContexts, browser_context->GetResourceContext(), |
| 897 request_context, media_request_context)); | 900 request_context, media_request_context)); |
| 898 | 901 |
| 899 // Several filters need the Blob storage context, so fetch it in advance. | 902 // Several filters need the Blob storage context, so fetch it in advance. |
| 900 scoped_refptr<ChromeBlobStorageContext> blob_storage_context = | 903 scoped_refptr<ChromeBlobStorageContext> blob_storage_context = |
| 901 ChromeBlobStorageContext::GetFor(browser_context); | 904 ChromeBlobStorageContext::GetFor(browser_context); |
| 902 | 905 |
| 903 ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter( | 906 resource_message_filter_ = new ResourceMessageFilter( |
| 904 GetID(), PROCESS_TYPE_RENDERER, | 907 GetID(), PROCESS_TYPE_RENDERER, |
| 905 storage_partition_impl_->GetAppCacheService(), | 908 storage_partition_impl_->GetAppCacheService(), blob_storage_context.get(), |
| 906 blob_storage_context.get(), | |
| 907 storage_partition_impl_->GetFileSystemContext(), | 909 storage_partition_impl_->GetFileSystemContext(), |
| 908 storage_partition_impl_->GetServiceWorkerContext(), | 910 storage_partition_impl_->GetServiceWorkerContext(), |
| 909 storage_partition_impl_->GetHostZoomLevelContext(), | 911 storage_partition_impl_->GetHostZoomLevelContext(), |
| 910 get_contexts_callback); | 912 get_contexts_callback); |
| 911 | 913 |
| 912 AddFilter(resource_message_filter); | 914 AddFilter(resource_message_filter_.get()); |
| 915 |
| 913 MediaStreamManager* media_stream_manager = | 916 MediaStreamManager* media_stream_manager = |
| 914 BrowserMainLoop::GetInstance()->media_stream_manager(); | 917 BrowserMainLoop::GetInstance()->media_stream_manager(); |
| 915 // The AudioInputRendererHost and AudioRendererHost needs to be available for | 918 // The AudioInputRendererHost and AudioRendererHost needs to be available for |
| 916 // lookup, so it's stashed in a member variable. | 919 // lookup, so it's stashed in a member variable. |
| 917 audio_input_renderer_host_ = new AudioInputRendererHost( | 920 audio_input_renderer_host_ = new AudioInputRendererHost( |
| 918 GetID(), base::GetProcId(GetHandle()), audio_manager, | 921 GetID(), base::GetProcId(GetHandle()), audio_manager, |
| 919 media_stream_manager, AudioMirroringManager::GetInstance(), | 922 media_stream_manager, AudioMirroringManager::GetInstance(), |
| 920 BrowserMainLoop::GetInstance()->user_input_monitor()); | 923 BrowserMainLoop::GetInstance()->user_input_monitor()); |
| 921 AddFilter(audio_input_renderer_host_.get()); | 924 AddFilter(audio_input_renderer_host_.get()); |
| 922 audio_renderer_host_ = new AudioRendererHost( | 925 audio_renderer_host_ = new AudioRendererHost( |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1098 GetInterfaceRegistry()->AddInterface( | 1101 GetInterfaceRegistry()->AddInterface( |
| 1099 base::Bind(&DeviceOrientationHost::Create), io_task_runner); | 1102 base::Bind(&DeviceOrientationHost::Create), io_task_runner); |
| 1100 GetInterfaceRegistry()->AddInterface( | 1103 GetInterfaceRegistry()->AddInterface( |
| 1101 base::Bind(&DeviceOrientationAbsoluteHost::Create), io_task_runner); | 1104 base::Bind(&DeviceOrientationAbsoluteHost::Create), io_task_runner); |
| 1102 | 1105 |
| 1103 #if defined(OS_ANDROID) | 1106 #if defined(OS_ANDROID) |
| 1104 ServiceRegistrarAndroid::RegisterProcessHostServices( | 1107 ServiceRegistrarAndroid::RegisterProcessHostServices( |
| 1105 mojo_child_connection_->service_registry_android()); | 1108 mojo_child_connection_->service_registry_android()); |
| 1106 #endif | 1109 #endif |
| 1107 | 1110 |
| 1111 GetInterfaceRegistry()->AddInterface(base::Bind( |
| 1112 &RenderProcessHostImpl::CreateURLLoaderFactory, base::Unretained(this))); |
| 1113 |
| 1108 GetContentClient()->browser()->ExposeInterfacesToRenderer( | 1114 GetContentClient()->browser()->ExposeInterfacesToRenderer( |
| 1109 GetInterfaceRegistry(), this); | 1115 GetInterfaceRegistry(), this); |
| 1110 } | 1116 } |
| 1111 | 1117 |
| 1112 void RenderProcessHostImpl::CreateStoragePartitionService( | 1118 void RenderProcessHostImpl::CreateStoragePartitionService( |
| 1113 mojo::InterfaceRequest<mojom::StoragePartitionService> request) { | 1119 mojo::InterfaceRequest<mojom::StoragePartitionService> request) { |
| 1114 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! | 1120 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! |
| 1115 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1121 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1116 switches::kMojoLocalStorage)) { | 1122 switches::kMojoLocalStorage)) { |
| 1117 storage_partition_impl_->Bind(std::move(request)); | 1123 storage_partition_impl_->Bind(std::move(request)); |
| 1118 } | 1124 } |
| 1119 } | 1125 } |
| 1120 | 1126 |
| 1127 void RenderProcessHostImpl::CreateURLLoaderFactory( |
| 1128 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) { |
| 1129 url_loader_factory_holder_.reset( |
| 1130 new URLLoaderFactoryHolder(resource_message_filter_, std::move(request))); |
| 1131 } |
| 1132 |
| 1121 int RenderProcessHostImpl::GetNextRoutingID() { | 1133 int RenderProcessHostImpl::GetNextRoutingID() { |
| 1122 return widget_helper_->GetNextRoutingID(); | 1134 return widget_helper_->GetNextRoutingID(); |
| 1123 } | 1135 } |
| 1124 | 1136 |
| 1125 void RenderProcessHostImpl::ResumeDeferredNavigation( | 1137 void RenderProcessHostImpl::ResumeDeferredNavigation( |
| 1126 const GlobalRequestID& request_id) { | 1138 const GlobalRequestID& request_id) { |
| 1127 widget_helper_->ResumeDeferredNavigation(request_id); | 1139 widget_helper_->ResumeDeferredNavigation(request_id); |
| 1128 } | 1140 } |
| 1129 | 1141 |
| 1130 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { | 1142 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { |
| (...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1857 | 1869 |
| 1858 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { | 1870 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { |
| 1859 ignore_input_events_ = ignore_input_events; | 1871 ignore_input_events_ = ignore_input_events; |
| 1860 } | 1872 } |
| 1861 | 1873 |
| 1862 bool RenderProcessHostImpl::IgnoreInputEvents() const { | 1874 bool RenderProcessHostImpl::IgnoreInputEvents() const { |
| 1863 return ignore_input_events_; | 1875 return ignore_input_events_; |
| 1864 } | 1876 } |
| 1865 | 1877 |
| 1866 void RenderProcessHostImpl::Cleanup() { | 1878 void RenderProcessHostImpl::Cleanup() { |
| 1879 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1867 // Keep the one renderer thread around forever in single process mode. | 1880 // Keep the one renderer thread around forever in single process mode. |
| 1868 if (run_renderer_in_process()) | 1881 if (run_renderer_in_process()) |
| 1869 return; | 1882 return; |
| 1870 | 1883 |
| 1871 // If within_process_died_observer_ is true, one of our observers performed an | 1884 // If within_process_died_observer_ is true, one of our observers performed an |
| 1872 // action that caused us to die (e.g. http://crbug.com/339504). Therefore, | 1885 // action that caused us to die (e.g. http://crbug.com/339504). Therefore, |
| 1873 // delay the destruction until all of the observer callbacks have been made, | 1886 // delay the destruction until all of the observer callbacks have been made, |
| 1874 // and guarantee that the RenderProcessHostDestroyed observer callback is | 1887 // and guarantee that the RenderProcessHostDestroyed observer callback is |
| 1875 // always the last callback fired. | 1888 // always the last callback fired. |
| 1876 if (within_process_died_observer_) { | 1889 if (within_process_died_observer_) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1940 | 1953 |
| 1941 // It's important not to wait for the DeleteTask to delete the channel | 1954 // It's important not to wait for the DeleteTask to delete the channel |
| 1942 // proxy. Kill it off now. That way, in case the profile is going away, the | 1955 // proxy. Kill it off now. That way, in case the profile is going away, the |
| 1943 // rest of the objects attached to this RenderProcessHost start going | 1956 // rest of the objects attached to this RenderProcessHost start going |
| 1944 // away first, since deleting the channel proxy will post a | 1957 // away first, since deleting the channel proxy will post a |
| 1945 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. | 1958 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. |
| 1946 channel_.reset(); | 1959 channel_.reset(); |
| 1947 | 1960 |
| 1948 // The following members should be cleared in ProcessDied() as well! | 1961 // The following members should be cleared in ProcessDied() as well! |
| 1949 message_port_message_filter_ = NULL; | 1962 message_port_message_filter_ = NULL; |
| 1963 url_loader_factory_holder_ = nullptr; |
| 1950 | 1964 |
| 1951 RemoveUserData(kSessionStorageHolderKey); | 1965 RemoveUserData(kSessionStorageHolderKey); |
| 1952 | 1966 |
| 1953 // Remove ourself from the list of renderer processes so that we can't be | 1967 // Remove ourself from the list of renderer processes so that we can't be |
| 1954 // reused in between now and when the Delete task runs. | 1968 // reused in between now and when the Delete task runs. |
| 1955 UnregisterHost(GetID()); | 1969 UnregisterHost(GetID()); |
| 1956 } | 1970 } |
| 1957 } | 1971 } |
| 1958 | 1972 |
| 1959 void RenderProcessHostImpl::AddPendingView() { | 1973 void RenderProcessHostImpl::AddPendingView() { |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2458 | 2472 |
| 2459 within_process_died_observer_ = true; | 2473 within_process_died_observer_ = true; |
| 2460 NotificationService::current()->Notify( | 2474 NotificationService::current()->Notify( |
| 2461 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), | 2475 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), |
| 2462 Details<RendererClosedDetails>(&details)); | 2476 Details<RendererClosedDetails>(&details)); |
| 2463 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, | 2477 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, |
| 2464 RenderProcessExited(this, status, exit_code)); | 2478 RenderProcessExited(this, status, exit_code)); |
| 2465 within_process_died_observer_ = false; | 2479 within_process_died_observer_ = false; |
| 2466 | 2480 |
| 2467 message_port_message_filter_ = NULL; | 2481 message_port_message_filter_ = NULL; |
| 2482 url_loader_factory_holder_ = nullptr; |
| 2468 RemoveUserData(kSessionStorageHolderKey); | 2483 RemoveUserData(kSessionStorageHolderKey); |
| 2469 | 2484 |
| 2470 IDMap<IPC::Listener>::iterator iter(&listeners_); | 2485 IDMap<IPC::Listener>::iterator iter(&listeners_); |
| 2471 while (!iter.IsAtEnd()) { | 2486 while (!iter.IsAtEnd()) { |
| 2472 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( | 2487 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( |
| 2473 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); | 2488 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); |
| 2474 iter.Advance(); | 2489 iter.Advance(); |
| 2475 } | 2490 } |
| 2476 | 2491 |
| 2477 // It's possible that one of the calls out to the observers might have caused | 2492 // 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... |
| 2782 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 2797 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
| 2783 | 2798 |
| 2784 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias | 2799 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias |
| 2785 // enough information here so that we can determine what the bad message was. | 2800 // enough information here so that we can determine what the bad message was. |
| 2786 base::debug::Alias(&error); | 2801 base::debug::Alias(&error); |
| 2787 bad_message::ReceivedBadMessage(process.get(), | 2802 bad_message::ReceivedBadMessage(process.get(), |
| 2788 bad_message::RPH_MOJO_PROCESS_ERROR); | 2803 bad_message::RPH_MOJO_PROCESS_ERROR); |
| 2789 } | 2804 } |
| 2790 | 2805 |
| 2791 } // namespace content | 2806 } // namespace content |
| OLD | NEW |