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