OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" | 80 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" |
81 #include "content/browser/renderer_host/media/midi_dispatcher_host.h" | 81 #include "content/browser/renderer_host/media/midi_dispatcher_host.h" |
82 #include "content/browser/renderer_host/media/midi_host.h" | 82 #include "content/browser/renderer_host/media/midi_host.h" |
83 #include "content/browser/renderer_host/media/peer_connection_tracker_host.h" | 83 #include "content/browser/renderer_host/media/peer_connection_tracker_host.h" |
84 #include "content/browser/renderer_host/media/video_capture_host.h" | 84 #include "content/browser/renderer_host/media/video_capture_host.h" |
85 #include "content/browser/renderer_host/memory_benchmark_message_filter.h" | 85 #include "content/browser/renderer_host/memory_benchmark_message_filter.h" |
86 #include "content/browser/renderer_host/p2p/socket_dispatcher_host.h" | 86 #include "content/browser/renderer_host/p2p/socket_dispatcher_host.h" |
87 #include "content/browser/renderer_host/pepper/pepper_message_filter.h" | 87 #include "content/browser/renderer_host/pepper/pepper_message_filter.h" |
88 #include "content/browser/renderer_host/pepper/pepper_renderer_connection.h" | 88 #include "content/browser/renderer_host/pepper/pepper_renderer_connection.h" |
89 #include "content/browser/renderer_host/render_message_filter.h" | 89 #include "content/browser/renderer_host/render_message_filter.h" |
90 #include "content/browser/renderer_host/render_process_host_mojo_impl.h" | |
91 #include "content/browser/renderer_host/render_view_host_delegate.h" | 90 #include "content/browser/renderer_host/render_view_host_delegate.h" |
92 #include "content/browser/renderer_host/render_view_host_impl.h" | 91 #include "content/browser/renderer_host/render_view_host_impl.h" |
93 #include "content/browser/renderer_host/render_widget_helper.h" | 92 #include "content/browser/renderer_host/render_widget_helper.h" |
94 #include "content/browser/renderer_host/render_widget_host_impl.h" | 93 #include "content/browser/renderer_host/render_widget_host_impl.h" |
95 #include "content/browser/renderer_host/socket_stream_dispatcher_host.h" | 94 #include "content/browser/renderer_host/socket_stream_dispatcher_host.h" |
96 #include "content/browser/renderer_host/text_input_client_message_filter.h" | 95 #include "content/browser/renderer_host/text_input_client_message_filter.h" |
97 #include "content/browser/renderer_host/websocket_dispatcher_host.h" | 96 #include "content/browser/renderer_host/websocket_dispatcher_host.h" |
98 #include "content/browser/resolve_proxy_msg_helper.h" | 97 #include "content/browser/resolve_proxy_msg_helper.h" |
99 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host.
h" | 98 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host.
h" |
100 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 99 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
101 #include "content/browser/service_worker/service_worker_dispatcher_host.h" | 100 #include "content/browser/service_worker/service_worker_dispatcher_host.h" |
102 #include "content/browser/shared_worker/shared_worker_message_filter.h" | 101 #include "content/browser/shared_worker/shared_worker_message_filter.h" |
103 #include "content/browser/speech/input_tag_speech_dispatcher_host.h" | 102 #include "content/browser/speech/input_tag_speech_dispatcher_host.h" |
104 #include "content/browser/speech/speech_recognition_dispatcher_host.h" | 103 #include "content/browser/speech/speech_recognition_dispatcher_host.h" |
105 #include "content/browser/storage_partition_impl.h" | 104 #include "content/browser/storage_partition_impl.h" |
106 #include "content/browser/streams/stream_context.h" | 105 #include "content/browser/streams/stream_context.h" |
107 #include "content/browser/tracing/trace_message_filter.h" | 106 #include "content/browser/tracing/trace_message_filter.h" |
108 #include "content/browser/vibration/vibration_message_filter.h" | 107 #include "content/browser/vibration/vibration_message_filter.h" |
109 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 108 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
110 #include "content/browser/worker_host/worker_message_filter.h" | 109 #include "content/browser/worker_host/worker_message_filter.h" |
111 #include "content/browser/worker_host/worker_storage_partition.h" | 110 #include "content/browser/worker_host/worker_storage_partition.h" |
112 #include "content/common/child_process_host_impl.h" | 111 #include "content/common/child_process_host_impl.h" |
113 #include "content/common/child_process_messages.h" | 112 #include "content/common/child_process_messages.h" |
114 #include "content/common/content_switches_internal.h" | 113 #include "content/common/content_switches_internal.h" |
115 #include "content/common/gpu/gpu_messages.h" | 114 #include "content/common/gpu/gpu_messages.h" |
| 115 #include "content/common/mojo/mojo_channel_init.h" |
| 116 #include "content/common/mojo/mojo_messages.h" |
116 #include "content/common/resource_messages.h" | 117 #include "content/common/resource_messages.h" |
117 #include "content/common/view_messages.h" | 118 #include "content/common/view_messages.h" |
118 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" | 119 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" |
119 #include "content/public/browser/browser_context.h" | 120 #include "content/public/browser/browser_context.h" |
120 #include "content/public/browser/content_browser_client.h" | 121 #include "content/public/browser/content_browser_client.h" |
121 #include "content/public/browser/notification_service.h" | 122 #include "content/public/browser/notification_service.h" |
122 #include "content/public/browser/notification_types.h" | 123 #include "content/public/browser/notification_types.h" |
123 #include "content/public/browser/render_process_host_factory.h" | 124 #include "content/public/browser/render_process_host_factory.h" |
124 #include "content/public/browser/render_process_host_observer.h" | 125 #include "content/public/browser/render_process_host_observer.h" |
125 #include "content/public/browser/render_widget_host.h" | 126 #include "content/public/browser/render_widget_host.h" |
126 #include "content/public/browser/render_widget_host_iterator.h" | 127 #include "content/public/browser/render_widget_host_iterator.h" |
127 #include "content/public/browser/resource_context.h" | 128 #include "content/public/browser/resource_context.h" |
128 #include "content/public/browser/user_metrics.h" | 129 #include "content/public/browser/user_metrics.h" |
129 #include "content/public/browser/worker_service.h" | 130 #include "content/public/browser/worker_service.h" |
130 #include "content/public/common/content_constants.h" | 131 #include "content/public/common/content_constants.h" |
131 #include "content/public/common/content_switches.h" | 132 #include "content/public/common/content_switches.h" |
132 #include "content/public/common/process_type.h" | 133 #include "content/public/common/process_type.h" |
133 #include "content/public/common/result_codes.h" | 134 #include "content/public/common/result_codes.h" |
134 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 135 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
135 #include "content/public/common/url_constants.h" | 136 #include "content/public/common/url_constants.h" |
136 #include "gpu/command_buffer/service/gpu_switches.h" | 137 #include "gpu/command_buffer/service/gpu_switches.h" |
137 #include "ipc/ipc_channel.h" | 138 #include "ipc/ipc_channel.h" |
138 #include "ipc/ipc_logging.h" | 139 #include "ipc/ipc_logging.h" |
139 #include "ipc/ipc_switches.h" | 140 #include "ipc/ipc_switches.h" |
140 #include "media/base/media_switches.h" | 141 #include "media/base/media_switches.h" |
| 142 #include "mojo/embedder/platform_channel_pair.h" |
141 #include "net/url_request/url_request_context_getter.h" | 143 #include "net/url_request/url_request_context_getter.h" |
142 #include "ppapi/shared_impl/ppapi_switches.h" | 144 #include "ppapi/shared_impl/ppapi_switches.h" |
143 #include "third_party/skia/include/core/SkBitmap.h" | 145 #include "third_party/skia/include/core/SkBitmap.h" |
144 #include "ui/base/ui_base_switches.h" | 146 #include "ui/base/ui_base_switches.h" |
145 #include "ui/events/event_switches.h" | 147 #include "ui/events/event_switches.h" |
146 #include "ui/gfx/switches.h" | 148 #include "ui/gfx/switches.h" |
147 #include "ui/gl/gl_switches.h" | 149 #include "ui/gl/gl_switches.h" |
148 #include "ui/native_theme/native_theme_switches.h" | 150 #include "ui/native_theme/native_theme_switches.h" |
149 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" | 151 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" |
150 #include "webkit/common/resource_type.h" | 152 #include "webkit/common/resource_type.h" |
(...skipping 11 matching lines...) Expand all Loading... |
162 #include "content/common/media/media_stream_messages.h" | 164 #include "content/common/media/media_stream_messages.h" |
163 #endif | 165 #endif |
164 | 166 |
165 extern bool g_exited_main_message_loop; | 167 extern bool g_exited_main_message_loop; |
166 | 168 |
167 static const char* kSiteProcessMapKeyName = "content_site_process_map"; | 169 static const char* kSiteProcessMapKeyName = "content_site_process_map"; |
168 | 170 |
169 namespace content { | 171 namespace content { |
170 namespace { | 172 namespace { |
171 | 173 |
| 174 base::PlatformFile PlatformFileFromScopedPlatformHandle( |
| 175 mojo::embedder::ScopedPlatformHandle handle) { |
| 176 #if defined(OS_POSIX) |
| 177 return handle.release().fd; |
| 178 #elif defined(OS_WIN) |
| 179 return handle.release().handle; |
| 180 #endif |
| 181 } |
| 182 |
172 void CacheShaderInfo(int32 id, base::FilePath path) { | 183 void CacheShaderInfo(int32 id, base::FilePath path) { |
173 ShaderCacheFactory::GetInstance()->SetCacheInfo(id, path); | 184 ShaderCacheFactory::GetInstance()->SetCacheInfo(id, path); |
174 } | 185 } |
175 | 186 |
176 void RemoveShaderInfo(int32 id) { | 187 void RemoveShaderInfo(int32 id) { |
177 ShaderCacheFactory::GetInstance()->RemoveCacheInfo(id); | 188 ShaderCacheFactory::GetInstance()->RemoveCacheInfo(id); |
178 } | 189 } |
179 | 190 |
180 net::URLRequestContext* GetRequestContext( | 191 net::URLRequestContext* GetRequestContext( |
181 scoped_refptr<net::URLRequestContextGetter> request_context, | 192 scoped_refptr<net::URLRequestContextGetter> request_context, |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 | 552 |
542 // Setup the IPC channel. | 553 // Setup the IPC channel. |
543 const std::string channel_id = | 554 const std::string channel_id = |
544 IPC::Channel::GenerateVerifiedChannelID(std::string()); | 555 IPC::Channel::GenerateVerifiedChannelID(std::string()); |
545 channel_.reset( | 556 channel_.reset( |
546 new IPC::ChannelProxy(channel_id, | 557 new IPC::ChannelProxy(channel_id, |
547 IPC::Channel::MODE_SERVER, | 558 IPC::Channel::MODE_SERVER, |
548 this, | 559 this, |
549 BrowserThread::GetMessageLoopProxyForThread( | 560 BrowserThread::GetMessageLoopProxyForThread( |
550 BrowserThread::IO).get())); | 561 BrowserThread::IO).get())); |
| 562 InitializeMojo(); |
551 | 563 |
552 // Call the embedder first so that their IPC filters have priority. | 564 // Call the embedder first so that their IPC filters have priority. |
553 GetContentClient()->browser()->RenderProcessWillLaunch(this); | 565 GetContentClient()->browser()->RenderProcessWillLaunch(this); |
554 | 566 |
555 CreateMessageFilters(); | 567 CreateMessageFilters(); |
556 | 568 |
557 if (run_renderer_in_process()) { | 569 if (run_renderer_in_process()) { |
558 DCHECK(g_renderer_main_thread_factory); | 570 DCHECK(g_renderer_main_thread_factory); |
559 // Crank up a thread and run the initialization there. With the way that | 571 // Crank up a thread and run the initialization there. With the way that |
560 // messages flow between the browser and renderer, this thread is required | 572 // messages flow between the browser and renderer, this thread is required |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 | 613 |
602 if (!gpu_observer_registered_) { | 614 if (!gpu_observer_registered_) { |
603 gpu_observer_registered_ = true; | 615 gpu_observer_registered_ = true; |
604 GpuDataManagerImpl::GetInstance()->AddObserver(this); | 616 GpuDataManagerImpl::GetInstance()->AddObserver(this); |
605 } | 617 } |
606 | 618 |
607 is_initialized_ = true; | 619 is_initialized_ = true; |
608 return true; | 620 return true; |
609 } | 621 } |
610 | 622 |
| 623 void RenderProcessHostImpl::InitializeMojo() { |
| 624 mojo::embedder::PlatformChannelPair channel_pair; |
| 625 mojo_channel_init_.reset(new MojoChannelInit); |
| 626 |
| 627 mojo::ScopedMessagePipeHandle message_pipe = mojo_channel_init_->Init( |
| 628 PlatformFileFromScopedPlatformHandle(channel_pair.PassServerHandle()), |
| 629 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
| 630 DCHECK(message_pipe.is_valid()); |
| 631 |
| 632 // The render_process_ is ready to use at this point, but all calls will be |
| 633 // queued until the client-side is connected. See ActivateMojo. |
| 634 render_process_.reset( |
| 635 ScopedIRenderProcessHandle::From(message_pipe.Pass()), this); |
| 636 |
| 637 // Forward this to the client once we know its process handle. |
| 638 mojo_client_handle_ = channel_pair.PassClientHandle(); |
| 639 } |
| 640 |
| 641 void RenderProcessHostImpl::ActivateMojo() { |
| 642 base::PlatformFile client_file = |
| 643 PlatformFileFromScopedPlatformHandle(mojo_client_handle_.Pass()); |
| 644 Send(new MojoMsg_Activate( |
| 645 IPC::GetFileHandleForProcess(client_file, GetHandle(), true))); |
| 646 } |
| 647 |
611 void RenderProcessHostImpl::CreateMessageFilters() { | 648 void RenderProcessHostImpl::CreateMessageFilters() { |
612 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 649 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
613 AddFilter(new ResourceSchedulerFilter(GetID())); | 650 AddFilter(new ResourceSchedulerFilter(GetID())); |
614 MediaInternals* media_internals = MediaInternals::GetInstance(); | 651 MediaInternals* media_internals = MediaInternals::GetInstance(); |
615 media::AudioManager* audio_manager = | 652 media::AudioManager* audio_manager = |
616 BrowserMainLoop::GetInstance()->audio_manager(); | 653 BrowserMainLoop::GetInstance()->audio_manager(); |
617 // Add BrowserPluginMessageFilter to ensure it gets the first stab at messages | 654 // Add BrowserPluginMessageFilter to ensure it gets the first stab at messages |
618 // from guests. | 655 // from guests. |
619 if (supports_browser_plugin_) { | 656 if (supports_browser_plugin_) { |
620 scoped_refptr<BrowserPluginMessageFilter> bp_message_filter( | 657 scoped_refptr<BrowserPluginMessageFilter> bp_message_filter( |
(...skipping 1289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1910 while (!iter.IsAtEnd()) { | 1947 while (!iter.IsAtEnd()) { |
1911 iter.GetCurrentValue()->OnMessageReceived( | 1948 iter.GetCurrentValue()->OnMessageReceived( |
1912 ViewHostMsg_RenderProcessGone(iter.GetCurrentKey(), | 1949 ViewHostMsg_RenderProcessGone(iter.GetCurrentKey(), |
1913 static_cast<int>(status), | 1950 static_cast<int>(status), |
1914 exit_code)); | 1951 exit_code)); |
1915 iter.Advance(); | 1952 iter.Advance(); |
1916 } | 1953 } |
1917 | 1954 |
1918 ClearTransportDIBCache(); | 1955 ClearTransportDIBCache(); |
1919 | 1956 |
1920 render_process_host_mojo_.reset(); | 1957 render_process_.reset(); |
| 1958 mojo_channel_init_.reset(); |
1921 | 1959 |
1922 // It's possible that one of the calls out to the observers might have caused | 1960 // It's possible that one of the calls out to the observers might have caused |
1923 // this object to be no longer needed. | 1961 // this object to be no longer needed. |
1924 if (delayed_cleanup_needed_) | 1962 if (delayed_cleanup_needed_) |
1925 Cleanup(); | 1963 Cleanup(); |
1926 | 1964 |
1927 // This object is not deleted at this point and might be reused later. | 1965 // This object is not deleted at this point and might be reused later. |
1928 // TODO(darin): clean this up | 1966 // TODO(darin): clean this up |
1929 } | 1967 } |
1930 | 1968 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2045 // with state that must be there before any JavaScript executes. | 2083 // with state that must be there before any JavaScript executes. |
2046 // | 2084 // |
2047 // The queued messages contain such things as "navigate". If this notification | 2085 // The queued messages contain such things as "navigate". If this notification |
2048 // was after, we can end up executing JavaScript before the initialization | 2086 // was after, we can end up executing JavaScript before the initialization |
2049 // happens. | 2087 // happens. |
2050 NotificationService::current()->Notify( | 2088 NotificationService::current()->Notify( |
2051 NOTIFICATION_RENDERER_PROCESS_CREATED, | 2089 NOTIFICATION_RENDERER_PROCESS_CREATED, |
2052 Source<RenderProcessHost>(this), | 2090 Source<RenderProcessHost>(this), |
2053 NotificationService::NoDetails()); | 2091 NotificationService::NoDetails()); |
2054 | 2092 |
| 2093 // Let the Mojo system get setup on the child process side before any other |
| 2094 // IPCs arrive. This way those may safely generate Mojo-related RPCs. |
| 2095 ActivateMojo(); |
| 2096 |
2055 while (!queued_messages_.empty()) { | 2097 while (!queued_messages_.empty()) { |
2056 Send(queued_messages_.front()); | 2098 Send(queued_messages_.front()); |
2057 queued_messages_.pop(); | 2099 queued_messages_.pop(); |
2058 } | 2100 } |
2059 | 2101 |
2060 #if defined(ENABLE_WEBRTC) | 2102 #if defined(ENABLE_WEBRTC) |
2061 if (WebRTCInternals::GetInstance()->aec_dump_enabled()) | 2103 if (WebRTCInternals::GetInstance()->aec_dump_enabled()) |
2062 EnableAecDump(WebRTCInternals::GetInstance()->aec_dump_file_path()); | 2104 EnableAecDump(WebRTCInternals::GetInstance()->aec_dump_file_path()); |
2063 #endif | 2105 #endif |
2064 | |
2065 if (render_process_host_mojo_.get()) | |
2066 render_process_host_mojo_->OnProcessLaunched(); | |
2067 } | 2106 } |
2068 | 2107 |
2069 scoped_refptr<AudioRendererHost> | 2108 scoped_refptr<AudioRendererHost> |
2070 RenderProcessHostImpl::audio_renderer_host() const { | 2109 RenderProcessHostImpl::audio_renderer_host() const { |
2071 return audio_renderer_host_; | 2110 return audio_renderer_host_; |
2072 } | 2111 } |
2073 | 2112 |
2074 void RenderProcessHostImpl::OnUserMetricsRecordAction( | 2113 void RenderProcessHostImpl::OnUserMetricsRecordAction( |
2075 const std::string& action) { | 2114 const std::string& action) { |
2076 RecordComputedAction(action); | 2115 RecordComputedAction(action); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2133 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 2172 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
2134 DCHECK_GT(worker_ref_count_, 0); | 2173 DCHECK_GT(worker_ref_count_, 0); |
2135 --worker_ref_count_; | 2174 --worker_ref_count_; |
2136 if (worker_ref_count_ == 0) | 2175 if (worker_ref_count_ == 0) |
2137 Cleanup(); | 2176 Cleanup(); |
2138 } | 2177 } |
2139 | 2178 |
2140 void RenderProcessHostImpl::SetWebUIHandle( | 2179 void RenderProcessHostImpl::SetWebUIHandle( |
2141 int32 view_routing_id, | 2180 int32 view_routing_id, |
2142 mojo::ScopedMessagePipeHandle handle) { | 2181 mojo::ScopedMessagePipeHandle handle) { |
2143 if (!render_process_host_mojo_) | 2182 DCHECK(!render_process_.is_null()); |
2144 render_process_host_mojo_.reset(new RenderProcessHostMojoImpl(this)); | 2183 render_process_->SetWebUIHandle(view_routing_id, handle.Pass()); |
2145 render_process_host_mojo_->SetWebUIHandle(view_routing_id, handle.Pass()); | |
2146 } | 2184 } |
2147 | 2185 |
2148 } // namespace content | 2186 } // namespace content |
OLD | NEW |