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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 70 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
71 #include "content/browser/gpu/compositor_util.h" | 71 #include "content/browser/gpu/compositor_util.h" |
72 #include "content/browser/gpu/gpu_data_manager_impl.h" | 72 #include "content/browser/gpu/gpu_data_manager_impl.h" |
73 #include "content/browser/gpu/gpu_process_host.h" | 73 #include "content/browser/gpu/gpu_process_host.h" |
74 #include "content/browser/gpu/shader_disk_cache.h" | 74 #include "content/browser/gpu/shader_disk_cache.h" |
75 #include "content/browser/histogram_message_filter.h" | 75 #include "content/browser/histogram_message_filter.h" |
76 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 76 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
77 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" | 77 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" |
78 #include "content/browser/loader/resource_message_filter.h" | 78 #include "content/browser/loader/resource_message_filter.h" |
79 #include "content/browser/loader/resource_scheduler_filter.h" | 79 #include "content/browser/loader/resource_scheduler_filter.h" |
| 80 #include "content/browser/loader/url_loader_factory_impl.h" |
80 #include "content/browser/media/capture/audio_mirroring_manager.h" | 81 #include "content/browser/media/capture/audio_mirroring_manager.h" |
81 #include "content/browser/media/capture/image_capture_impl.h" | 82 #include "content/browser/media/capture/image_capture_impl.h" |
82 #include "content/browser/media/media_internals.h" | 83 #include "content/browser/media/media_internals.h" |
83 #include "content/browser/media/midi_host.h" | 84 #include "content/browser/media/midi_host.h" |
84 #include "content/browser/memory/memory_message_filter.h" | 85 #include "content/browser/memory/memory_message_filter.h" |
85 #include "content/browser/message_port_message_filter.h" | 86 #include "content/browser/message_port_message_filter.h" |
86 #include "content/browser/mime_registry_message_filter.h" | 87 #include "content/browser/mime_registry_message_filter.h" |
87 #include "content/browser/mojo/constants.h" | 88 #include "content/browser/mojo/constants.h" |
88 #include "content/browser/mojo/mojo_application_host.h" | 89 #include "content/browser/mojo/mojo_application_host.h" |
89 #include "content/browser/mojo/mojo_child_connection.h" | 90 #include "content/browser/mojo/mojo_child_connection.h" |
(...skipping 34 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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 GetStoragePartition()->GetMediaURLRequestContext()); | 871 GetStoragePartition()->GetMediaURLRequestContext()); |
869 | 872 |
870 ResourceMessageFilter::GetContextsCallback get_contexts_callback( | 873 ResourceMessageFilter::GetContextsCallback get_contexts_callback( |
871 base::Bind(&GetContexts, browser_context->GetResourceContext(), | 874 base::Bind(&GetContexts, browser_context->GetResourceContext(), |
872 request_context, media_request_context)); | 875 request_context, media_request_context)); |
873 | 876 |
874 // Several filters need the Blob storage context, so fetch it in advance. | 877 // Several filters need the Blob storage context, so fetch it in advance. |
875 scoped_refptr<ChromeBlobStorageContext> blob_storage_context = | 878 scoped_refptr<ChromeBlobStorageContext> blob_storage_context = |
876 ChromeBlobStorageContext::GetFor(browser_context); | 879 ChromeBlobStorageContext::GetFor(browser_context); |
877 | 880 |
878 ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter( | 881 resource_message_filter_ = new ResourceMessageFilter( |
879 GetID(), PROCESS_TYPE_RENDERER, | 882 GetID(), PROCESS_TYPE_RENDERER, |
880 storage_partition_impl_->GetAppCacheService(), | 883 storage_partition_impl_->GetAppCacheService(), blob_storage_context.get(), |
881 blob_storage_context.get(), | |
882 storage_partition_impl_->GetFileSystemContext(), | 884 storage_partition_impl_->GetFileSystemContext(), |
883 storage_partition_impl_->GetServiceWorkerContext(), | 885 storage_partition_impl_->GetServiceWorkerContext(), |
884 storage_partition_impl_->GetHostZoomLevelContext(), | 886 storage_partition_impl_->GetHostZoomLevelContext(), |
885 get_contexts_callback); | 887 get_contexts_callback); |
886 | 888 |
887 AddFilter(resource_message_filter); | 889 AddFilter(resource_message_filter_.get()); |
| 890 |
888 MediaStreamManager* media_stream_manager = | 891 MediaStreamManager* media_stream_manager = |
889 BrowserMainLoop::GetInstance()->media_stream_manager(); | 892 BrowserMainLoop::GetInstance()->media_stream_manager(); |
890 // The AudioInputRendererHost and AudioRendererHost needs to be available for | 893 // The AudioInputRendererHost and AudioRendererHost needs to be available for |
891 // lookup, so it's stashed in a member variable. | 894 // lookup, so it's stashed in a member variable. |
892 audio_input_renderer_host_ = new AudioInputRendererHost( | 895 audio_input_renderer_host_ = new AudioInputRendererHost( |
893 GetID(), base::GetProcId(GetHandle()), audio_manager, | 896 GetID(), base::GetProcId(GetHandle()), audio_manager, |
894 media_stream_manager, AudioMirroringManager::GetInstance(), | 897 media_stream_manager, AudioMirroringManager::GetInstance(), |
895 BrowserMainLoop::GetInstance()->user_input_monitor()); | 898 BrowserMainLoop::GetInstance()->user_input_monitor()); |
896 AddFilter(audio_input_renderer_host_.get()); | 899 AddFilter(audio_input_renderer_host_.get()); |
897 audio_renderer_host_ = new AudioRendererHost( | 900 audio_renderer_host_ = new AudioRendererHost( |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 | 1095 |
1093 mojo_application_host_->service_registry()->AddService( | 1096 mojo_application_host_->service_registry()->AddService( |
1094 base::Bind(&RenderProcessHostImpl::CreateStoragePartitionService, | 1097 base::Bind(&RenderProcessHostImpl::CreateStoragePartitionService, |
1095 base::Unretained(this))); | 1098 base::Unretained(this))); |
1096 | 1099 |
1097 #if defined(OS_ANDROID) | 1100 #if defined(OS_ANDROID) |
1098 ServiceRegistrarAndroid::RegisterProcessHostServices( | 1101 ServiceRegistrarAndroid::RegisterProcessHostServices( |
1099 mojo_application_host_->service_registry_android()); | 1102 mojo_application_host_->service_registry_android()); |
1100 #endif | 1103 #endif |
1101 | 1104 |
| 1105 mojo_application_host_->service_registry()->AddService(base::Bind( |
| 1106 &RenderProcessHostImpl::CreateURLLoaderFactory, base::Unretained(this))); |
| 1107 |
1102 GetContentClient()->browser()->RegisterRenderProcessMojoServices( | 1108 GetContentClient()->browser()->RegisterRenderProcessMojoServices( |
1103 mojo_application_host_->service_registry()); | 1109 mojo_application_host_->service_registry()); |
1104 } | 1110 } |
1105 | 1111 |
1106 void RenderProcessHostImpl::CreateStoragePartitionService( | 1112 void RenderProcessHostImpl::CreateStoragePartitionService( |
1107 mojo::InterfaceRequest<mojom::StoragePartitionService> request) { | 1113 mojo::InterfaceRequest<mojom::StoragePartitionService> request) { |
1108 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! | 1114 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! |
1109 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1115 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
1110 switches::kMojoLocalStorage)) { | 1116 switches::kMojoLocalStorage)) { |
1111 storage_partition_impl_->Bind(std::move(request)); | 1117 storage_partition_impl_->Bind(std::move(request)); |
1112 } | 1118 } |
1113 } | 1119 } |
1114 | 1120 |
| 1121 void RenderProcessHostImpl::CreateURLLoaderFactory( |
| 1122 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) { |
| 1123 url_loader_factory_.reset( |
| 1124 new URLLoaderFactoryImpl(resource_message_filter_, std::move(request))); |
| 1125 } |
| 1126 |
1115 int RenderProcessHostImpl::GetNextRoutingID() { | 1127 int RenderProcessHostImpl::GetNextRoutingID() { |
1116 return widget_helper_->GetNextRoutingID(); | 1128 return widget_helper_->GetNextRoutingID(); |
1117 } | 1129 } |
1118 | 1130 |
1119 void RenderProcessHostImpl::ResumeDeferredNavigation( | 1131 void RenderProcessHostImpl::ResumeDeferredNavigation( |
1120 const GlobalRequestID& request_id) { | 1132 const GlobalRequestID& request_id) { |
1121 widget_helper_->ResumeDeferredNavigation(request_id); | 1133 widget_helper_->ResumeDeferredNavigation(request_id); |
1122 } | 1134 } |
1123 | 1135 |
1124 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { | 1136 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1819 | 1831 |
1820 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { | 1832 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { |
1821 ignore_input_events_ = ignore_input_events; | 1833 ignore_input_events_ = ignore_input_events; |
1822 } | 1834 } |
1823 | 1835 |
1824 bool RenderProcessHostImpl::IgnoreInputEvents() const { | 1836 bool RenderProcessHostImpl::IgnoreInputEvents() const { |
1825 return ignore_input_events_; | 1837 return ignore_input_events_; |
1826 } | 1838 } |
1827 | 1839 |
1828 void RenderProcessHostImpl::Cleanup() { | 1840 void RenderProcessHostImpl::Cleanup() { |
| 1841 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
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_) { |
1835 delayed_cleanup_needed_ = true; | 1848 delayed_cleanup_needed_ = true; |
1836 return; | 1849 return; |
1837 } | 1850 } |
1838 delayed_cleanup_needed_ = false; | 1851 delayed_cleanup_needed_ = false; |
(...skipping 59 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_ = 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_ = 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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2792 | 2807 |
2793 // Skip widgets in other processes. | 2808 // Skip widgets in other processes. |
2794 if (rvh->GetProcess()->GetID() != GetID()) | 2809 if (rvh->GetProcess()->GetID() != GetID()) |
2795 continue; | 2810 continue; |
2796 | 2811 |
2797 rvh->OnWebkitPreferencesChanged(); | 2812 rvh->OnWebkitPreferencesChanged(); |
2798 } | 2813 } |
2799 } | 2814 } |
2800 | 2815 |
2801 } // namespace content | 2816 } // namespace content |
OLD | NEW |