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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 #include "content/browser/storage_partition_impl.h" | 121 #include "content/browser/storage_partition_impl.h" |
122 #include "content/browser/streams/stream_context.h" | 122 #include "content/browser/streams/stream_context.h" |
123 #include "content/browser/tracing/trace_message_filter.h" | 123 #include "content/browser/tracing/trace_message_filter.h" |
124 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 124 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
125 #include "content/common/child_process_host_impl.h" | 125 #include "content/common/child_process_host_impl.h" |
126 #include "content/common/child_process_messages.h" | 126 #include "content/common/child_process_messages.h" |
127 #include "content/common/content_switches_internal.h" | 127 #include "content/common/content_switches_internal.h" |
128 #include "content/common/frame_messages.h" | 128 #include "content/common/frame_messages.h" |
129 #include "content/common/gpu_host_messages.h" | 129 #include "content/common/gpu_host_messages.h" |
130 #include "content/common/in_process_child_thread_params.h" | 130 #include "content/common/in_process_child_thread_params.h" |
131 #include "content/common/mojo/channel_init.h" | |
132 #include "content/common/mojo/mojo_messages.h" | |
133 #include "content/common/mojo/mojo_shell_connection_impl.h" | 131 #include "content/common/mojo/mojo_shell_connection_impl.h" |
134 #include "content/common/render_process_messages.h" | 132 #include "content/common/render_process_messages.h" |
135 #include "content/common/resource_messages.h" | 133 #include "content/common/resource_messages.h" |
136 #include "content/common/site_isolation_policy.h" | 134 #include "content/common/site_isolation_policy.h" |
137 #include "content/common/view_messages.h" | 135 #include "content/common/view_messages.h" |
138 #include "content/public/browser/browser_context.h" | 136 #include "content/public/browser/browser_context.h" |
139 #include "content/public/browser/browser_thread.h" | 137 #include "content/public/browser/browser_thread.h" |
140 #include "content/public/browser/content_browser_client.h" | 138 #include "content/public/browser/content_browser_client.h" |
141 #include "content/public/browser/notification_service.h" | 139 #include "content/public/browser/notification_service.h" |
142 #include "content/public/browser/notification_types.h" | 140 #include "content/public/browser/notification_types.h" |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 // Setup the IPC channel. | 727 // Setup the IPC channel. |
730 const std::string channel_id = | 728 const std::string channel_id = |
731 IPC::Channel::GenerateVerifiedChannelID(std::string()); | 729 IPC::Channel::GenerateVerifiedChannelID(std::string()); |
732 channel_ = CreateChannelProxy(channel_id); | 730 channel_ = CreateChannelProxy(channel_id); |
733 #if USE_ATTACHMENT_BROKER | 731 #if USE_ATTACHMENT_BROKER |
734 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( | 732 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( |
735 channel_.get(), content::BrowserThread::GetMessageLoopProxyForThread( | 733 channel_.get(), content::BrowserThread::GetMessageLoopProxyForThread( |
736 content::BrowserThread::IO)); | 734 content::BrowserThread::IO)); |
737 #endif | 735 #endif |
738 | 736 |
739 // Setup the Mojo channel. | |
740 mojo_application_host_->Init(); | |
741 | |
742 // Call the embedder first so that their IPC filters have priority. | 737 // Call the embedder first so that their IPC filters have priority. |
743 GetContentClient()->browser()->RenderProcessWillLaunch(this); | 738 GetContentClient()->browser()->RenderProcessWillLaunch(this); |
744 | 739 |
745 CreateMessageFilters(); | 740 CreateMessageFilters(); |
746 RegisterMojoServices(); | 741 RegisterMojoServices(); |
747 | 742 |
748 if (run_renderer_in_process()) { | 743 if (run_renderer_in_process()) { |
749 DCHECK(g_renderer_main_thread_factory); | 744 DCHECK(g_renderer_main_thread_factory); |
750 // Crank up a thread and run the initialization there. With the way that | 745 // Crank up a thread and run the initialization there. With the way that |
751 // messages flow between the browser and renderer, this thread is required | 746 // messages flow between the browser and renderer, this thread is required |
752 // to prevent a deadlock in single-process mode. Since the primordial | 747 // to prevent a deadlock in single-process mode. Since the primordial |
753 // thread in the renderer process runs the WebKit code and can sometimes | 748 // thread in the renderer process runs the WebKit code and can sometimes |
754 // make blocking calls to the UI thread (i.e. this thread), they need to run | 749 // make blocking calls to the UI thread (i.e. this thread), they need to run |
755 // on separate threads. | 750 // on separate threads. |
756 in_process_renderer_.reset( | 751 in_process_renderer_.reset( |
757 g_renderer_main_thread_factory(InProcessChildThreadParams( | 752 g_renderer_main_thread_factory(InProcessChildThreadParams( |
758 channel_id, | 753 channel_id, |
759 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) | 754 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) |
760 ->task_runner(), | 755 ->task_runner(), |
761 in_process_renderer_handle_.release()))); | 756 mojo_channel_token_, mojo_application_host_->GetToken()))); |
762 | 757 |
763 base::Thread::Options options; | 758 base::Thread::Options options; |
764 #if defined(OS_WIN) && !defined(OS_MACOSX) | 759 #if defined(OS_WIN) && !defined(OS_MACOSX) |
765 // In-process plugins require this to be a UI message loop. | 760 // In-process plugins require this to be a UI message loop. |
766 options.message_loop_type = base::MessageLoop::TYPE_UI; | 761 options.message_loop_type = base::MessageLoop::TYPE_UI; |
767 #else | 762 #else |
768 // We can't have multiple UI loops on Linux and Android, so we don't support | 763 // We can't have multiple UI loops on Linux and Android, so we don't support |
769 // in-process plugins. | 764 // in-process plugins. |
770 options.message_loop_type = base::MessageLoop::TYPE_DEFAULT; | 765 options.message_loop_type = base::MessageLoop::TYPE_DEFAULT; |
771 #endif | 766 #endif |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 init_time_ = base::TimeTicks::Now(); | 805 init_time_ = base::TimeTicks::Now(); |
811 return true; | 806 return true; |
812 } | 807 } |
813 | 808 |
814 std::unique_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy( | 809 std::unique_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy( |
815 const std::string& channel_id) { | 810 const std::string& channel_id) { |
816 scoped_refptr<base::SingleThreadTaskRunner> runner = | 811 scoped_refptr<base::SingleThreadTaskRunner> runner = |
817 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 812 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
818 if (ShouldUseMojoChannel()) { | 813 if (ShouldUseMojoChannel()) { |
819 VLOG(1) << "Mojo Channel is enabled on host"; | 814 VLOG(1) << "Mojo Channel is enabled on host"; |
820 mojo::ScopedMessagePipeHandle handle; | 815 mojo_channel_token_ = mojo::edk::GenerateRandomToken(); |
821 | 816 mojo::ScopedMessagePipeHandle handle = |
822 if (run_renderer_in_process()) { | 817 mojo::edk::CreateParentMessagePipe(mojo_channel_token_); |
823 mojo::MessagePipe pipe; | |
824 handle = std::move(pipe.handle0); | |
825 in_process_renderer_handle_ = std::move(pipe.handle1); | |
826 } else { | |
827 mojo_channel_token_ = mojo::edk::GenerateRandomToken(); | |
828 handle = mojo::edk::CreateParentMessagePipe(mojo_channel_token_); | |
829 } | |
830 | 818 |
831 // Do NOT expand ifdef or run time condition checks here! Synchronous | 819 // Do NOT expand ifdef or run time condition checks here! Synchronous |
832 // IPCs from browser process are banned. It is only narrowly allowed | 820 // IPCs from browser process are banned. It is only narrowly allowed |
833 // for Android WebView to maintain backward compatibility. | 821 // for Android WebView to maintain backward compatibility. |
834 // See crbug.com/526842 for details. | 822 // See crbug.com/526842 for details. |
835 #if defined(OS_ANDROID) | 823 #if defined(OS_ANDROID) |
836 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 824 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
837 switches::kIPCSyncCompositing)) { | 825 switches::kIPCSyncCompositing)) { |
838 return IPC::SyncChannel::Create( | 826 return IPC::SyncChannel::Create( |
839 IPC::ChannelMojo::CreateServerFactory(std::move(handle)), this, | 827 IPC::ChannelMojo::CreateServerFactory(std::move(handle)), this, |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 command_line->AppendSwitchASCII(switches::kDeviceScaleFactor, | 1371 command_line->AppendSwitchASCII(switches::kDeviceScaleFactor, |
1384 base::DoubleToString(gfx::GetDPIScale())); | 1372 base::DoubleToString(gfx::GetDPIScale())); |
1385 #endif | 1373 #endif |
1386 | 1374 |
1387 AppendCompositorCommandLineFlags(command_line); | 1375 AppendCompositorCommandLineFlags(command_line); |
1388 | 1376 |
1389 if (!mojo_channel_token_.empty()) { | 1377 if (!mojo_channel_token_.empty()) { |
1390 command_line->AppendSwitchASCII(switches::kMojoChannelToken, | 1378 command_line->AppendSwitchASCII(switches::kMojoChannelToken, |
1391 mojo_channel_token_); | 1379 mojo_channel_token_); |
1392 } | 1380 } |
| 1381 command_line->AppendSwitchASCII(switches::kMojoApplicationChannelToken, |
| 1382 mojo_application_host_->GetToken()); |
1393 } | 1383 } |
1394 | 1384 |
1395 void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer( | 1385 void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer( |
1396 const base::CommandLine& browser_cmd, | 1386 const base::CommandLine& browser_cmd, |
1397 base::CommandLine* renderer_cmd) const { | 1387 base::CommandLine* renderer_cmd) const { |
1398 // Propagate the following switches to the renderer command line (along | 1388 // Propagate the following switches to the renderer command line (along |
1399 // with any associated values) if present in the browser command line. | 1389 // with any associated values) if present in the browser command line. |
1400 static const char* const kSwitchNames[] = { | 1390 static const char* const kSwitchNames[] = { |
1401 switches::kAgcStartupMinVolume, | 1391 switches::kAgcStartupMinVolume, |
1402 switches::kAllowLoopbackInPeerConnection, | 1392 switches::kAllowLoopbackInPeerConnection, |
(...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2624 // ExtensionService uses this notification to initialize the renderer process | 2614 // ExtensionService uses this notification to initialize the renderer process |
2625 // with state that must be there before any JavaScript executes. | 2615 // with state that must be there before any JavaScript executes. |
2626 // | 2616 // |
2627 // The queued messages contain such things as "navigate". If this notification | 2617 // The queued messages contain such things as "navigate". If this notification |
2628 // was after, we can end up executing JavaScript before the initialization | 2618 // was after, we can end up executing JavaScript before the initialization |
2629 // happens. | 2619 // happens. |
2630 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, | 2620 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, |
2631 Source<RenderProcessHost>(this), | 2621 Source<RenderProcessHost>(this), |
2632 NotificationService::NoDetails()); | 2622 NotificationService::NoDetails()); |
2633 | 2623 |
2634 // Allow Mojo to be setup before the renderer sees any Chrome IPC messages. | |
2635 // This way, Mojo can be safely used from the renderer in response to any | |
2636 // Chrome IPC message. | |
2637 mojo_application_host_->Activate(this, GetHandle()); | |
2638 | |
2639 while (!queued_messages_.empty()) { | 2624 while (!queued_messages_.empty()) { |
2640 Send(queued_messages_.front()); | 2625 Send(queued_messages_.front()); |
2641 queued_messages_.pop(); | 2626 queued_messages_.pop(); |
2642 } | 2627 } |
2643 | 2628 |
2644 if (IsReady()) { | 2629 if (IsReady()) { |
2645 DCHECK(!sent_render_process_ready_); | 2630 DCHECK(!sent_render_process_ready_); |
2646 sent_render_process_ready_ = true; | 2631 sent_render_process_ready_ = true; |
2647 // Send RenderProcessReady only if the channel is already connected. | 2632 // Send RenderProcessReady only if the channel is already connected. |
2648 FOR_EACH_OBSERVER(RenderProcessHostObserver, | 2633 FOR_EACH_OBSERVER(RenderProcessHostObserver, |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2842 | 2827 |
2843 // Skip widgets in other processes. | 2828 // Skip widgets in other processes. |
2844 if (rvh->GetProcess()->GetID() != GetID()) | 2829 if (rvh->GetProcess()->GetID() != GetID()) |
2845 continue; | 2830 continue; |
2846 | 2831 |
2847 rvh->OnWebkitPreferencesChanged(); | 2832 rvh->OnWebkitPreferencesChanged(); |
2848 } | 2833 } |
2849 } | 2834 } |
2850 | 2835 |
2851 } // namespace content | 2836 } // namespace content |
OLD | NEW |