| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 #include "ipc/ipc_channel.h" | 176 #include "ipc/ipc_channel.h" |
| 177 #include "ipc/ipc_channel_mojo.h" | 177 #include "ipc/ipc_channel_mojo.h" |
| 178 #include "ipc/ipc_logging.h" | 178 #include "ipc/ipc_logging.h" |
| 179 #include "media/base/media_switches.h" | 179 #include "media/base/media_switches.h" |
| 180 #include "media/media_features.h" | 180 #include "media/media_features.h" |
| 181 #include "mojo/edk/embedder/embedder.h" | 181 #include "mojo/edk/embedder/embedder.h" |
| 182 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" | 182 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" |
| 183 #include "net/url_request/url_request_context_getter.h" | 183 #include "net/url_request/url_request_context_getter.h" |
| 184 #include "ppapi/features/features.h" | 184 #include "ppapi/features/features.h" |
| 185 #include "services/resource_coordinator/memory/coordinator/coordinator_impl.h" | 185 #include "services/resource_coordinator/memory/coordinator/coordinator_impl.h" |
| 186 #include "services/service_manager/public/cpp/binder_registry.h" |
| 186 #include "services/service_manager/public/cpp/connection.h" | 187 #include "services/service_manager/public/cpp/connection.h" |
| 187 #include "services/service_manager/public/cpp/connector.h" | 188 #include "services/service_manager/public/cpp/connector.h" |
| 188 #include "services/service_manager/public/cpp/interface_provider.h" | 189 #include "services/service_manager/public/cpp/interface_provider.h" |
| 189 #include "services/service_manager/public/cpp/interface_registry.h" | |
| 190 #include "services/service_manager/runner/common/client_util.h" | 190 #include "services/service_manager/runner/common/client_util.h" |
| 191 #include "services/service_manager/runner/common/switches.h" | 191 #include "services/service_manager/runner/common/switches.h" |
| 192 #include "services/shape_detection/public/interfaces/barcodedetection.mojom.h" | 192 #include "services/shape_detection/public/interfaces/barcodedetection.mojom.h" |
| 193 #include "services/shape_detection/public/interfaces/constants.mojom.h" | 193 #include "services/shape_detection/public/interfaces/constants.mojom.h" |
| 194 #include "services/shape_detection/public/interfaces/facedetection_provider.mojo
m.h" | 194 #include "services/shape_detection/public/interfaces/facedetection_provider.mojo
m.h" |
| 195 #include "services/shape_detection/public/interfaces/textdetection.mojom.h" | 195 #include "services/shape_detection/public/interfaces/textdetection.mojom.h" |
| 196 #include "storage/browser/fileapi/sandbox_file_system_backend.h" | 196 #include "storage/browser/fileapi/sandbox_file_system_backend.h" |
| 197 #include "third_party/WebKit/public/public_features.h" | 197 #include "third_party/WebKit/public/public_features.h" |
| 198 #include "third_party/skia/include/core/SkBitmap.h" | 198 #include "third_party/skia/include/core/SkBitmap.h" |
| 199 #include "ui/base/ui_base_switches.h" | 199 #include "ui/base/ui_base_switches.h" |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 base::Lock lock_; | 512 base::Lock lock_; |
| 513 ConnectionFilterImpl* filter_; | 513 ConnectionFilterImpl* filter_; |
| 514 }; | 514 }; |
| 515 | 515 |
| 516 // Held by the RPH's BrowserContext's ServiceManagerConnection, ownership | 516 // Held by the RPH's BrowserContext's ServiceManagerConnection, ownership |
| 517 // transferred back to RPH upon RPH destruction. | 517 // transferred back to RPH upon RPH destruction. |
| 518 class RenderProcessHostImpl::ConnectionFilterImpl : public ConnectionFilter { | 518 class RenderProcessHostImpl::ConnectionFilterImpl : public ConnectionFilter { |
| 519 public: | 519 public: |
| 520 ConnectionFilterImpl( | 520 ConnectionFilterImpl( |
| 521 const service_manager::Identity& child_identity, | 521 const service_manager::Identity& child_identity, |
| 522 std::unique_ptr<service_manager::InterfaceRegistry> registry) | 522 std::unique_ptr<service_manager::BinderRegistry> registry) |
| 523 : child_identity_(child_identity), | 523 : child_identity_(child_identity), |
| 524 registry_(std::move(registry)), | 524 registry_(std::move(registry)), |
| 525 controller_(new ConnectionFilterController(this)), | 525 controller_(new ConnectionFilterController(this)), |
| 526 weak_factory_(this) { | 526 weak_factory_(this) { |
| 527 // Registration of this filter may race with browser shutdown, in which case | 527 // Registration of this filter may race with browser shutdown, in which case |
| 528 // it's possible for this filter to be destroyed on the main thread. This | 528 // it's possible for this filter to be destroyed on the main thread. This |
| 529 // is fine as long as the filter hasn't been used on the IO thread yet. We | 529 // is fine as long as the filter hasn't been used on the IO thread yet. We |
| 530 // detach the ThreadChecker initially and the first use of the filter will | 530 // detach the ThreadChecker initially and the first use of the filter will |
| 531 // bind it. | 531 // bind it. |
| 532 thread_checker_.DetachFromThread(); | 532 thread_checker_.DetachFromThread(); |
| 533 } | 533 } |
| 534 | 534 |
| 535 ~ConnectionFilterImpl() override { | 535 ~ConnectionFilterImpl() override { |
| 536 DCHECK(thread_checker_.CalledOnValidThread()); | 536 DCHECK(thread_checker_.CalledOnValidThread()); |
| 537 controller_->Detach(); | 537 controller_->Detach(); |
| 538 } | 538 } |
| 539 | 539 |
| 540 scoped_refptr<ConnectionFilterController> controller() { return controller_; } | 540 scoped_refptr<ConnectionFilterController> controller() { return controller_; } |
| 541 | 541 |
| 542 void Disable() { | 542 void Disable() { |
| 543 base::AutoLock lock(enabled_lock_); | 543 base::AutoLock lock(enabled_lock_); |
| 544 enabled_ = false; | 544 enabled_ = false; |
| 545 } | 545 } |
| 546 | 546 |
| 547 private: | 547 private: |
| 548 // ConnectionFilter: | 548 // ConnectionFilter: |
| 549 bool OnConnect(const service_manager::Identity& remote_identity, | 549 void OnBindInterface(const service_manager::ServiceInfo& source_info, |
| 550 service_manager::InterfaceRegistry* registry, | 550 const std::string& interface_name, |
| 551 service_manager::Connector* connector) override { | 551 mojo::ScopedMessagePipeHandle* interface_pipe, |
| 552 service_manager::Connector* connector) override { |
| 552 DCHECK(thread_checker_.CalledOnValidThread()); | 553 DCHECK(thread_checker_.CalledOnValidThread()); |
| 553 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 554 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 554 // We only fulfill connections from the renderer we host. | 555 // We only fulfill connections from the renderer we host. |
| 555 if (child_identity_.name() != remote_identity.name() || | 556 if (child_identity_.name() != source_info.identity.name() || |
| 556 child_identity_.instance() != remote_identity.instance()) { | 557 child_identity_.instance() != source_info.identity.instance()) { |
| 557 return false; | 558 return; |
| 558 } | 559 } |
| 559 | 560 |
| 560 base::AutoLock lock(enabled_lock_); | 561 base::AutoLock lock(enabled_lock_); |
| 561 if (!enabled_) | 562 if (!enabled_) |
| 562 return false; | 563 return; |
| 563 | 564 |
| 564 std::set<std::string> interface_names; | 565 if (registry_->CanBindInterface(interface_name)) { |
| 565 registry_->GetInterfaceNames(&interface_names); | 566 registry_->BindInterface(source_info.identity, interface_name, |
| 566 for (auto& interface_name : interface_names) { | 567 std::move(*interface_pipe)); |
| 567 // Note that the added callbacks may outlive this object, which is | |
| 568 // destroyed in RPH::Cleanup(). | |
| 569 registry->AddInterface(interface_name, | |
| 570 base::Bind(&ConnectionFilterImpl::GetInterface, | |
| 571 weak_factory_.GetWeakPtr(), | |
| 572 interface_name)); | |
| 573 } | 568 } |
| 574 return true; | |
| 575 } | |
| 576 | |
| 577 void GetInterface(const std::string& interface_name, | |
| 578 mojo::ScopedMessagePipeHandle handle) { | |
| 579 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 580 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 581 service_manager::mojom::InterfaceProvider* provider = registry_.get(); | |
| 582 | |
| 583 base::AutoLock lock(enabled_lock_); | |
| 584 if (enabled_) | |
| 585 provider->GetInterface(interface_name, std::move(handle)); | |
| 586 } | 569 } |
| 587 | 570 |
| 588 base::ThreadChecker thread_checker_; | 571 base::ThreadChecker thread_checker_; |
| 589 service_manager::Identity child_identity_; | 572 service_manager::Identity child_identity_; |
| 590 std::unique_ptr<service_manager::InterfaceRegistry> registry_; | 573 std::unique_ptr<service_manager::BinderRegistry> registry_; |
| 591 scoped_refptr<ConnectionFilterController> controller_; | 574 scoped_refptr<ConnectionFilterController> controller_; |
| 592 | 575 |
| 593 // Guards |enabled_|. | 576 // Guards |enabled_|. |
| 594 base::Lock enabled_lock_; | 577 base::Lock enabled_lock_; |
| 595 bool enabled_ = true; | 578 bool enabled_ = true; |
| 596 | 579 |
| 597 base::WeakPtrFactory<ConnectionFilterImpl> weak_factory_; | 580 base::WeakPtrFactory<ConnectionFilterImpl> weak_factory_; |
| 598 | 581 |
| 599 DISALLOW_COPY_AND_ASSIGN(ConnectionFilterImpl); | 582 DISALLOW_COPY_AND_ASSIGN(ConnectionFilterImpl); |
| 600 }; | 583 }; |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 pending_connection_.reset(new mojo::edk::PendingProcessConnection); | 953 pending_connection_.reset(new mojo::edk::PendingProcessConnection); |
| 971 child_connection_.reset(new ChildConnection( | 954 child_connection_.reset(new ChildConnection( |
| 972 mojom::kRendererServiceName, | 955 mojom::kRendererServiceName, |
| 973 base::StringPrintf("%d_%d", id_, instance_id_++), | 956 base::StringPrintf("%d_%d", id_, instance_id_++), |
| 974 pending_connection_.get(), connector, io_task_runner)); | 957 pending_connection_.get(), connector, io_task_runner)); |
| 975 | 958 |
| 976 // Send an interface request to bootstrap the IPC::Channel. Note that this | 959 // Send an interface request to bootstrap the IPC::Channel. Note that this |
| 977 // request will happily sit on the pipe until the process is launched and | 960 // request will happily sit on the pipe until the process is launched and |
| 978 // connected to the ServiceManager. We take the other end immediately and | 961 // connected to the ServiceManager. We take the other end immediately and |
| 979 // plug it into a new ChannelProxy. | 962 // plug it into a new ChannelProxy. |
| 980 IPC::mojom::ChannelBootstrapPtr bootstrap; | 963 mojo::MessagePipe pipe; |
| 981 GetRemoteInterfaces()->GetInterface(&bootstrap); | 964 BindInterface(IPC::mojom::ChannelBootstrap::Name_, std::move(pipe.handle1)); |
| 982 std::unique_ptr<IPC::ChannelFactory> channel_factory = | 965 std::unique_ptr<IPC::ChannelFactory> channel_factory = |
| 983 IPC::ChannelMojo::CreateServerFactory( | 966 IPC::ChannelMojo::CreateServerFactory(std::move(pipe.handle0), |
| 984 bootstrap.PassInterface().PassHandle(), io_task_runner); | 967 io_task_runner); |
| 985 | 968 |
| 986 ResetChannelProxy(); | 969 ResetChannelProxy(); |
| 987 | 970 |
| 988 // Do NOT expand ifdef or run time condition checks here! Synchronous | 971 // Do NOT expand ifdef or run time condition checks here! Synchronous |
| 989 // IPCs from browser process are banned. It is only narrowly allowed | 972 // IPCs from browser process are banned. It is only narrowly allowed |
| 990 // for Android WebView to maintain backward compatibility. | 973 // for Android WebView to maintain backward compatibility. |
| 991 // See crbug.com/526842 for details. | 974 // See crbug.com/526842 for details. |
| 992 #if defined(OS_ANDROID) | 975 #if defined(OS_ANDROID) |
| 993 if (GetContentClient()->UsingSynchronousCompositing()) { | 976 if (GetContentClient()->UsingSynchronousCompositing()) { |
| 994 channel_ = IPC::SyncChannel::Create( | 977 channel_ = IPC::SyncChannel::Create( |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1194 AddFilter(new HistogramMessageFilter()); | 1177 AddFilter(new HistogramMessageFilter()); |
| 1195 AddFilter(new MemoryMessageFilter(this)); | 1178 AddFilter(new MemoryMessageFilter(this)); |
| 1196 #if defined(OS_ANDROID) | 1179 #if defined(OS_ANDROID) |
| 1197 synchronous_compositor_filter_ = | 1180 synchronous_compositor_filter_ = |
| 1198 new SynchronousCompositorBrowserFilter(GetID()); | 1181 new SynchronousCompositorBrowserFilter(GetID()); |
| 1199 AddFilter(synchronous_compositor_filter_.get()); | 1182 AddFilter(synchronous_compositor_filter_.get()); |
| 1200 #endif | 1183 #endif |
| 1201 } | 1184 } |
| 1202 | 1185 |
| 1203 void RenderProcessHostImpl::RegisterMojoInterfaces() { | 1186 void RenderProcessHostImpl::RegisterMojoInterfaces() { |
| 1204 auto registry = base::MakeUnique<service_manager::InterfaceRegistry>( | 1187 auto registry = base::MakeUnique<service_manager::BinderRegistry>(); |
| 1205 service_manager::mojom::kServiceManager_ConnectorSpec); | |
| 1206 | 1188 |
| 1207 channel_->AddAssociatedInterfaceForIOThread( | 1189 channel_->AddAssociatedInterfaceForIOThread( |
| 1208 base::Bind(&IndexedDBDispatcherHost::AddBinding, indexed_db_factory_)); | 1190 base::Bind(&IndexedDBDispatcherHost::AddBinding, indexed_db_factory_)); |
| 1209 | 1191 |
| 1210 #if defined(OS_ANDROID) | 1192 #if defined(OS_ANDROID) |
| 1211 AddUIThreadInterface( | 1193 AddUIThreadInterface( |
| 1212 registry.get(), GetGlobalJavaInterfaces() | 1194 registry.get(), GetGlobalJavaInterfaces() |
| 1213 ->CreateInterfaceFactory< | 1195 ->CreateInterfaceFactory< |
| 1214 shape_detection::mojom::FaceDetectionProvider>()); | 1196 shape_detection::mojom::FaceDetectionProvider>()); |
| 1215 AddUIThreadInterface( | 1197 AddUIThreadInterface( |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1391 | 1373 |
| 1392 int RenderProcessHostImpl::GetNextRoutingID() { | 1374 int RenderProcessHostImpl::GetNextRoutingID() { |
| 1393 return widget_helper_->GetNextRoutingID(); | 1375 return widget_helper_->GetNextRoutingID(); |
| 1394 } | 1376 } |
| 1395 | 1377 |
| 1396 void RenderProcessHostImpl::ResumeDeferredNavigation( | 1378 void RenderProcessHostImpl::ResumeDeferredNavigation( |
| 1397 const GlobalRequestID& request_id) { | 1379 const GlobalRequestID& request_id) { |
| 1398 widget_helper_->ResumeDeferredNavigation(request_id); | 1380 widget_helper_->ResumeDeferredNavigation(request_id); |
| 1399 } | 1381 } |
| 1400 | 1382 |
| 1401 service_manager::InterfaceProvider* | 1383 void RenderProcessHostImpl::BindInterface( |
| 1402 RenderProcessHostImpl::GetRemoteInterfaces() { | 1384 const std::string& interface_name, |
| 1403 return child_connection_->GetRemoteInterfaces(); | 1385 mojo::ScopedMessagePipeHandle interface_pipe) { |
| 1386 child_connection_->BindInterface(interface_name, std::move(interface_pipe)); |
| 1404 } | 1387 } |
| 1405 | 1388 |
| 1406 std::unique_ptr<base::SharedPersistentMemoryAllocator> | 1389 std::unique_ptr<base::SharedPersistentMemoryAllocator> |
| 1407 RenderProcessHostImpl::TakeMetricsAllocator() { | 1390 RenderProcessHostImpl::TakeMetricsAllocator() { |
| 1408 return std::move(metrics_allocator_); | 1391 return std::move(metrics_allocator_); |
| 1409 } | 1392 } |
| 1410 | 1393 |
| 1411 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() | 1394 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() |
| 1412 const { | 1395 const { |
| 1413 return init_time_; | 1396 return init_time_; |
| (...skipping 1657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3071 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 3054 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
| 3072 | 3055 |
| 3073 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. | 3056 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. |
| 3074 // Capture the error message in a crash key value. | 3057 // Capture the error message in a crash key value. |
| 3075 base::debug::ScopedCrashKey error_key_value("mojo-message-error", error); | 3058 base::debug::ScopedCrashKey error_key_value("mojo-message-error", error); |
| 3076 bad_message::ReceivedBadMessage(render_process_id, | 3059 bad_message::ReceivedBadMessage(render_process_id, |
| 3077 bad_message::RPH_MOJO_PROCESS_ERROR); | 3060 bad_message::RPH_MOJO_PROCESS_ERROR); |
| 3078 } | 3061 } |
| 3079 | 3062 |
| 3080 } // namespace content | 3063 } // namespace content |
| OLD | NEW |