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 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 << "in-process."; | 621 << "in-process."; |
620 } | 622 } |
621 } | 623 } |
622 | 624 |
623 void RenderProcessHostImpl::RegisterRendererMainThreadFactory( | 625 void RenderProcessHostImpl::RegisterRendererMainThreadFactory( |
624 RendererMainThreadFactoryFunction create) { | 626 RendererMainThreadFactoryFunction create) { |
625 g_renderer_main_thread_factory = create; | 627 g_renderer_main_thread_factory = create; |
626 } | 628 } |
627 | 629 |
628 RenderProcessHostImpl::~RenderProcessHostImpl() { | 630 RenderProcessHostImpl::~RenderProcessHostImpl() { |
| 631 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
629 #ifndef NDEBUG | 632 #ifndef NDEBUG |
630 DCHECK(is_self_deleted_) | 633 DCHECK(is_self_deleted_) |
631 << "RenderProcessHostImpl is destroyed by something other than itself"; | 634 << "RenderProcessHostImpl is destroyed by something other than itself"; |
632 #endif | 635 #endif |
633 | 636 |
634 // Make sure to clean up the in-process renderer before the channel, otherwise | 637 // Make sure to clean up the in-process renderer before the channel, otherwise |
635 // it may still run and have its IPCs fail, causing asserts. | 638 // it may still run and have its IPCs fail, causing asserts. |
636 in_process_renderer_.reset(); | 639 in_process_renderer_.reset(); |
637 | 640 |
638 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); | 641 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 GetStoragePartition()->GetMediaURLRequestContext()); | 851 GetStoragePartition()->GetMediaURLRequestContext()); |
849 | 852 |
850 ResourceMessageFilter::GetContextsCallback get_contexts_callback( | 853 ResourceMessageFilter::GetContextsCallback get_contexts_callback( |
851 base::Bind(&GetContexts, browser_context->GetResourceContext(), | 854 base::Bind(&GetContexts, browser_context->GetResourceContext(), |
852 request_context, media_request_context)); | 855 request_context, media_request_context)); |
853 | 856 |
854 // Several filters need the Blob storage context, so fetch it in advance. | 857 // Several filters need the Blob storage context, so fetch it in advance. |
855 scoped_refptr<ChromeBlobStorageContext> blob_storage_context = | 858 scoped_refptr<ChromeBlobStorageContext> blob_storage_context = |
856 ChromeBlobStorageContext::GetFor(browser_context); | 859 ChromeBlobStorageContext::GetFor(browser_context); |
857 | 860 |
858 ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter( | 861 resource_message_filter_ = new ResourceMessageFilter( |
859 GetID(), PROCESS_TYPE_RENDERER, | 862 GetID(), PROCESS_TYPE_RENDERER, |
860 storage_partition_impl_->GetAppCacheService(), blob_storage_context.get(), | 863 storage_partition_impl_->GetAppCacheService(), blob_storage_context.get(), |
861 storage_partition_impl_->GetFileSystemContext(), | 864 storage_partition_impl_->GetFileSystemContext(), |
862 storage_partition_impl_->GetServiceWorkerContext(), | 865 storage_partition_impl_->GetServiceWorkerContext(), |
863 get_contexts_callback); | 866 get_contexts_callback); |
864 | 867 |
865 AddFilter(resource_message_filter); | 868 AddFilter(resource_message_filter_.get()); |
| 869 |
866 MediaStreamManager* media_stream_manager = | 870 MediaStreamManager* media_stream_manager = |
867 BrowserMainLoop::GetInstance()->media_stream_manager(); | 871 BrowserMainLoop::GetInstance()->media_stream_manager(); |
868 // The AudioInputRendererHost and AudioRendererHost needs to be available for | 872 // The AudioInputRendererHost and AudioRendererHost needs to be available for |
869 // lookup, so it's stashed in a member variable. | 873 // lookup, so it's stashed in a member variable. |
870 audio_input_renderer_host_ = new AudioInputRendererHost( | 874 audio_input_renderer_host_ = new AudioInputRendererHost( |
871 GetID(), base::GetProcId(GetHandle()), audio_manager, | 875 GetID(), base::GetProcId(GetHandle()), audio_manager, |
872 media_stream_manager, AudioMirroringManager::GetInstance(), | 876 media_stream_manager, AudioMirroringManager::GetInstance(), |
873 BrowserMainLoop::GetInstance()->user_input_monitor()); | 877 BrowserMainLoop::GetInstance()->user_input_monitor()); |
874 AddFilter(audio_input_renderer_host_.get()); | 878 AddFilter(audio_input_renderer_host_.get()); |
875 audio_renderer_host_ = new AudioRendererHost( | 879 audio_renderer_host_ = new AudioRendererHost( |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 | 1039 |
1036 mojo_application_host_->service_registry()->AddService( | 1040 mojo_application_host_->service_registry()->AddService( |
1037 base::Bind(&RenderProcessHostImpl::CreateStoragePartitionService, | 1041 base::Bind(&RenderProcessHostImpl::CreateStoragePartitionService, |
1038 base::Unretained(this))); | 1042 base::Unretained(this))); |
1039 | 1043 |
1040 #if defined(OS_ANDROID) | 1044 #if defined(OS_ANDROID) |
1041 ServiceRegistrarAndroid::RegisterProcessHostServices( | 1045 ServiceRegistrarAndroid::RegisterProcessHostServices( |
1042 mojo_application_host_->service_registry_android()); | 1046 mojo_application_host_->service_registry_android()); |
1043 #endif | 1047 #endif |
1044 | 1048 |
| 1049 mojo_application_host_->service_registry()->AddService(base::Bind( |
| 1050 &RenderProcessHostImpl::CreateURLLoaderFactory, base::Unretained(this))); |
| 1051 |
1045 GetContentClient()->browser()->RegisterRenderProcessMojoServices( | 1052 GetContentClient()->browser()->RegisterRenderProcessMojoServices( |
1046 mojo_application_host_->service_registry()); | 1053 mojo_application_host_->service_registry()); |
1047 } | 1054 } |
1048 | 1055 |
1049 void RenderProcessHostImpl::CreateStoragePartitionService( | 1056 void RenderProcessHostImpl::CreateStoragePartitionService( |
1050 mojo::InterfaceRequest<mojom::StoragePartitionService> request) { | 1057 mojo::InterfaceRequest<mojom::StoragePartitionService> request) { |
1051 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! | 1058 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! |
1052 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1059 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
1053 switches::kMojoLocalStorage)) { | 1060 switches::kMojoLocalStorage)) { |
1054 storage_partition_impl_->Bind(std::move(request)); | 1061 storage_partition_impl_->Bind(std::move(request)); |
1055 } | 1062 } |
1056 } | 1063 } |
1057 | 1064 |
| 1065 void RenderProcessHostImpl::CreateURLLoaderFactory( |
| 1066 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) { |
| 1067 url_loader_factory_.reset( |
| 1068 new URLLoaderFactoryImpl(resource_message_filter_, std::move(request))); |
| 1069 } |
| 1070 |
1058 int RenderProcessHostImpl::GetNextRoutingID() { | 1071 int RenderProcessHostImpl::GetNextRoutingID() { |
1059 return widget_helper_->GetNextRoutingID(); | 1072 return widget_helper_->GetNextRoutingID(); |
1060 } | 1073 } |
1061 | 1074 |
1062 void RenderProcessHostImpl::ResumeDeferredNavigation( | 1075 void RenderProcessHostImpl::ResumeDeferredNavigation( |
1063 const GlobalRequestID& request_id) { | 1076 const GlobalRequestID& request_id) { |
1064 widget_helper_->ResumeDeferredNavigation(request_id); | 1077 widget_helper_->ResumeDeferredNavigation(request_id); |
1065 } | 1078 } |
1066 | 1079 |
1067 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { | 1080 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { |
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1794 | 1807 |
1795 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { | 1808 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { |
1796 ignore_input_events_ = ignore_input_events; | 1809 ignore_input_events_ = ignore_input_events; |
1797 } | 1810 } |
1798 | 1811 |
1799 bool RenderProcessHostImpl::IgnoreInputEvents() const { | 1812 bool RenderProcessHostImpl::IgnoreInputEvents() const { |
1800 return ignore_input_events_; | 1813 return ignore_input_events_; |
1801 } | 1814 } |
1802 | 1815 |
1803 void RenderProcessHostImpl::Cleanup() { | 1816 void RenderProcessHostImpl::Cleanup() { |
| 1817 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1804 // If within_process_died_observer_ is true, one of our observers performed an | 1818 // 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, | 1819 // 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, | 1820 // delay the destruction until all of the observer callbacks have been made, |
1807 // and guarantee that the RenderProcessHostDestroyed observer callback is | 1821 // and guarantee that the RenderProcessHostDestroyed observer callback is |
1808 // always the last callback fired. | 1822 // always the last callback fired. |
1809 if (within_process_died_observer_) { | 1823 if (within_process_died_observer_) { |
1810 delayed_cleanup_needed_ = true; | 1824 delayed_cleanup_needed_ = true; |
1811 return; | 1825 return; |
1812 } | 1826 } |
1813 delayed_cleanup_needed_ = false; | 1827 delayed_cleanup_needed_ = false; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1873 | 1887 |
1874 // It's important not to wait for the DeleteTask to delete the channel | 1888 // 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 | 1889 // 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 | 1890 // rest of the objects attached to this RenderProcessHost start going |
1877 // away first, since deleting the channel proxy will post a | 1891 // away first, since deleting the channel proxy will post a |
1878 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. | 1892 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. |
1879 channel_.reset(); | 1893 channel_.reset(); |
1880 | 1894 |
1881 // The following members should be cleared in ProcessDied() as well! | 1895 // The following members should be cleared in ProcessDied() as well! |
1882 message_port_message_filter_ = NULL; | 1896 message_port_message_filter_ = NULL; |
| 1897 url_loader_factory_ = nullptr; |
1883 | 1898 |
1884 RemoveUserData(kSessionStorageHolderKey); | 1899 RemoveUserData(kSessionStorageHolderKey); |
1885 | 1900 |
1886 // On shutdown, |this| may not be deleted because the deleter is posted to | 1901 // On shutdown, |this| may not be deleted because the deleter is posted to |
1887 // the current MessageLoop, but MessageLoop deletes all its pending | 1902 // the current MessageLoop, but MessageLoop deletes all its pending |
1888 // callbacks on shutdown. Since the deleter takes |this| as a raw pointer, | 1903 // 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. | 1904 // deleting the callback doesn't delete |this| resulting in a memory leak. |
1890 // Valgrind complains, so delete |mojo_application_host_| explicitly here to | 1905 // Valgrind complains, so delete |mojo_application_host_| explicitly here to |
1891 // stop valgrind from complaining. | 1906 // stop valgrind from complaining. |
1892 mojo_application_host_.reset(); | 1907 mojo_application_host_.reset(); |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2390 | 2405 |
2391 within_process_died_observer_ = true; | 2406 within_process_died_observer_ = true; |
2392 NotificationService::current()->Notify( | 2407 NotificationService::current()->Notify( |
2393 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), | 2408 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), |
2394 Details<RendererClosedDetails>(&details)); | 2409 Details<RendererClosedDetails>(&details)); |
2395 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, | 2410 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, |
2396 RenderProcessExited(this, status, exit_code)); | 2411 RenderProcessExited(this, status, exit_code)); |
2397 within_process_died_observer_ = false; | 2412 within_process_died_observer_ = false; |
2398 | 2413 |
2399 message_port_message_filter_ = NULL; | 2414 message_port_message_filter_ = NULL; |
| 2415 url_loader_factory_ = nullptr; |
2400 RemoveUserData(kSessionStorageHolderKey); | 2416 RemoveUserData(kSessionStorageHolderKey); |
2401 | 2417 |
2402 IDMap<IPC::Listener>::iterator iter(&listeners_); | 2418 IDMap<IPC::Listener>::iterator iter(&listeners_); |
2403 while (!iter.IsAtEnd()) { | 2419 while (!iter.IsAtEnd()) { |
2404 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( | 2420 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( |
2405 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); | 2421 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); |
2406 iter.Advance(); | 2422 iter.Advance(); |
2407 } | 2423 } |
2408 | 2424 |
2409 // It's possible that one of the calls out to the observers might have caused | 2425 // 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 | 2777 |
2762 // Skip widgets in other processes. | 2778 // Skip widgets in other processes. |
2763 if (rvh->GetProcess()->GetID() != GetID()) | 2779 if (rvh->GetProcess()->GetID() != GetID()) |
2764 continue; | 2780 continue; |
2765 | 2781 |
2766 rvh->OnWebkitPreferencesChanged(); | 2782 rvh->OnWebkitPreferencesChanged(); |
2767 } | 2783 } |
2768 } | 2784 } |
2769 | 2785 |
2770 } // namespace content | 2786 } // namespace content |
OLD | NEW |