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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 69 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
70 #include "content/browser/gpu/compositor_util.h" | 70 #include "content/browser/gpu/compositor_util.h" |
71 #include "content/browser/gpu/gpu_data_manager_impl.h" | 71 #include "content/browser/gpu/gpu_data_manager_impl.h" |
72 #include "content/browser/gpu/gpu_process_host.h" | 72 #include "content/browser/gpu/gpu_process_host.h" |
73 #include "content/browser/gpu/shader_disk_cache.h" | 73 #include "content/browser/gpu/shader_disk_cache.h" |
74 #include "content/browser/histogram_message_filter.h" | 74 #include "content/browser/histogram_message_filter.h" |
75 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 75 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
76 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" | 76 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" |
77 #include "content/browser/loader/resource_message_filter.h" | 77 #include "content/browser/loader/resource_message_filter.h" |
78 #include "content/browser/loader/resource_scheduler_filter.h" | 78 #include "content/browser/loader/resource_scheduler_filter.h" |
| 79 #include "content/browser/loader/url_loader_factory_holder.h" |
79 #include "content/browser/media/capture/audio_mirroring_manager.h" | 80 #include "content/browser/media/capture/audio_mirroring_manager.h" |
80 #include "content/browser/media/capture/image_capture_impl.h" | 81 #include "content/browser/media/capture/image_capture_impl.h" |
81 #include "content/browser/media/media_internals.h" | 82 #include "content/browser/media/media_internals.h" |
82 #include "content/browser/media/midi_host.h" | 83 #include "content/browser/media/midi_host.h" |
83 #include "content/browser/memory/memory_message_filter.h" | 84 #include "content/browser/memory/memory_message_filter.h" |
84 #include "content/browser/message_port_message_filter.h" | 85 #include "content/browser/message_port_message_filter.h" |
85 #include "content/browser/mime_registry_impl.h" | 86 #include "content/browser/mime_registry_impl.h" |
86 #include "content/browser/mojo/constants.h" | 87 #include "content/browser/mojo/constants.h" |
87 #include "content/browser/mojo/mojo_application_host.h" | 88 #include "content/browser/mojo/mojo_application_host.h" |
88 #include "content/browser/mojo/mojo_child_connection.h" | 89 #include "content/browser/mojo/mojo_child_connection.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 #include "content/common/child_process_host_impl.h" | 125 #include "content/common/child_process_host_impl.h" |
125 #include "content/common/child_process_messages.h" | 126 #include "content/common/child_process_messages.h" |
126 #include "content/common/content_switches_internal.h" | 127 #include "content/common/content_switches_internal.h" |
127 #include "content/common/frame_messages.h" | 128 #include "content/common/frame_messages.h" |
128 #include "content/common/gpu_host_messages.h" | 129 #include "content/common/gpu_host_messages.h" |
129 #include "content/common/in_process_child_thread_params.h" | 130 #include "content/common/in_process_child_thread_params.h" |
130 #include "content/common/mojo/mojo_shell_connection_impl.h" | 131 #include "content/common/mojo/mojo_shell_connection_impl.h" |
131 #include "content/common/render_process_messages.h" | 132 #include "content/common/render_process_messages.h" |
132 #include "content/common/resource_messages.h" | 133 #include "content/common/resource_messages.h" |
133 #include "content/common/site_isolation_policy.h" | 134 #include "content/common/site_isolation_policy.h" |
| 135 #include "content/common/url_loader_factory.mojom.h" |
134 #include "content/common/view_messages.h" | 136 #include "content/common/view_messages.h" |
135 #include "content/public/browser/browser_context.h" | 137 #include "content/public/browser/browser_context.h" |
136 #include "content/public/browser/browser_thread.h" | 138 #include "content/public/browser/browser_thread.h" |
137 #include "content/public/browser/content_browser_client.h" | 139 #include "content/public/browser/content_browser_client.h" |
138 #include "content/public/browser/notification_service.h" | 140 #include "content/public/browser/notification_service.h" |
139 #include "content/public/browser/notification_types.h" | 141 #include "content/public/browser/notification_types.h" |
140 #include "content/public/browser/render_process_host_factory.h" | 142 #include "content/public/browser/render_process_host_factory.h" |
141 #include "content/public/browser/render_process_host_observer.h" | 143 #include "content/public/browser/render_process_host_observer.h" |
142 #include "content/public/browser/render_widget_host.h" | 144 #include "content/public/browser/render_widget_host.h" |
143 #include "content/public/browser/render_widget_host_iterator.h" | 145 #include "content/public/browser/render_widget_host_iterator.h" |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 << "in-process."; | 643 << "in-process."; |
642 } | 644 } |
643 } | 645 } |
644 | 646 |
645 void RenderProcessHostImpl::RegisterRendererMainThreadFactory( | 647 void RenderProcessHostImpl::RegisterRendererMainThreadFactory( |
646 RendererMainThreadFactoryFunction create) { | 648 RendererMainThreadFactoryFunction create) { |
647 g_renderer_main_thread_factory = create; | 649 g_renderer_main_thread_factory = create; |
648 } | 650 } |
649 | 651 |
650 RenderProcessHostImpl::~RenderProcessHostImpl() { | 652 RenderProcessHostImpl::~RenderProcessHostImpl() { |
| 653 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
651 #ifndef NDEBUG | 654 #ifndef NDEBUG |
652 DCHECK(is_self_deleted_) | 655 DCHECK(is_self_deleted_) |
653 << "RenderProcessHostImpl is destroyed by something other than itself"; | 656 << "RenderProcessHostImpl is destroyed by something other than itself"; |
654 #endif | 657 #endif |
655 | 658 |
656 // Make sure to clean up the in-process renderer before the channel, otherwise | 659 // Make sure to clean up the in-process renderer before the channel, otherwise |
657 // it may still run and have its IPCs fail, causing asserts. | 660 // it may still run and have its IPCs fail, causing asserts. |
658 in_process_renderer_.reset(); | 661 in_process_renderer_.reset(); |
659 | 662 |
660 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); | 663 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 GetStoragePartition()->GetMediaURLRequestContext()); | 869 GetStoragePartition()->GetMediaURLRequestContext()); |
867 | 870 |
868 ResourceMessageFilter::GetContextsCallback get_contexts_callback( | 871 ResourceMessageFilter::GetContextsCallback get_contexts_callback( |
869 base::Bind(&GetContexts, browser_context->GetResourceContext(), | 872 base::Bind(&GetContexts, browser_context->GetResourceContext(), |
870 request_context, media_request_context)); | 873 request_context, media_request_context)); |
871 | 874 |
872 // Several filters need the Blob storage context, so fetch it in advance. | 875 // Several filters need the Blob storage context, so fetch it in advance. |
873 scoped_refptr<ChromeBlobStorageContext> blob_storage_context = | 876 scoped_refptr<ChromeBlobStorageContext> blob_storage_context = |
874 ChromeBlobStorageContext::GetFor(browser_context); | 877 ChromeBlobStorageContext::GetFor(browser_context); |
875 | 878 |
876 ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter( | 879 resource_message_filter_ = new ResourceMessageFilter( |
877 GetID(), PROCESS_TYPE_RENDERER, | 880 GetID(), PROCESS_TYPE_RENDERER, |
878 storage_partition_impl_->GetAppCacheService(), | 881 storage_partition_impl_->GetAppCacheService(), blob_storage_context.get(), |
879 blob_storage_context.get(), | |
880 storage_partition_impl_->GetFileSystemContext(), | 882 storage_partition_impl_->GetFileSystemContext(), |
881 storage_partition_impl_->GetServiceWorkerContext(), | 883 storage_partition_impl_->GetServiceWorkerContext(), |
882 storage_partition_impl_->GetHostZoomLevelContext(), | 884 storage_partition_impl_->GetHostZoomLevelContext(), |
883 get_contexts_callback); | 885 get_contexts_callback); |
884 | 886 |
885 AddFilter(resource_message_filter); | 887 AddFilter(resource_message_filter_.get()); |
| 888 |
886 MediaStreamManager* media_stream_manager = | 889 MediaStreamManager* media_stream_manager = |
887 BrowserMainLoop::GetInstance()->media_stream_manager(); | 890 BrowserMainLoop::GetInstance()->media_stream_manager(); |
888 // The AudioInputRendererHost and AudioRendererHost needs to be available for | 891 // The AudioInputRendererHost and AudioRendererHost needs to be available for |
889 // lookup, so it's stashed in a member variable. | 892 // lookup, so it's stashed in a member variable. |
890 audio_input_renderer_host_ = new AudioInputRendererHost( | 893 audio_input_renderer_host_ = new AudioInputRendererHost( |
891 GetID(), base::GetProcId(GetHandle()), audio_manager, | 894 GetID(), base::GetProcId(GetHandle()), audio_manager, |
892 media_stream_manager, AudioMirroringManager::GetInstance(), | 895 media_stream_manager, AudioMirroringManager::GetInstance(), |
893 BrowserMainLoop::GetInstance()->user_input_monitor()); | 896 BrowserMainLoop::GetInstance()->user_input_monitor()); |
894 AddFilter(audio_input_renderer_host_.get()); | 897 AddFilter(audio_input_renderer_host_.get()); |
895 audio_renderer_host_ = new AudioRendererHost( | 898 audio_renderer_host_ = new AudioRendererHost( |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 | 1090 |
1088 mojo_application_host_->service_registry()->AddService( | 1091 mojo_application_host_->service_registry()->AddService( |
1089 base::Bind(&MimeRegistryImpl::Create), | 1092 base::Bind(&MimeRegistryImpl::Create), |
1090 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); | 1093 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
1091 | 1094 |
1092 #if defined(OS_ANDROID) | 1095 #if defined(OS_ANDROID) |
1093 ServiceRegistrarAndroid::RegisterProcessHostServices( | 1096 ServiceRegistrarAndroid::RegisterProcessHostServices( |
1094 mojo_application_host_->service_registry_android()); | 1097 mojo_application_host_->service_registry_android()); |
1095 #endif | 1098 #endif |
1096 | 1099 |
| 1100 mojo_application_host_->service_registry()->AddService(base::Bind( |
| 1101 &RenderProcessHostImpl::CreateURLLoaderFactory, base::Unretained(this))); |
| 1102 |
1097 GetContentClient()->browser()->RegisterRenderProcessMojoServices( | 1103 GetContentClient()->browser()->RegisterRenderProcessMojoServices( |
1098 mojo_application_host_->service_registry()); | 1104 mojo_application_host_->service_registry()); |
1099 } | 1105 } |
1100 | 1106 |
1101 void RenderProcessHostImpl::CreateStoragePartitionService( | 1107 void RenderProcessHostImpl::CreateStoragePartitionService( |
1102 mojo::InterfaceRequest<mojom::StoragePartitionService> request) { | 1108 mojo::InterfaceRequest<mojom::StoragePartitionService> request) { |
1103 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! | 1109 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! |
1104 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1110 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
1105 switches::kMojoLocalStorage)) { | 1111 switches::kMojoLocalStorage)) { |
1106 storage_partition_impl_->Bind(std::move(request)); | 1112 storage_partition_impl_->Bind(std::move(request)); |
1107 } | 1113 } |
1108 } | 1114 } |
1109 | 1115 |
| 1116 void RenderProcessHostImpl::CreateURLLoaderFactory( |
| 1117 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) { |
| 1118 url_loader_factory_holder_.reset( |
| 1119 new URLLoaderFactoryHolder(resource_message_filter_, std::move(request))); |
| 1120 } |
| 1121 |
1110 int RenderProcessHostImpl::GetNextRoutingID() { | 1122 int RenderProcessHostImpl::GetNextRoutingID() { |
1111 return widget_helper_->GetNextRoutingID(); | 1123 return widget_helper_->GetNextRoutingID(); |
1112 } | 1124 } |
1113 | 1125 |
1114 void RenderProcessHostImpl::ResumeDeferredNavigation( | 1126 void RenderProcessHostImpl::ResumeDeferredNavigation( |
1115 const GlobalRequestID& request_id) { | 1127 const GlobalRequestID& request_id) { |
1116 widget_helper_->ResumeDeferredNavigation(request_id); | 1128 widget_helper_->ResumeDeferredNavigation(request_id); |
1117 } | 1129 } |
1118 | 1130 |
1119 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { | 1131 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { |
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1815 | 1827 |
1816 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { | 1828 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { |
1817 ignore_input_events_ = ignore_input_events; | 1829 ignore_input_events_ = ignore_input_events; |
1818 } | 1830 } |
1819 | 1831 |
1820 bool RenderProcessHostImpl::IgnoreInputEvents() const { | 1832 bool RenderProcessHostImpl::IgnoreInputEvents() const { |
1821 return ignore_input_events_; | 1833 return ignore_input_events_; |
1822 } | 1834 } |
1823 | 1835 |
1824 void RenderProcessHostImpl::Cleanup() { | 1836 void RenderProcessHostImpl::Cleanup() { |
| 1837 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1825 // Keep the one renderer thread around forever in single process mode. | 1838 // Keep the one renderer thread around forever in single process mode. |
1826 if (run_renderer_in_process()) | 1839 if (run_renderer_in_process()) |
1827 return; | 1840 return; |
1828 | 1841 |
1829 // If within_process_died_observer_ is true, one of our observers performed an | 1842 // If within_process_died_observer_ is true, one of our observers performed an |
1830 // action that caused us to die (e.g. http://crbug.com/339504). Therefore, | 1843 // action that caused us to die (e.g. http://crbug.com/339504). Therefore, |
1831 // delay the destruction until all of the observer callbacks have been made, | 1844 // delay the destruction until all of the observer callbacks have been made, |
1832 // and guarantee that the RenderProcessHostDestroyed observer callback is | 1845 // and guarantee that the RenderProcessHostDestroyed observer callback is |
1833 // always the last callback fired. | 1846 // always the last callback fired. |
1834 if (within_process_died_observer_) { | 1847 if (within_process_died_observer_) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1898 | 1911 |
1899 // It's important not to wait for the DeleteTask to delete the channel | 1912 // It's important not to wait for the DeleteTask to delete the channel |
1900 // proxy. Kill it off now. That way, in case the profile is going away, the | 1913 // proxy. Kill it off now. That way, in case the profile is going away, the |
1901 // rest of the objects attached to this RenderProcessHost start going | 1914 // rest of the objects attached to this RenderProcessHost start going |
1902 // away first, since deleting the channel proxy will post a | 1915 // away first, since deleting the channel proxy will post a |
1903 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. | 1916 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. |
1904 channel_.reset(); | 1917 channel_.reset(); |
1905 | 1918 |
1906 // The following members should be cleared in ProcessDied() as well! | 1919 // The following members should be cleared in ProcessDied() as well! |
1907 message_port_message_filter_ = NULL; | 1920 message_port_message_filter_ = NULL; |
| 1921 url_loader_factory_holder_ = nullptr; |
1908 | 1922 |
1909 RemoveUserData(kSessionStorageHolderKey); | 1923 RemoveUserData(kSessionStorageHolderKey); |
1910 | 1924 |
1911 // On shutdown, |this| may not be deleted because the deleter is posted to | 1925 // On shutdown, |this| may not be deleted because the deleter is posted to |
1912 // the current MessageLoop, but MessageLoop deletes all its pending | 1926 // the current MessageLoop, but MessageLoop deletes all its pending |
1913 // callbacks on shutdown. Since the deleter takes |this| as a raw pointer, | 1927 // callbacks on shutdown. Since the deleter takes |this| as a raw pointer, |
1914 // deleting the callback doesn't delete |this| resulting in a memory leak. | 1928 // deleting the callback doesn't delete |this| resulting in a memory leak. |
1915 // Valgrind complains, so delete |mojo_application_host_| explicitly here to | 1929 // Valgrind complains, so delete |mojo_application_host_| explicitly here to |
1916 // stop valgrind from complaining. | 1930 // stop valgrind from complaining. |
1917 mojo_application_host_.reset(); | 1931 mojo_application_host_.reset(); |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2421 | 2435 |
2422 within_process_died_observer_ = true; | 2436 within_process_died_observer_ = true; |
2423 NotificationService::current()->Notify( | 2437 NotificationService::current()->Notify( |
2424 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), | 2438 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), |
2425 Details<RendererClosedDetails>(&details)); | 2439 Details<RendererClosedDetails>(&details)); |
2426 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, | 2440 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, |
2427 RenderProcessExited(this, status, exit_code)); | 2441 RenderProcessExited(this, status, exit_code)); |
2428 within_process_died_observer_ = false; | 2442 within_process_died_observer_ = false; |
2429 | 2443 |
2430 message_port_message_filter_ = NULL; | 2444 message_port_message_filter_ = NULL; |
| 2445 url_loader_factory_holder_ = nullptr; |
2431 RemoveUserData(kSessionStorageHolderKey); | 2446 RemoveUserData(kSessionStorageHolderKey); |
2432 | 2447 |
2433 IDMap<IPC::Listener>::iterator iter(&listeners_); | 2448 IDMap<IPC::Listener>::iterator iter(&listeners_); |
2434 while (!iter.IsAtEnd()) { | 2449 while (!iter.IsAtEnd()) { |
2435 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( | 2450 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( |
2436 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); | 2451 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); |
2437 iter.Advance(); | 2452 iter.Advance(); |
2438 } | 2453 } |
2439 | 2454 |
2440 // It's possible that one of the calls out to the observers might have caused | 2455 // It's possible that one of the calls out to the observers might have caused |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2793 | 2808 |
2794 // Skip widgets in other processes. | 2809 // Skip widgets in other processes. |
2795 if (rvh->GetProcess()->GetID() != GetID()) | 2810 if (rvh->GetProcess()->GetID() != GetID()) |
2796 continue; | 2811 continue; |
2797 | 2812 |
2798 rvh->OnWebkitPreferencesChanged(); | 2813 rvh->OnWebkitPreferencesChanged(); |
2799 } | 2814 } |
2800 } | 2815 } |
2801 | 2816 |
2802 } // namespace content | 2817 } // namespace content |
OLD | NEW |