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 #include "content/child/child_thread_impl.h" | 5 #include "content/child/child_thread_impl.h" |
6 | 6 |
7 #include <signal.h> | 7 #include <signal.h> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 #include "content/child/push_messaging/push_dispatcher.h" | 46 #include "content/child/push_messaging/push_dispatcher.h" |
47 #include "content/child/quota_dispatcher.h" | 47 #include "content/child/quota_dispatcher.h" |
48 #include "content/child/quota_message_filter.h" | 48 #include "content/child/quota_message_filter.h" |
49 #include "content/child/resource_dispatcher.h" | 49 #include "content/child/resource_dispatcher.h" |
50 #include "content/child/service_worker/service_worker_message_filter.h" | 50 #include "content/child/service_worker/service_worker_message_filter.h" |
51 #include "content/child/thread_safe_sender.h" | 51 #include "content/child/thread_safe_sender.h" |
52 #include "content/child/websocket_dispatcher.h" | 52 #include "content/child/websocket_dispatcher.h" |
53 #include "content/child/websocket_message_filter.h" | 53 #include "content/child/websocket_message_filter.h" |
54 #include "content/common/child_process_messages.h" | 54 #include "content/common/child_process_messages.h" |
55 #include "content/common/in_process_child_thread_params.h" | 55 #include "content/common/in_process_child_thread_params.h" |
| 56 #include "content/common/mojo/constants.h" |
56 #include "content/public/common/content_switches.h" | 57 #include "content/public/common/content_switches.h" |
57 #include "content/public/common/mojo_channel_switches.h" | 58 #include "content/public/common/mojo_channel_switches.h" |
58 #include "content/public/common/mojo_shell_connection.h" | 59 #include "content/public/common/mojo_shell_connection.h" |
59 #include "ipc/attachment_broker.h" | 60 #include "ipc/attachment_broker.h" |
60 #include "ipc/attachment_broker_unprivileged.h" | 61 #include "ipc/attachment_broker_unprivileged.h" |
61 #include "ipc/ipc_channel_mojo.h" | 62 #include "ipc/ipc_channel_mojo.h" |
62 #include "ipc/ipc_logging.h" | 63 #include "ipc/ipc_logging.h" |
63 #include "ipc/ipc_platform_file.h" | 64 #include "ipc/ipc_platform_file.h" |
64 #include "ipc/ipc_switches.h" | 65 #include "ipc/ipc_switches.h" |
65 #include "ipc/ipc_sync_channel.h" | 66 #include "ipc/ipc_sync_channel.h" |
66 #include "ipc/ipc_sync_message_filter.h" | 67 #include "ipc/ipc_sync_message_filter.h" |
67 #include "mojo/edk/embedder/embedder.h" | 68 #include "mojo/edk/embedder/embedder.h" |
68 #include "mojo/edk/embedder/named_platform_channel_pair.h" | 69 #include "mojo/edk/embedder/named_platform_channel_pair.h" |
69 #include "mojo/edk/embedder/platform_channel_pair.h" | 70 #include "mojo/edk/embedder/platform_channel_pair.h" |
70 #include "mojo/edk/embedder/scoped_ipc_support.h" | 71 #include "mojo/edk/embedder/scoped_ipc_support.h" |
| 72 #include "services/shell/public/cpp/connector.h" |
71 #include "services/shell/public/cpp/interface_provider.h" | 73 #include "services/shell/public/cpp/interface_provider.h" |
72 #include "services/shell/public/cpp/interface_registry.h" | 74 #include "services/shell/public/cpp/interface_registry.h" |
73 #include "services/shell/runner/common/client_util.h" | 75 #include "services/shell/runner/common/client_util.h" |
74 | 76 |
75 #if defined(OS_POSIX) | 77 #if defined(OS_POSIX) |
76 #include "base/posix/global_descriptors.h" | 78 #include "base/posix/global_descriptors.h" |
77 #include "content/public/common/content_descriptors.h" | 79 #include "content/public/common/content_descriptors.h" |
78 #endif | 80 #endif |
79 | 81 |
80 using tracked_objects::ThreadData; | 82 using tracked_objects::ThreadData; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 | 261 |
260 ChildThread* ChildThread::Get() { | 262 ChildThread* ChildThread::Get() { |
261 return ChildThreadImpl::current(); | 263 return ChildThreadImpl::current(); |
262 } | 264 } |
263 | 265 |
264 ChildThreadImpl::Options::Options() | 266 ChildThreadImpl::Options::Options() |
265 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 267 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
266 switches::kProcessChannelID)), | 268 switches::kProcessChannelID)), |
267 use_mojo_channel(base::CommandLine::ForCurrentProcess()->HasSwitch( | 269 use_mojo_channel(base::CommandLine::ForCurrentProcess()->HasSwitch( |
268 switches::kMojoChannelToken)), | 270 switches::kMojoChannelToken)), |
269 auto_start_mojo_shell_connection(true) { | 271 auto_start_mojo_shell_connection(true), |
| 272 connect_to_browser(false) { |
270 } | 273 } |
271 | 274 |
272 ChildThreadImpl::Options::Options(const Options& other) = default; | 275 ChildThreadImpl::Options::Options(const Options& other) = default; |
273 | 276 |
274 ChildThreadImpl::Options::~Options() { | 277 ChildThreadImpl::Options::~Options() { |
275 } | 278 } |
276 | 279 |
277 ChildThreadImpl::Options::Builder::Builder() { | 280 ChildThreadImpl::Options::Builder::Builder() { |
278 } | 281 } |
279 | 282 |
(...skipping 14 matching lines...) Expand all Loading... |
294 } | 297 } |
295 | 298 |
296 ChildThreadImpl::Options::Builder& | 299 ChildThreadImpl::Options::Builder& |
297 ChildThreadImpl::Options::Builder::AutoStartMojoShellConnection( | 300 ChildThreadImpl::Options::Builder::AutoStartMojoShellConnection( |
298 bool auto_start) { | 301 bool auto_start) { |
299 options_.auto_start_mojo_shell_connection = auto_start; | 302 options_.auto_start_mojo_shell_connection = auto_start; |
300 return *this; | 303 return *this; |
301 } | 304 } |
302 | 305 |
303 ChildThreadImpl::Options::Builder& | 306 ChildThreadImpl::Options::Builder& |
| 307 ChildThreadImpl::Options::Builder::ConnectToBrowser( |
| 308 bool connect_to_browser) { |
| 309 options_.connect_to_browser = connect_to_browser; |
| 310 return *this; |
| 311 } |
| 312 |
| 313 ChildThreadImpl::Options::Builder& |
304 ChildThreadImpl::Options::Builder::WithChannelName( | 314 ChildThreadImpl::Options::Builder::WithChannelName( |
305 const std::string& channel_name) { | 315 const std::string& channel_name) { |
306 options_.channel_name = channel_name; | 316 options_.channel_name = channel_name; |
307 return *this; | 317 return *this; |
308 } | 318 } |
309 | 319 |
310 ChildThreadImpl::Options::Builder& | 320 ChildThreadImpl::Options::Builder& |
311 ChildThreadImpl::Options::Builder::AddStartupFilter( | 321 ChildThreadImpl::Options::Builder::AddStartupFilter( |
312 IPC::MessageFilter* filter) { | 322 IPC::MessageFilter* filter) { |
313 options_.startup_filters.push_back(filter); | 323 options_.startup_filters.push_back(filter); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 mojo_application_token = options.in_process_application_token; | 435 mojo_application_token = options.in_process_application_token; |
426 } | 436 } |
427 if (!mojo_application_token.empty()) { | 437 if (!mojo_application_token.empty()) { |
428 mojo::ScopedMessagePipeHandle handle = | 438 mojo::ScopedMessagePipeHandle handle = |
429 mojo::edk::CreateChildMessagePipe(mojo_application_token); | 439 mojo::edk::CreateChildMessagePipe(mojo_application_token); |
430 DCHECK(handle.is_valid()); | 440 DCHECK(handle.is_valid()); |
431 mojo_shell_connection_ = MojoShellConnection::Create( | 441 mojo_shell_connection_ = MojoShellConnection::Create( |
432 mojo::MakeRequest<shell::mojom::Service>(std::move(handle)), | 442 mojo::MakeRequest<shell::mojom::Service>(std::move(handle)), |
433 GetIOTaskRunner()); | 443 GetIOTaskRunner()); |
434 | 444 |
| 445 // When connect_to_browser is true, we obtain interfaces from the browser |
| 446 // process by connecting to it, rather than from the incoming interface |
| 447 // provider. Exposed interfaces are subject to manifest capability spec. |
| 448 shell::InterfaceProvider* remote_interfaces = nullptr; |
| 449 if (options.connect_to_browser) { |
| 450 browser_connection_ = mojo_shell_connection_->GetConnector()->Connect( |
| 451 kBrowserMojoApplicationName); |
| 452 } else { |
| 453 remote_interfaces = GetRemoteInterfaces(); |
| 454 } |
| 455 |
435 // TODO(rockot): Remove this once all child-to-browser interface connections | 456 // TODO(rockot): Remove this once all child-to-browser interface connections |
436 // are made via a Connector rather than directly through an | 457 // are made via a Connector rather than directly through an |
437 // InterfaceProvider, and all exposed interfaces are exposed via a | 458 // InterfaceProvider, and all exposed interfaces are exposed via a |
438 // ConnectionFilter. | 459 // ConnectionFilter. |
439 mojo_shell_connection_->SetupInterfaceRequestProxies( | 460 mojo_shell_connection_->SetupInterfaceRequestProxies( |
440 GetInterfaceRegistry(), GetRemoteInterfaces()); | 461 GetInterfaceRegistry(), remote_interfaces); |
441 | 462 |
442 if (options.auto_start_mojo_shell_connection) | 463 if (options.auto_start_mojo_shell_connection) |
443 StartMojoShellConnection(); | 464 StartMojoShellConnection(); |
444 } | 465 } |
445 | 466 |
446 sync_message_filter_ = channel_->CreateSyncMessageFilter(); | 467 sync_message_filter_ = channel_->CreateSyncMessageFilter(); |
447 thread_safe_sender_ = new ThreadSafeSender( | 468 thread_safe_sender_ = new ThreadSafeSender( |
448 message_loop_->task_runner(), sync_message_filter_.get()); | 469 message_loop_->task_runner(), sync_message_filter_.get()); |
449 | 470 |
450 resource_dispatcher_.reset(new ResourceDispatcher( | 471 resource_dispatcher_.reset(new ResourceDispatcher( |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 return mojo_shell_connection_.get(); | 640 return mojo_shell_connection_.get(); |
620 } | 641 } |
621 | 642 |
622 shell::InterfaceRegistry* ChildThreadImpl::GetInterfaceRegistry() { | 643 shell::InterfaceRegistry* ChildThreadImpl::GetInterfaceRegistry() { |
623 if (!interface_registry_.get()) | 644 if (!interface_registry_.get()) |
624 interface_registry_.reset(new shell::InterfaceRegistry(nullptr)); | 645 interface_registry_.reset(new shell::InterfaceRegistry(nullptr)); |
625 return interface_registry_.get(); | 646 return interface_registry_.get(); |
626 } | 647 } |
627 | 648 |
628 shell::InterfaceProvider* ChildThreadImpl::GetRemoteInterfaces() { | 649 shell::InterfaceProvider* ChildThreadImpl::GetRemoteInterfaces() { |
| 650 if (browser_connection_) |
| 651 return browser_connection_->GetRemoteInterfaces(); |
| 652 |
629 if (!remote_interfaces_.get()) | 653 if (!remote_interfaces_.get()) |
630 remote_interfaces_.reset(new shell::InterfaceProvider); | 654 remote_interfaces_.reset(new shell::InterfaceProvider); |
631 return remote_interfaces_.get(); | 655 return remote_interfaces_.get(); |
632 } | 656 } |
633 | 657 |
634 IPC::MessageRouter* ChildThreadImpl::GetRouter() { | 658 IPC::MessageRouter* ChildThreadImpl::GetRouter() { |
635 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread()); | 659 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread()); |
636 return &router_; | 660 return &router_; |
637 } | 661 } |
638 | 662 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 void ChildThreadImpl::EnsureConnected() { | 810 void ChildThreadImpl::EnsureConnected() { |
787 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; | 811 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; |
788 base::Process::Current().Terminate(0, false); | 812 base::Process::Current().Terminate(0, false); |
789 } | 813 } |
790 | 814 |
791 bool ChildThreadImpl::IsInBrowserProcess() const { | 815 bool ChildThreadImpl::IsInBrowserProcess() const { |
792 return static_cast<bool>(browser_process_io_runner_); | 816 return static_cast<bool>(browser_process_io_runner_); |
793 } | 817 } |
794 | 818 |
795 } // namespace content | 819 } // namespace content |
OLD | NEW |