| 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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 242 |
| 243 #if defined(OS_WIN) | 243 #if defined(OS_WIN) |
| 244 #define IntToStringType base::IntToString16 | 244 #define IntToStringType base::IntToString16 |
| 245 #else | 245 #else |
| 246 #define IntToStringType base::IntToString | 246 #define IntToStringType base::IntToString |
| 247 #endif | 247 #endif |
| 248 | 248 |
| 249 namespace content { | 249 namespace content { |
| 250 namespace { | 250 namespace { |
| 251 | 251 |
| 252 const char kRendererInterfaceKeyName[] = "mojom_renderer_interface"; | |
| 253 const char kSiteProcessMapKeyName[] = "content_site_process_map"; | 252 const char kSiteProcessMapKeyName[] = "content_site_process_map"; |
| 254 | 253 |
| 255 #ifdef ENABLE_WEBRTC | 254 #ifdef ENABLE_WEBRTC |
| 256 const base::FilePath::CharType kAecDumpFileNameAddition[] = | 255 const base::FilePath::CharType kAecDumpFileNameAddition[] = |
| 257 FILE_PATH_LITERAL("aec_dump"); | 256 FILE_PATH_LITERAL("aec_dump"); |
| 258 #endif | 257 #endif |
| 259 | 258 |
| 260 void CacheShaderInfo(int32_t id, base::FilePath path) { | 259 void CacheShaderInfo(int32_t id, base::FilePath path) { |
| 261 ShaderCacheFactory::GetInstance()->SetCacheInfo(id, path); | 260 ShaderCacheFactory::GetInstance()->SetCacheInfo(id, path); |
| 262 } | 261 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 DCHECK(context); | 358 DCHECK(context); |
| 360 SiteProcessMap* map = static_cast<SiteProcessMap*>( | 359 SiteProcessMap* map = static_cast<SiteProcessMap*>( |
| 361 context->GetUserData(kSiteProcessMapKeyName)); | 360 context->GetUserData(kSiteProcessMapKeyName)); |
| 362 if (!map) { | 361 if (!map) { |
| 363 map = new SiteProcessMap(); | 362 map = new SiteProcessMap(); |
| 364 context->SetUserData(kSiteProcessMapKeyName, map); | 363 context->SetUserData(kSiteProcessMapKeyName, map); |
| 365 } | 364 } |
| 366 return map; | 365 return map; |
| 367 } | 366 } |
| 368 | 367 |
| 369 // Holds a Mojo associated interface proxy in an RPH's user data. | |
| 370 template <typename Interface> | |
| 371 class AssociatedInterfaceHolder : public base::SupportsUserData::Data { | |
| 372 public: | |
| 373 AssociatedInterfaceHolder() {} | |
| 374 ~AssociatedInterfaceHolder() override {} | |
| 375 | |
| 376 mojo::AssociatedInterfacePtr<Interface>& proxy() { return proxy_; } | |
| 377 | |
| 378 private: | |
| 379 mojo::AssociatedInterfacePtr<Interface> proxy_; | |
| 380 | |
| 381 DISALLOW_COPY_AND_ASSIGN(AssociatedInterfaceHolder); | |
| 382 }; | |
| 383 | |
| 384 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) | 368 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) |
| 385 // This static member variable holds the zygote communication information for | 369 // This static member variable holds the zygote communication information for |
| 386 // the renderer. | 370 // the renderer. |
| 387 ZygoteHandle g_render_zygote; | 371 ZygoteHandle g_render_zygote; |
| 388 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) | 372 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) |
| 389 | 373 |
| 390 // NOTE: changes to this class need to be reviewed by the security team. | 374 // NOTE: changes to this class need to be reviewed by the security team. |
| 391 class RendererSandboxedProcessLauncherDelegate | 375 class RendererSandboxedProcessLauncherDelegate |
| 392 : public SandboxedProcessLauncherDelegate { | 376 : public SandboxedProcessLauncherDelegate { |
| 393 public: | 377 public: |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 // We acquire a few associated interface proxies here -- before the channel is | 1009 // We acquire a few associated interface proxies here -- before the channel is |
| 1026 // paused -- to ensure that subsequent initialization messages on those | 1010 // paused -- to ensure that subsequent initialization messages on those |
| 1027 // interfaces behave properly. Specifically, this avoids the risk of an | 1011 // interfaces behave properly. Specifically, this avoids the risk of an |
| 1028 // interface being requested while the Channel is paused, which could | 1012 // interface being requested while the Channel is paused, which could |
| 1029 // effectively and undesirably block the transmission of a subsequent message | 1013 // effectively and undesirably block the transmission of a subsequent message |
| 1030 // on that interface while the Channel is unpaused. | 1014 // on that interface while the Channel is unpaused. |
| 1031 // | 1015 // |
| 1032 // See OnProcessLaunched() for some additional details of this somewhat | 1016 // See OnProcessLaunched() for some additional details of this somewhat |
| 1033 // surprising behavior. | 1017 // surprising behavior. |
| 1034 channel_->GetRemoteAssociatedInterface(&remote_route_provider_); | 1018 channel_->GetRemoteAssociatedInterface(&remote_route_provider_); |
| 1035 | 1019 channel_->GetRemoteAssociatedInterface(&renderer_interface_); |
| 1036 std::unique_ptr<AssociatedInterfaceHolder<mojom::Renderer>> holder = | |
| 1037 base::MakeUnique<AssociatedInterfaceHolder<mojom::Renderer>>(); | |
| 1038 channel_->GetRemoteAssociatedInterface(&holder->proxy()); | |
| 1039 SetUserData(kRendererInterfaceKeyName, holder.release()); | |
| 1040 | 1020 |
| 1041 // We start the Channel in a paused state. It will be briefly unpaused again | 1021 // We start the Channel in a paused state. It will be briefly unpaused again |
| 1042 // in Init() if applicable, before process launch is initiated. | 1022 // in Init() if applicable, before process launch is initiated. |
| 1043 channel_->Pause(); | 1023 channel_->Pause(); |
| 1044 } | 1024 } |
| 1045 | 1025 |
| 1046 void RenderProcessHostImpl::CreateMessageFilters() { | 1026 void RenderProcessHostImpl::CreateMessageFilters() { |
| 1047 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1027 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1048 AddFilter(new ResourceSchedulerFilter(GetID())); | 1028 AddFilter(new ResourceSchedulerFilter(GetID())); |
| 1049 MediaInternals* media_internals = MediaInternals::GetInstance(); | 1029 MediaInternals* media_internals = MediaInternals::GetInstance(); |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1426 | 1406 |
| 1427 bool RenderProcessHostImpl::IsWorkerRefCountDisabled() { | 1407 bool RenderProcessHostImpl::IsWorkerRefCountDisabled() { |
| 1428 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1408 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1429 return is_worker_ref_count_disabled_; | 1409 return is_worker_ref_count_disabled_; |
| 1430 } | 1410 } |
| 1431 | 1411 |
| 1432 void RenderProcessHostImpl::PurgeAndSuspend() { | 1412 void RenderProcessHostImpl::PurgeAndSuspend() { |
| 1433 Send(new ChildProcessMsg_PurgeAndSuspend()); | 1413 Send(new ChildProcessMsg_PurgeAndSuspend()); |
| 1434 } | 1414 } |
| 1435 | 1415 |
| 1416 mojom::Renderer* RenderProcessHostImpl::GetRendererInterface() { |
| 1417 return renderer_interface_.get(); |
| 1418 } |
| 1419 |
| 1436 mojom::RouteProvider* RenderProcessHostImpl::GetRemoteRouteProvider() { | 1420 mojom::RouteProvider* RenderProcessHostImpl::GetRemoteRouteProvider() { |
| 1437 return remote_route_provider_.get(); | 1421 return remote_route_provider_.get(); |
| 1438 } | 1422 } |
| 1439 | 1423 |
| 1440 // static | |
| 1441 mojom::Renderer* RenderProcessHostImpl::GetRendererInterface( | |
| 1442 RenderProcessHost* host) { | |
| 1443 AssociatedInterfaceHolder<mojom::Renderer>* holder = | |
| 1444 static_cast<AssociatedInterfaceHolder<mojom::Renderer>*>( | |
| 1445 host->GetUserData(kRendererInterfaceKeyName)); | |
| 1446 if (!holder) { | |
| 1447 // In tests, MockRenderProcessHost will not have initialized this key on its | |
| 1448 // own. We do it with a dead-end endpoint so outgoing requests are silently | |
| 1449 // dropped. | |
| 1450 holder = new AssociatedInterfaceHolder<mojom::Renderer>; | |
| 1451 host->SetUserData(kRendererInterfaceKeyName, holder); | |
| 1452 mojo::GetDummyProxyForTesting(&holder->proxy()); | |
| 1453 } | |
| 1454 | |
| 1455 return holder->proxy().get(); | |
| 1456 } | |
| 1457 | |
| 1458 void RenderProcessHostImpl::AddRoute(int32_t routing_id, | 1424 void RenderProcessHostImpl::AddRoute(int32_t routing_id, |
| 1459 IPC::Listener* listener) { | 1425 IPC::Listener* listener) { |
| 1460 CHECK(!listeners_.Lookup(routing_id)) << "Found Routing ID Conflict: " | 1426 CHECK(!listeners_.Lookup(routing_id)) << "Found Routing ID Conflict: " |
| 1461 << routing_id; | 1427 << routing_id; |
| 1462 listeners_.AddWithID(listener, routing_id); | 1428 listeners_.AddWithID(listener, routing_id); |
| 1463 } | 1429 } |
| 1464 | 1430 |
| 1465 void RenderProcessHostImpl::RemoveRoute(int32_t routing_id) { | 1431 void RenderProcessHostImpl::RemoveRoute(int32_t routing_id) { |
| 1466 DCHECK(listeners_.Lookup(routing_id) != nullptr); | 1432 DCHECK(listeners_.Lookup(routing_id) != nullptr); |
| 1467 listeners_.Remove(routing_id); | 1433 listeners_.Remove(routing_id); |
| (...skipping 1229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2697 } | 2663 } |
| 2698 | 2664 |
| 2699 RendererClosedDetails details(status, exit_code); | 2665 RendererClosedDetails details(status, exit_code); |
| 2700 | 2666 |
| 2701 child_process_launcher_.reset(); | 2667 child_process_launcher_.reset(); |
| 2702 is_dead_ = true; | 2668 is_dead_ = true; |
| 2703 | 2669 |
| 2704 // Clear all cached associated interface proxies as well, since these are | 2670 // Clear all cached associated interface proxies as well, since these are |
| 2705 // effectively bound to the lifetime of the Channel. | 2671 // effectively bound to the lifetime of the Channel. |
| 2706 remote_route_provider_.reset(); | 2672 remote_route_provider_.reset(); |
| 2707 RemoveUserData(kRendererInterfaceKeyName); | 2673 renderer_interface_.reset(); |
| 2708 | 2674 |
| 2709 UpdateProcessPriority(); | 2675 UpdateProcessPriority(); |
| 2710 DCHECK(!is_process_backgrounded_); | 2676 DCHECK(!is_process_backgrounded_); |
| 2711 | 2677 |
| 2712 within_process_died_observer_ = true; | 2678 within_process_died_observer_ = true; |
| 2713 NotificationService::current()->Notify( | 2679 NotificationService::current()->Notify( |
| 2714 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), | 2680 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), |
| 2715 Details<RendererClosedDetails>(&details)); | 2681 Details<RendererClosedDetails>(&details)); |
| 2716 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, | 2682 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, |
| 2717 RenderProcessExited(this, status, exit_code)); | 2683 RenderProcessExited(this, status, exit_code)); |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3036 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 3002 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
| 3037 | 3003 |
| 3038 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias | 3004 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias |
| 3039 // enough information here so that we can determine what the bad message was. | 3005 // enough information here so that we can determine what the bad message was. |
| 3040 base::debug::Alias(&error); | 3006 base::debug::Alias(&error); |
| 3041 bad_message::ReceivedBadMessage(render_process_id, | 3007 bad_message::ReceivedBadMessage(render_process_id, |
| 3042 bad_message::RPH_MOJO_PROCESS_ERROR); | 3008 bad_message::RPH_MOJO_PROCESS_ERROR); |
| 3043 } | 3009 } |
| 3044 | 3010 |
| 3045 } // namespace content | 3011 } // namespace content |
| OLD | NEW |