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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 #include "ipc/attachment_broker.h" | 162 #include "ipc/attachment_broker.h" |
163 #include "ipc/attachment_broker_privileged.h" | 163 #include "ipc/attachment_broker_privileged.h" |
164 #include "ipc/ipc_channel.h" | 164 #include "ipc/ipc_channel.h" |
165 #include "ipc/ipc_channel_mojo.h" | 165 #include "ipc/ipc_channel_mojo.h" |
166 #include "ipc/ipc_logging.h" | 166 #include "ipc/ipc_logging.h" |
167 #include "ipc/ipc_switches.h" | 167 #include "ipc/ipc_switches.h" |
168 #include "media/base/media_switches.h" | 168 #include "media/base/media_switches.h" |
169 #include "mojo/edk/embedder/embedder.h" | 169 #include "mojo/edk/embedder/embedder.h" |
170 #include "net/url_request/url_request_context_getter.h" | 170 #include "net/url_request/url_request_context_getter.h" |
171 #include "ppapi/shared_impl/ppapi_switches.h" | 171 #include "ppapi/shared_impl/ppapi_switches.h" |
172 #include "services/shell/public/cpp/interface_provider.h" | |
173 #include "services/shell/public/cpp/interface_registry.h" | |
174 #include "services/shell/runner/common/switches.h" | 172 #include "services/shell/runner/common/switches.h" |
175 #include "storage/browser/fileapi/sandbox_file_system_backend.h" | 173 #include "storage/browser/fileapi/sandbox_file_system_backend.h" |
176 #include "third_party/skia/include/core/SkBitmap.h" | 174 #include "third_party/skia/include/core/SkBitmap.h" |
177 #include "ui/base/ui_base_switches.h" | 175 #include "ui/base/ui_base_switches.h" |
178 #include "ui/display/display_switches.h" | 176 #include "ui/display/display_switches.h" |
179 #include "ui/events/event_switches.h" | 177 #include "ui/events/event_switches.h" |
180 #include "ui/gfx/switches.h" | 178 #include "ui/gfx/switches.h" |
181 #include "ui/gl/gl_switches.h" | 179 #include "ui/gl/gl_switches.h" |
182 #include "ui/gl/gpu_switching_manager.h" | 180 #include "ui/gl/gpu_switching_manager.h" |
183 #include "ui/native_theme/native_theme_switches.h" | 181 #include "ui/native_theme/native_theme_switches.h" |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 // single process modes, the global attachment broker is the privileged | 591 // single process modes, the global attachment broker is the privileged |
594 // attachment broker, rather than an unprivileged attachment broker. | 592 // attachment broker, rather than an unprivileged attachment broker. |
595 #if defined(OS_MACOSX) | 593 #if defined(OS_MACOSX) |
596 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded( | 594 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded( |
597 MachBroker::GetInstance()); | 595 MachBroker::GetInstance()); |
598 #else | 596 #else |
599 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(); | 597 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(); |
600 #endif // defined(OS_MACOSX) | 598 #endif // defined(OS_MACOSX) |
601 #endif // USE_ATTACHMENT_BROKER | 599 #endif // USE_ATTACHMENT_BROKER |
602 | 600 |
603 scoped_refptr<base::SequencedTaskRunner> io_task_runner = | |
604 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | |
605 shell::Connector* connector = | 601 shell::Connector* connector = |
606 BrowserContext::GetShellConnectorFor(browser_context_); | 602 BrowserContext::GetShellConnectorFor(browser_context_); |
607 // Some embedders may not initialize Mojo or the shell connector for a browser | 603 // Some embedders may not initialize Mojo or the shell connector for a browser |
608 // context (e.g. Android WebView)... so just fall back to the per-process | 604 // context (e.g. Android WebView)... so just fall back to the per-process |
609 // connector. | 605 // connector. |
610 if (!connector) { | 606 if (!connector) { |
611 // Additionally, some test code may not initialize the process-wide | 607 // Additionally, some test code may not initialize the process-wide |
612 // MojoShellConnection prior to this point. This class of test code doesn't | 608 // MojoShellConnection prior to this point. This class of test code doesn't |
613 // care about render processes so we can initialize a dummy one. | 609 // care about render processes so we can initialize a dummy one. |
614 if (!MojoShellConnection::GetForProcess()) { | 610 if (!MojoShellConnection::GetForProcess()) { |
615 shell::mojom::ServiceRequest request = mojo::GetProxy(&test_service_); | 611 shell::mojom::ServiceRequest request = mojo::GetProxy(&test_service_); |
616 MojoShellConnection::SetForProcess(MojoShellConnection::Create( | 612 MojoShellConnection::SetForProcess(MojoShellConnection::Create( |
617 std::move(request), io_task_runner)); | 613 std::move(request))); |
618 } | 614 } |
619 connector = MojoShellConnection::GetForProcess()->GetConnector(); | 615 connector = MojoShellConnection::GetForProcess()->GetConnector(); |
620 } | 616 } |
621 mojo_child_connection_.reset(new MojoChildConnection( | 617 mojo_child_connection_.reset(new MojoChildConnection( |
622 kRendererMojoApplicationName, | 618 kRendererMojoApplicationName, |
623 base::StringPrintf("%d_%d", id_, instance_id_++), child_token_, connector, | 619 base::StringPrintf("%d_%d", id_, instance_id_++), |
624 io_task_runner)); | 620 child_token_, |
| 621 connector)); |
625 } | 622 } |
626 | 623 |
627 // static | 624 // static |
628 void RenderProcessHostImpl::ShutDownInProcessRenderer() { | 625 void RenderProcessHostImpl::ShutDownInProcessRenderer() { |
629 DCHECK(g_run_renderer_in_process_); | 626 DCHECK(g_run_renderer_in_process_); |
630 | 627 |
631 switch (g_all_hosts.Pointer()->size()) { | 628 switch (g_all_hosts.Pointer()->size()) { |
632 case 0: | 629 case 0: |
633 return; | 630 return; |
634 case 1: { | 631 case 1: { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 DCHECK(g_renderer_main_thread_factory); | 736 DCHECK(g_renderer_main_thread_factory); |
740 // Crank up a thread and run the initialization there. With the way that | 737 // Crank up a thread and run the initialization there. With the way that |
741 // messages flow between the browser and renderer, this thread is required | 738 // messages flow between the browser and renderer, this thread is required |
742 // to prevent a deadlock in single-process mode. Since the primordial | 739 // to prevent a deadlock in single-process mode. Since the primordial |
743 // thread in the renderer process runs the WebKit code and can sometimes | 740 // thread in the renderer process runs the WebKit code and can sometimes |
744 // make blocking calls to the UI thread (i.e. this thread), they need to run | 741 // make blocking calls to the UI thread (i.e. this thread), they need to run |
745 // on separate threads. | 742 // on separate threads. |
746 in_process_renderer_.reset( | 743 in_process_renderer_.reset( |
747 g_renderer_main_thread_factory(InProcessChildThreadParams( | 744 g_renderer_main_thread_factory(InProcessChildThreadParams( |
748 channel_id, | 745 channel_id, |
749 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 746 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) |
| 747 ->task_runner(), |
750 mojo_channel_token_, | 748 mojo_channel_token_, |
751 mojo_child_connection_->service_token()))); | 749 mojo_child_connection_->service_token()))); |
752 | 750 |
753 base::Thread::Options options; | 751 base::Thread::Options options; |
754 #if defined(OS_WIN) && !defined(OS_MACOSX) | 752 #if defined(OS_WIN) && !defined(OS_MACOSX) |
755 // In-process plugins require this to be a UI message loop. | 753 // In-process plugins require this to be a UI message loop. |
756 options.message_loop_type = base::MessageLoop::TYPE_UI; | 754 options.message_loop_type = base::MessageLoop::TYPE_UI; |
757 #else | 755 #else |
758 // We can't have multiple UI loops on Linux and Android, so we don't support | 756 // We can't have multiple UI loops on Linux and Android, so we don't support |
759 // in-process plugins. | 757 // in-process plugins. |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 void RenderProcessHostImpl::ResumeDeferredNavigation( | 1096 void RenderProcessHostImpl::ResumeDeferredNavigation( |
1099 const GlobalRequestID& request_id) { | 1097 const GlobalRequestID& request_id) { |
1100 widget_helper_->ResumeDeferredNavigation(request_id); | 1098 widget_helper_->ResumeDeferredNavigation(request_id); |
1101 } | 1099 } |
1102 | 1100 |
1103 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { | 1101 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { |
1104 Send(new ViewMsg_TimezoneChange(zone_id)); | 1102 Send(new ViewMsg_TimezoneChange(zone_id)); |
1105 } | 1103 } |
1106 | 1104 |
1107 shell::InterfaceRegistry* RenderProcessHostImpl::GetInterfaceRegistry() { | 1105 shell::InterfaceRegistry* RenderProcessHostImpl::GetInterfaceRegistry() { |
1108 return mojo_child_connection_->GetInterfaceRegistry(); | 1106 return GetChildConnection()->GetInterfaceRegistry(); |
1109 } | 1107 } |
1110 | 1108 |
1111 shell::InterfaceProvider* RenderProcessHostImpl::GetRemoteInterfaces() { | 1109 shell::InterfaceProvider* RenderProcessHostImpl::GetRemoteInterfaces() { |
1112 return mojo_child_connection_->GetRemoteInterfaces(); | 1110 return GetChildConnection()->GetRemoteInterfaces(); |
| 1111 } |
| 1112 |
| 1113 shell::Connection* RenderProcessHostImpl::GetChildConnection() { |
| 1114 DCHECK(mojo_child_connection_); |
| 1115 return mojo_child_connection_->connection(); |
1113 } | 1116 } |
1114 | 1117 |
1115 std::unique_ptr<base::SharedPersistentMemoryAllocator> | 1118 std::unique_ptr<base::SharedPersistentMemoryAllocator> |
1116 RenderProcessHostImpl::TakeMetricsAllocator() { | 1119 RenderProcessHostImpl::TakeMetricsAllocator() { |
1117 return std::move(metrics_allocator_); | 1120 return std::move(metrics_allocator_); |
1118 } | 1121 } |
1119 | 1122 |
1120 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() | 1123 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() |
1121 const { | 1124 const { |
1122 return init_time_; | 1125 return init_time_; |
(...skipping 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2421 // RenderProcessExited observers and RenderProcessGone handlers might | 2424 // RenderProcessExited observers and RenderProcessGone handlers might |
2422 // navigate or perform other actions that require a connection. Ensure that | 2425 // navigate or perform other actions that require a connection. Ensure that |
2423 // there is one before calling them. | 2426 // there is one before calling them. |
2424 child_token_ = mojo::edk::GenerateRandomToken(); | 2427 child_token_ = mojo::edk::GenerateRandomToken(); |
2425 shell::Connector* connector = | 2428 shell::Connector* connector = |
2426 BrowserContext::GetShellConnectorFor(browser_context_); | 2429 BrowserContext::GetShellConnectorFor(browser_context_); |
2427 if (!connector) | 2430 if (!connector) |
2428 connector = MojoShellConnection::GetForProcess()->GetConnector(); | 2431 connector = MojoShellConnection::GetForProcess()->GetConnector(); |
2429 mojo_child_connection_.reset(new MojoChildConnection( | 2432 mojo_child_connection_.reset(new MojoChildConnection( |
2430 kRendererMojoApplicationName, | 2433 kRendererMojoApplicationName, |
2431 base::StringPrintf("%d_%d", id_, instance_id_++), child_token_, connector, | 2434 base::StringPrintf("%d_%d", id_, instance_id_++), |
2432 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); | 2435 child_token_, |
| 2436 connector)); |
2433 | 2437 |
2434 within_process_died_observer_ = true; | 2438 within_process_died_observer_ = true; |
2435 NotificationService::current()->Notify( | 2439 NotificationService::current()->Notify( |
2436 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), | 2440 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), |
2437 Details<RendererClosedDetails>(&details)); | 2441 Details<RendererClosedDetails>(&details)); |
2438 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, | 2442 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, |
2439 RenderProcessExited(this, status, exit_code)); | 2443 RenderProcessExited(this, status, exit_code)); |
2440 within_process_died_observer_ = false; | 2444 within_process_died_observer_ = false; |
2441 | 2445 |
2442 message_port_message_filter_ = NULL; | 2446 message_port_message_filter_ = NULL; |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2826 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 2830 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
2827 | 2831 |
2828 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias | 2832 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias |
2829 // enough information here so that we can determine what the bad message was. | 2833 // enough information here so that we can determine what the bad message was. |
2830 base::debug::Alias(&error); | 2834 base::debug::Alias(&error); |
2831 bad_message::ReceivedBadMessage(process.get(), | 2835 bad_message::ReceivedBadMessage(process.get(), |
2832 bad_message::RPH_MOJO_PROCESS_ERROR); | 2836 bad_message::RPH_MOJO_PROCESS_ERROR); |
2833 } | 2837 } |
2834 | 2838 |
2835 } // namespace content | 2839 } // namespace content |
OLD | NEW |