Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(913)

Side by Side Diff: content/child/child_thread_impl.cc

Issue 2183703005: Renderers should obtain browser InterfaceProvider by connecting to browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #include "ipc/ipc_channel_mojo.h" 61 #include "ipc/ipc_channel_mojo.h"
62 #include "ipc/ipc_logging.h" 62 #include "ipc/ipc_logging.h"
63 #include "ipc/ipc_platform_file.h" 63 #include "ipc/ipc_platform_file.h"
64 #include "ipc/ipc_switches.h" 64 #include "ipc/ipc_switches.h"
65 #include "ipc/ipc_sync_channel.h" 65 #include "ipc/ipc_sync_channel.h"
66 #include "ipc/ipc_sync_message_filter.h" 66 #include "ipc/ipc_sync_message_filter.h"
67 #include "mojo/edk/embedder/embedder.h" 67 #include "mojo/edk/embedder/embedder.h"
68 #include "mojo/edk/embedder/named_platform_channel_pair.h" 68 #include "mojo/edk/embedder/named_platform_channel_pair.h"
69 #include "mojo/edk/embedder/platform_channel_pair.h" 69 #include "mojo/edk/embedder/platform_channel_pair.h"
70 #include "mojo/edk/embedder/scoped_ipc_support.h" 70 #include "mojo/edk/embedder/scoped_ipc_support.h"
71 #include "services/shell/public/cpp/connector.h"
71 #include "services/shell/public/cpp/interface_provider.h" 72 #include "services/shell/public/cpp/interface_provider.h"
72 #include "services/shell/public/cpp/interface_registry.h" 73 #include "services/shell/public/cpp/interface_registry.h"
73 #include "services/shell/runner/common/client_util.h" 74 #include "services/shell/runner/common/client_util.h"
74 75
75 #if defined(OS_POSIX) 76 #if defined(OS_POSIX)
76 #include "base/posix/global_descriptors.h" 77 #include "base/posix/global_descriptors.h"
77 #include "content/public/common/content_descriptors.h" 78 #include "content/public/common/content_descriptors.h"
78 #endif 79 #endif
79 80
80 using tracked_objects::ThreadData; 81 using tracked_objects::ThreadData;
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 260
260 ChildThread* ChildThread::Get() { 261 ChildThread* ChildThread::Get() {
261 return ChildThreadImpl::current(); 262 return ChildThreadImpl::current();
262 } 263 }
263 264
264 ChildThreadImpl::Options::Options() 265 ChildThreadImpl::Options::Options()
265 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 266 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
266 switches::kProcessChannelID)), 267 switches::kProcessChannelID)),
267 use_mojo_channel(base::CommandLine::ForCurrentProcess()->HasSwitch( 268 use_mojo_channel(base::CommandLine::ForCurrentProcess()->HasSwitch(
268 switches::kMojoChannelToken)), 269 switches::kMojoChannelToken)),
269 auto_start_mojo_shell_connection(true) { 270 auto_start_mojo_shell_connection(true),
271 connect_to_browser(false) {
270 } 272 }
271 273
272 ChildThreadImpl::Options::Options(const Options& other) = default; 274 ChildThreadImpl::Options::Options(const Options& other) = default;
273 275
274 ChildThreadImpl::Options::~Options() { 276 ChildThreadImpl::Options::~Options() {
275 } 277 }
276 278
277 ChildThreadImpl::Options::Builder::Builder() { 279 ChildThreadImpl::Options::Builder::Builder() {
278 } 280 }
279 281
(...skipping 14 matching lines...) Expand all
294 } 296 }
295 297
296 ChildThreadImpl::Options::Builder& 298 ChildThreadImpl::Options::Builder&
297 ChildThreadImpl::Options::Builder::AutoStartMojoShellConnection( 299 ChildThreadImpl::Options::Builder::AutoStartMojoShellConnection(
298 bool auto_start) { 300 bool auto_start) {
299 options_.auto_start_mojo_shell_connection = auto_start; 301 options_.auto_start_mojo_shell_connection = auto_start;
300 return *this; 302 return *this;
301 } 303 }
302 304
303 ChildThreadImpl::Options::Builder& 305 ChildThreadImpl::Options::Builder&
306 ChildThreadImpl::Options::Builder::ConnectToBrowser(
307 bool connect_to_browser) {
308 options_.connect_to_browser = connect_to_browser;
309 return *this;
310 }
311
312 ChildThreadImpl::Options::Builder&
304 ChildThreadImpl::Options::Builder::WithChannelName( 313 ChildThreadImpl::Options::Builder::WithChannelName(
305 const std::string& channel_name) { 314 const std::string& channel_name) {
306 options_.channel_name = channel_name; 315 options_.channel_name = channel_name;
307 return *this; 316 return *this;
308 } 317 }
309 318
310 ChildThreadImpl::Options::Builder& 319 ChildThreadImpl::Options::Builder&
311 ChildThreadImpl::Options::Builder::AddStartupFilter( 320 ChildThreadImpl::Options::Builder::AddStartupFilter(
312 IPC::MessageFilter* filter) { 321 IPC::MessageFilter* filter) {
313 options_.startup_filters.push_back(filter); 322 options_.startup_filters.push_back(filter);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 mojo_application_token = options.in_process_application_token; 434 mojo_application_token = options.in_process_application_token;
426 } 435 }
427 if (!mojo_application_token.empty()) { 436 if (!mojo_application_token.empty()) {
428 mojo::ScopedMessagePipeHandle handle = 437 mojo::ScopedMessagePipeHandle handle =
429 mojo::edk::CreateChildMessagePipe(mojo_application_token); 438 mojo::edk::CreateChildMessagePipe(mojo_application_token);
430 DCHECK(handle.is_valid()); 439 DCHECK(handle.is_valid());
431 mojo_shell_connection_ = MojoShellConnection::Create( 440 mojo_shell_connection_ = MojoShellConnection::Create(
432 mojo::MakeRequest<shell::mojom::Service>(std::move(handle)), 441 mojo::MakeRequest<shell::mojom::Service>(std::move(handle)),
433 GetIOTaskRunner()); 442 GetIOTaskRunner());
434 443
444 // When connect_to_browser_ is true, we obtain interfaces from the browser
445 // process by connecting to it, rather than from the incoming interface
446 // provider. Exposed interfaces are subject to manifest capability spec.
447 connect_to_browser_ = options.connect_to_browser;
448 shell::InterfaceProvider* remote_interfaces = nullptr;
449 if (connect_to_browser_) {
450 browser_connection_ = mojo_shell_connection_->GetConnector()->Connect(
451 "exe:content_browser");
Ken Rockot(use gerrit already) 2016/07/29 17:09:46 We should really move content/browser/mojo/constan
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
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 (connect_to_browser_)
Ken Rockot(use gerrit already) 2016/07/29 17:09:46 Or you could get rid of connect_to_browser_ as a m
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698