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_impl.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_message_filter.h" | 88 #include "content/browser/mime_registry_message_filter.h" |
88 #include "content/browser/mojo/constants.h" | 89 #include "content/browser/mojo/constants.h" |
89 #include "content/browser/mojo/mojo_application_host.h" | 90 #include "content/browser/mojo/mojo_application_host.h" |
90 #include "content/browser/mojo/mojo_child_connection.h" | 91 #include "content/browser/mojo/mojo_child_connection.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 #include "content/common/child_process_host_impl.h" | 126 #include "content/common/child_process_host_impl.h" |
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/mojo_shell_connection_impl.h" | 132 #include "content/common/mojo/mojo_shell_connection_impl.h" |
132 #include "content/common/render_process_messages.h" | 133 #include "content/common/render_process_messages.h" |
133 #include "content/common/resource_messages.h" | 134 #include "content/common/resource_messages.h" |
134 #include "content/common/site_isolation_policy.h" | 135 #include "content/common/site_isolation_policy.h" |
| 136 #include "content/common/url_loader_factory.mojom.h" |
135 #include "content/common/view_messages.h" | 137 #include "content/common/view_messages.h" |
136 #include "content/public/browser/browser_context.h" | 138 #include "content/public/browser/browser_context.h" |
137 #include "content/public/browser/browser_thread.h" | 139 #include "content/public/browser/browser_thread.h" |
138 #include "content/public/browser/content_browser_client.h" | 140 #include "content/public/browser/content_browser_client.h" |
139 #include "content/public/browser/notification_service.h" | 141 #include "content/public/browser/notification_service.h" |
140 #include "content/public/browser/notification_types.h" | 142 #include "content/public/browser/notification_types.h" |
141 #include "content/public/browser/render_process_host_factory.h" | 143 #include "content/public/browser/render_process_host_factory.h" |
142 #include "content/public/browser/render_process_host_observer.h" | 144 #include "content/public/browser/render_process_host_observer.h" |
143 #include "content/public/browser/render_widget_host.h" | 145 #include "content/public/browser/render_widget_host.h" |
144 #include "content/public/browser/render_widget_host_iterator.h" | 146 #include "content/public/browser/render_widget_host_iterator.h" |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 std::string UintVectorToString(const std::vector<unsigned>& vector) { | 442 std::string UintVectorToString(const std::vector<unsigned>& vector) { |
441 std::string str; | 443 std::string str; |
442 for (auto it : vector) { | 444 for (auto it : vector) { |
443 if (!str.empty()) | 445 if (!str.empty()) |
444 str += ","; | 446 str += ","; |
445 str += base::UintToString(it); | 447 str += base::UintToString(it); |
446 } | 448 } |
447 return str; | 449 return str; |
448 } | 450 } |
449 | 451 |
| 452 void Noop(scoped_refptr<ResourceMessageFilter> unused) { |
| 453 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 454 } |
| 455 |
450 } // namespace | 456 } // namespace |
451 | 457 |
452 RendererMainThreadFactoryFunction g_renderer_main_thread_factory = NULL; | 458 RendererMainThreadFactoryFunction g_renderer_main_thread_factory = NULL; |
453 | 459 |
454 base::MessageLoop* g_in_process_thread; | 460 base::MessageLoop* g_in_process_thread; |
455 | 461 |
456 base::MessageLoop* | 462 base::MessageLoop* |
457 RenderProcessHostImpl::GetInProcessRendererThreadForTesting() { | 463 RenderProcessHostImpl::GetInProcessRendererThreadForTesting() { |
458 return g_in_process_thread; | 464 return g_in_process_thread; |
459 } | 465 } |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 << "in-process."; | 627 << "in-process."; |
622 } | 628 } |
623 } | 629 } |
624 | 630 |
625 void RenderProcessHostImpl::RegisterRendererMainThreadFactory( | 631 void RenderProcessHostImpl::RegisterRendererMainThreadFactory( |
626 RendererMainThreadFactoryFunction create) { | 632 RendererMainThreadFactoryFunction create) { |
627 g_renderer_main_thread_factory = create; | 633 g_renderer_main_thread_factory = create; |
628 } | 634 } |
629 | 635 |
630 RenderProcessHostImpl::~RenderProcessHostImpl() { | 636 RenderProcessHostImpl::~RenderProcessHostImpl() { |
| 637 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
631 #ifndef NDEBUG | 638 #ifndef NDEBUG |
632 DCHECK(is_self_deleted_) | 639 DCHECK(is_self_deleted_) |
633 << "RenderProcessHostImpl is destroyed by something other than itself"; | 640 << "RenderProcessHostImpl is destroyed by something other than itself"; |
634 #endif | 641 #endif |
635 | 642 |
636 // Make sure to clean up the in-process renderer before the channel, otherwise | 643 // Make sure to clean up the in-process renderer before the channel, otherwise |
637 // it may still run and have its IPCs fail, causing asserts. | 644 // it may still run and have its IPCs fail, causing asserts. |
638 in_process_renderer_.reset(); | 645 in_process_renderer_.reset(); |
639 | 646 |
640 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); | 647 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
850 GetStoragePartition()->GetMediaURLRequestContext()); | 857 GetStoragePartition()->GetMediaURLRequestContext()); |
851 | 858 |
852 ResourceMessageFilter::GetContextsCallback get_contexts_callback( | 859 ResourceMessageFilter::GetContextsCallback get_contexts_callback( |
853 base::Bind(&GetContexts, browser_context->GetResourceContext(), | 860 base::Bind(&GetContexts, browser_context->GetResourceContext(), |
854 request_context, media_request_context)); | 861 request_context, media_request_context)); |
855 | 862 |
856 // Several filters need the Blob storage context, so fetch it in advance. | 863 // Several filters need the Blob storage context, so fetch it in advance. |
857 scoped_refptr<ChromeBlobStorageContext> blob_storage_context = | 864 scoped_refptr<ChromeBlobStorageContext> blob_storage_context = |
858 ChromeBlobStorageContext::GetFor(browser_context); | 865 ChromeBlobStorageContext::GetFor(browser_context); |
859 | 866 |
860 ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter( | 867 resource_message_filter_ = new ResourceMessageFilter( |
861 GetID(), PROCESS_TYPE_RENDERER, | 868 GetID(), PROCESS_TYPE_RENDERER, |
862 storage_partition_impl_->GetAppCacheService(), | 869 storage_partition_impl_->GetAppCacheService(), blob_storage_context.get(), |
863 blob_storage_context.get(), | |
864 storage_partition_impl_->GetFileSystemContext(), | 870 storage_partition_impl_->GetFileSystemContext(), |
865 storage_partition_impl_->GetServiceWorkerContext(), | 871 storage_partition_impl_->GetServiceWorkerContext(), |
866 storage_partition_impl_->GetHostZoomLevelContext(), | 872 storage_partition_impl_->GetHostZoomLevelContext(), |
867 get_contexts_callback); | 873 get_contexts_callback); |
868 | 874 |
869 AddFilter(resource_message_filter); | 875 AddFilter(resource_message_filter_.get()); |
| 876 |
870 MediaStreamManager* media_stream_manager = | 877 MediaStreamManager* media_stream_manager = |
871 BrowserMainLoop::GetInstance()->media_stream_manager(); | 878 BrowserMainLoop::GetInstance()->media_stream_manager(); |
872 // The AudioInputRendererHost and AudioRendererHost needs to be available for | 879 // The AudioInputRendererHost and AudioRendererHost needs to be available for |
873 // lookup, so it's stashed in a member variable. | 880 // lookup, so it's stashed in a member variable. |
874 audio_input_renderer_host_ = new AudioInputRendererHost( | 881 audio_input_renderer_host_ = new AudioInputRendererHost( |
875 GetID(), base::GetProcId(GetHandle()), audio_manager, | 882 GetID(), base::GetProcId(GetHandle()), audio_manager, |
876 media_stream_manager, AudioMirroringManager::GetInstance(), | 883 media_stream_manager, AudioMirroringManager::GetInstance(), |
877 BrowserMainLoop::GetInstance()->user_input_monitor()); | 884 BrowserMainLoop::GetInstance()->user_input_monitor()); |
878 AddFilter(audio_input_renderer_host_.get()); | 885 AddFilter(audio_input_renderer_host_.get()); |
879 audio_renderer_host_ = new AudioRendererHost( | 886 audio_renderer_host_ = new AudioRendererHost( |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 | 1051 |
1045 mojo_application_host_->service_registry()->AddService( | 1052 mojo_application_host_->service_registry()->AddService( |
1046 base::Bind(&RenderProcessHostImpl::CreateStoragePartitionService, | 1053 base::Bind(&RenderProcessHostImpl::CreateStoragePartitionService, |
1047 base::Unretained(this))); | 1054 base::Unretained(this))); |
1048 | 1055 |
1049 #if defined(OS_ANDROID) | 1056 #if defined(OS_ANDROID) |
1050 ServiceRegistrarAndroid::RegisterProcessHostServices( | 1057 ServiceRegistrarAndroid::RegisterProcessHostServices( |
1051 mojo_application_host_->service_registry_android()); | 1058 mojo_application_host_->service_registry_android()); |
1052 #endif | 1059 #endif |
1053 | 1060 |
| 1061 mojo_application_host_->service_registry()->AddService(base::Bind( |
| 1062 &RenderProcessHostImpl::CreateURLLoaderFactory, base::Unretained(this))); |
| 1063 |
1054 GetContentClient()->browser()->RegisterRenderProcessMojoServices( | 1064 GetContentClient()->browser()->RegisterRenderProcessMojoServices( |
1055 mojo_application_host_->service_registry()); | 1065 mojo_application_host_->service_registry()); |
1056 } | 1066 } |
1057 | 1067 |
1058 void RenderProcessHostImpl::CreateStoragePartitionService( | 1068 void RenderProcessHostImpl::CreateStoragePartitionService( |
1059 mojo::InterfaceRequest<mojom::StoragePartitionService> request) { | 1069 mojo::InterfaceRequest<mojom::StoragePartitionService> request) { |
1060 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! | 1070 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! |
1061 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1071 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
1062 switches::kMojoLocalStorage)) { | 1072 switches::kMojoLocalStorage)) { |
1063 storage_partition_impl_->Bind(std::move(request)); | 1073 storage_partition_impl_->Bind(std::move(request)); |
1064 } | 1074 } |
1065 } | 1075 } |
1066 | 1076 |
| 1077 void RenderProcessHostImpl::CreateURLLoaderFactory( |
| 1078 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) { |
| 1079 url_loader_factory_.reset( |
| 1080 new URLLoaderFactoryImpl(resource_message_filter_, std::move(request))); |
| 1081 } |
| 1082 |
1067 int RenderProcessHostImpl::GetNextRoutingID() { | 1083 int RenderProcessHostImpl::GetNextRoutingID() { |
1068 return widget_helper_->GetNextRoutingID(); | 1084 return widget_helper_->GetNextRoutingID(); |
1069 } | 1085 } |
1070 | 1086 |
1071 void RenderProcessHostImpl::ResumeDeferredNavigation( | 1087 void RenderProcessHostImpl::ResumeDeferredNavigation( |
1072 const GlobalRequestID& request_id) { | 1088 const GlobalRequestID& request_id) { |
1073 widget_helper_->ResumeDeferredNavigation(request_id); | 1089 widget_helper_->ResumeDeferredNavigation(request_id); |
1074 } | 1090 } |
1075 | 1091 |
1076 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { | 1092 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { |
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1794 | 1810 |
1795 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { | 1811 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { |
1796 ignore_input_events_ = ignore_input_events; | 1812 ignore_input_events_ = ignore_input_events; |
1797 } | 1813 } |
1798 | 1814 |
1799 bool RenderProcessHostImpl::IgnoreInputEvents() const { | 1815 bool RenderProcessHostImpl::IgnoreInputEvents() const { |
1800 return ignore_input_events_; | 1816 return ignore_input_events_; |
1801 } | 1817 } |
1802 | 1818 |
1803 void RenderProcessHostImpl::Cleanup() { | 1819 void RenderProcessHostImpl::Cleanup() { |
| 1820 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1804 // If within_process_died_observer_ is true, one of our observers performed an | 1821 // If within_process_died_observer_ is true, one of our observers performed an |
1805 // action that caused us to die (e.g. http://crbug.com/339504). Therefore, | 1822 // action that caused us to die (e.g. http://crbug.com/339504). Therefore, |
1806 // delay the destruction until all of the observer callbacks have been made, | 1823 // delay the destruction until all of the observer callbacks have been made, |
1807 // and guarantee that the RenderProcessHostDestroyed observer callback is | 1824 // and guarantee that the RenderProcessHostDestroyed observer callback is |
1808 // always the last callback fired. | 1825 // always the last callback fired. |
1809 if (within_process_died_observer_) { | 1826 if (within_process_died_observer_) { |
1810 delayed_cleanup_needed_ = true; | 1827 delayed_cleanup_needed_ = true; |
1811 return; | 1828 return; |
1812 } | 1829 } |
1813 delayed_cleanup_needed_ = false; | 1830 delayed_cleanup_needed_ = false; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1873 | 1890 |
1874 // It's important not to wait for the DeleteTask to delete the channel | 1891 // It's important not to wait for the DeleteTask to delete the channel |
1875 // proxy. Kill it off now. That way, in case the profile is going away, the | 1892 // proxy. Kill it off now. That way, in case the profile is going away, the |
1876 // rest of the objects attached to this RenderProcessHost start going | 1893 // rest of the objects attached to this RenderProcessHost start going |
1877 // away first, since deleting the channel proxy will post a | 1894 // away first, since deleting the channel proxy will post a |
1878 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. | 1895 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. |
1879 channel_.reset(); | 1896 channel_.reset(); |
1880 | 1897 |
1881 // The following members should be cleared in ProcessDied() as well! | 1898 // The following members should be cleared in ProcessDied() as well! |
1882 message_port_message_filter_ = NULL; | 1899 message_port_message_filter_ = NULL; |
| 1900 url_loader_factory_ = nullptr; |
| 1901 // We need to destruct the filter on the IO thread. |
| 1902 BrowserThread::PostTask( |
| 1903 BrowserThread::IO, FROM_HERE, |
| 1904 base::Bind(&Noop, std::move(resource_message_filter_))); |
1883 | 1905 |
1884 RemoveUserData(kSessionStorageHolderKey); | 1906 RemoveUserData(kSessionStorageHolderKey); |
1885 | 1907 |
1886 // On shutdown, |this| may not be deleted because the deleter is posted to | 1908 // On shutdown, |this| may not be deleted because the deleter is posted to |
1887 // the current MessageLoop, but MessageLoop deletes all its pending | 1909 // the current MessageLoop, but MessageLoop deletes all its pending |
1888 // callbacks on shutdown. Since the deleter takes |this| as a raw pointer, | 1910 // callbacks on shutdown. Since the deleter takes |this| as a raw pointer, |
1889 // deleting the callback doesn't delete |this| resulting in a memory leak. | 1911 // deleting the callback doesn't delete |this| resulting in a memory leak. |
1890 // Valgrind complains, so delete |mojo_application_host_| explicitly here to | 1912 // Valgrind complains, so delete |mojo_application_host_| explicitly here to |
1891 // stop valgrind from complaining. | 1913 // stop valgrind from complaining. |
1892 mojo_application_host_.reset(); | 1914 mojo_application_host_.reset(); |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2390 | 2412 |
2391 within_process_died_observer_ = true; | 2413 within_process_died_observer_ = true; |
2392 NotificationService::current()->Notify( | 2414 NotificationService::current()->Notify( |
2393 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), | 2415 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), |
2394 Details<RendererClosedDetails>(&details)); | 2416 Details<RendererClosedDetails>(&details)); |
2395 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, | 2417 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, |
2396 RenderProcessExited(this, status, exit_code)); | 2418 RenderProcessExited(this, status, exit_code)); |
2397 within_process_died_observer_ = false; | 2419 within_process_died_observer_ = false; |
2398 | 2420 |
2399 message_port_message_filter_ = NULL; | 2421 message_port_message_filter_ = NULL; |
| 2422 url_loader_factory_ = nullptr; |
| 2423 // We need to destruct the filter on the IO thread. |
| 2424 BrowserThread::PostTask( |
| 2425 BrowserThread::IO, FROM_HERE, |
| 2426 base::Bind(&Noop, std::move(resource_message_filter_))); |
2400 RemoveUserData(kSessionStorageHolderKey); | 2427 RemoveUserData(kSessionStorageHolderKey); |
2401 | 2428 |
2402 IDMap<IPC::Listener>::iterator iter(&listeners_); | 2429 IDMap<IPC::Listener>::iterator iter(&listeners_); |
2403 while (!iter.IsAtEnd()) { | 2430 while (!iter.IsAtEnd()) { |
2404 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( | 2431 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( |
2405 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); | 2432 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); |
2406 iter.Advance(); | 2433 iter.Advance(); |
2407 } | 2434 } |
2408 | 2435 |
2409 // It's possible that one of the calls out to the observers might have caused | 2436 // 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... |
2761 | 2788 |
2762 // Skip widgets in other processes. | 2789 // Skip widgets in other processes. |
2763 if (rvh->GetProcess()->GetID() != GetID()) | 2790 if (rvh->GetProcess()->GetID() != GetID()) |
2764 continue; | 2791 continue; |
2765 | 2792 |
2766 rvh->OnWebkitPreferencesChanged(); | 2793 rvh->OnWebkitPreferencesChanged(); |
2767 } | 2794 } |
2768 } | 2795 } |
2769 | 2796 |
2770 } // namespace content | 2797 } // namespace content |
OLD | NEW |