| 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 #include "content/public/common/url_constants.h" | 157 #include "content/public/common/url_constants.h" |
| 158 #include "device/battery/battery_monitor_impl.h" | 158 #include "device/battery/battery_monitor_impl.h" |
| 159 #include "gpu/GLES2/gl2extchromium.h" | 159 #include "gpu/GLES2/gl2extchromium.h" |
| 160 #include "gpu/command_buffer/client/gpu_switches.h" | 160 #include "gpu/command_buffer/client/gpu_switches.h" |
| 161 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 161 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 162 #include "gpu/command_buffer/service/gpu_switches.h" | 162 #include "gpu/command_buffer/service/gpu_switches.h" |
| 163 #include "ipc/attachment_broker.h" | 163 #include "ipc/attachment_broker.h" |
| 164 #include "ipc/attachment_broker_privileged.h" | 164 #include "ipc/attachment_broker_privileged.h" |
| 165 #include "ipc/ipc_channel.h" | 165 #include "ipc/ipc_channel.h" |
| 166 #include "ipc/ipc_logging.h" | 166 #include "ipc/ipc_logging.h" |
| 167 #include "ipc/ipc_sender.h" |
| 167 #include "ipc/ipc_switches.h" | 168 #include "ipc/ipc_switches.h" |
| 168 #include "ipc/mojo/ipc_channel_mojo.h" | 169 #include "ipc/mojo/ipc_channel_mojo.h" |
| 169 #include "media/base/media_switches.h" | 170 #include "media/base/media_switches.h" |
| 170 #include "mojo/edk/embedder/embedder.h" | 171 #include "mojo/edk/embedder/embedder.h" |
| 171 #include "net/url_request/url_request_context_getter.h" | 172 #include "net/url_request/url_request_context_getter.h" |
| 172 #include "ppapi/shared_impl/ppapi_switches.h" | 173 #include "ppapi/shared_impl/ppapi_switches.h" |
| 173 #include "services/shell/runner/common/switches.h" | 174 #include "services/shell/runner/common/switches.h" |
| 174 #include "storage/browser/fileapi/sandbox_file_system_backend.h" | 175 #include "storage/browser/fileapi/sandbox_file_system_backend.h" |
| 175 #include "third_party/skia/include/core/SkBitmap.h" | 176 #include "third_party/skia/include/core/SkBitmap.h" |
| 176 #include "ui/base/ui_base_switches.h" | 177 #include "ui/base/ui_base_switches.h" |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 for (auto it : vector) { | 441 for (auto it : vector) { |
| 441 if (!str.empty()) | 442 if (!str.empty()) |
| 442 str += ","; | 443 str += ","; |
| 443 str += base::UintToString(it); | 444 str += base::UintToString(it); |
| 444 } | 445 } |
| 445 return str; | 446 return str; |
| 446 } | 447 } |
| 447 | 448 |
| 448 } // namespace | 449 } // namespace |
| 449 | 450 |
| 451 // SafeSenderProxy owns two IPC::Sender implementations which proxy to the |
| 452 // RPH's own ChannelProxy. One enables immediate sends while the other enables |
| 453 // IO-thread sends. These are both implemented via RPHI's SendImpl which safely |
| 454 // avoids dereferencing the underlying ChannelProxy if it's been reset (e.g. |
| 455 // after process death.) |
| 456 class RenderProcessHostImpl::SafeSenderProxy { |
| 457 public: |
| 458 // |process| must outlive this object. |
| 459 explicit SafeSenderProxy(RenderProcessHostImpl* process) |
| 460 : process_(process), |
| 461 immediate_sender_(this, true /* send_now */), |
| 462 io_thread_sender_(this, false /* send_now */) {} |
| 463 ~SafeSenderProxy() {} |
| 464 |
| 465 IPC::Sender* immediate_sender() { return &immediate_sender_; } |
| 466 IPC::Sender* io_thread_sender() { return &io_thread_sender_; } |
| 467 |
| 468 bool SendImpl(IPC::Message* message, bool send_now) { |
| 469 return process_->SendImpl(message, send_now); |
| 470 } |
| 471 |
| 472 private: |
| 473 class SenderProxy : public IPC::Sender { |
| 474 public: |
| 475 SenderProxy(SafeSenderProxy* safe_proxy, bool send_now) |
| 476 : safe_proxy_(safe_proxy), send_now_(send_now) {} |
| 477 ~SenderProxy() override {} |
| 478 |
| 479 // IPC::Sender: |
| 480 bool Send(IPC::Message* message) override { |
| 481 return safe_proxy_->SendImpl(message, send_now_); |
| 482 } |
| 483 |
| 484 private: |
| 485 SafeSenderProxy* const safe_proxy_; |
| 486 const bool send_now_; |
| 487 |
| 488 DISALLOW_COPY_AND_ASSIGN(SenderProxy); |
| 489 }; |
| 490 |
| 491 RenderProcessHostImpl* process_; |
| 492 SenderProxy immediate_sender_; |
| 493 SenderProxy io_thread_sender_; |
| 494 |
| 495 DISALLOW_COPY_AND_ASSIGN(SafeSenderProxy); |
| 496 }; |
| 497 |
| 450 RendererMainThreadFactoryFunction g_renderer_main_thread_factory = NULL; | 498 RendererMainThreadFactoryFunction g_renderer_main_thread_factory = NULL; |
| 451 | 499 |
| 452 base::MessageLoop* g_in_process_thread; | 500 base::MessageLoop* g_in_process_thread; |
| 453 | 501 |
| 454 base::MessageLoop* | 502 base::MessageLoop* |
| 455 RenderProcessHostImpl::GetInProcessRendererThreadForTesting() { | 503 RenderProcessHostImpl::GetInProcessRendererThreadForTesting() { |
| 456 return g_in_process_thread; | 504 return g_in_process_thread; |
| 457 } | 505 } |
| 458 | 506 |
| 459 // Stores the maximum number of renderer processes the content module can | 507 // Stores the maximum number of renderer processes the content module can |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 RenderProcessHostImpl::RenderProcessHostImpl( | 577 RenderProcessHostImpl::RenderProcessHostImpl( |
| 530 BrowserContext* browser_context, | 578 BrowserContext* browser_context, |
| 531 StoragePartitionImpl* storage_partition_impl, | 579 StoragePartitionImpl* storage_partition_impl, |
| 532 bool is_for_guests_only) | 580 bool is_for_guests_only) |
| 533 : fast_shutdown_started_(false), | 581 : fast_shutdown_started_(false), |
| 534 deleting_soon_(false), | 582 deleting_soon_(false), |
| 535 #ifndef NDEBUG | 583 #ifndef NDEBUG |
| 536 is_self_deleted_(false), | 584 is_self_deleted_(false), |
| 537 #endif | 585 #endif |
| 538 pending_views_(0), | 586 pending_views_(0), |
| 587 safe_sender_(new SafeSenderProxy(this)), |
| 539 mojo_application_host_(new MojoApplicationHost), | 588 mojo_application_host_(new MojoApplicationHost), |
| 540 visible_widgets_(0), | 589 visible_widgets_(0), |
| 541 is_process_backgrounded_(false), | 590 is_process_backgrounded_(false), |
| 542 is_initialized_(false), | 591 is_initialized_(false), |
| 543 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), | 592 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), |
| 544 browser_context_(browser_context), | 593 browser_context_(browser_context), |
| 545 storage_partition_impl_(storage_partition_impl), | 594 storage_partition_impl_(storage_partition_impl), |
| 546 sudden_termination_allowed_(true), | 595 sudden_termination_allowed_(true), |
| 547 ignore_input_events_(false), | 596 ignore_input_events_(false), |
| 548 is_for_guests_only_(is_for_guests_only), | 597 is_for_guests_only_(is_for_guests_only), |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1008 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) | 1057 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
| 1009 enable_web_bluetooth = true; | 1058 enable_web_bluetooth = true; |
| 1010 #endif | 1059 #endif |
| 1011 | 1060 |
| 1012 if (enable_web_bluetooth) { | 1061 if (enable_web_bluetooth) { |
| 1013 bluetooth_dispatcher_host_ = new BluetoothDispatcherHost(GetID()); | 1062 bluetooth_dispatcher_host_ = new BluetoothDispatcherHost(GetID()); |
| 1014 AddFilter(bluetooth_dispatcher_host_.get()); | 1063 AddFilter(bluetooth_dispatcher_host_.get()); |
| 1015 } | 1064 } |
| 1016 } | 1065 } |
| 1017 | 1066 |
| 1067 bool RenderProcessHostImpl::SendImpl(IPC::Message* msg, bool send_now) { |
| 1068 TRACE_EVENT0("renderer_host", "RenderProcessHostImpl::SendImpl"); |
| 1069 #if !defined(OS_ANDROID) |
| 1070 DCHECK(!msg->is_sync()); |
| 1071 #endif |
| 1072 |
| 1073 if (!channel_) { |
| 1074 #if defined(OS_ANDROID) |
| 1075 if (msg->is_sync()) { |
| 1076 delete msg; |
| 1077 return false; |
| 1078 } |
| 1079 #endif |
| 1080 if (!is_initialized_) { |
| 1081 queued_messages_.push(msg); |
| 1082 return true; |
| 1083 } else { |
| 1084 delete msg; |
| 1085 return false; |
| 1086 } |
| 1087 } |
| 1088 |
| 1089 if (child_process_launcher_.get() && child_process_launcher_->IsStarting()) { |
| 1090 #if defined(OS_ANDROID) |
| 1091 if (msg->is_sync()) { |
| 1092 delete msg; |
| 1093 return false; |
| 1094 } |
| 1095 #endif |
| 1096 queued_messages_.push(msg); |
| 1097 return true; |
| 1098 } |
| 1099 |
| 1100 if (send_now) |
| 1101 return channel_->SendNow(msg); |
| 1102 |
| 1103 return channel_->SendOnIPCThread(msg); |
| 1104 } |
| 1105 |
| 1018 void RenderProcessHostImpl::RegisterMojoServices() { | 1106 void RenderProcessHostImpl::RegisterMojoServices() { |
| 1019 #if !defined(OS_ANDROID) | 1107 #if !defined(OS_ANDROID) |
| 1020 mojo_application_host_->service_registry()->AddService( | 1108 mojo_application_host_->service_registry()->AddService( |
| 1021 base::Bind(&device::BatteryMonitorImpl::Create)); | 1109 base::Bind(&device::BatteryMonitorImpl::Create)); |
| 1022 #endif | 1110 #endif |
| 1023 | 1111 |
| 1024 mojo_application_host_->service_registry()->AddService( | 1112 mojo_application_host_->service_registry()->AddService( |
| 1025 base::Bind(&PermissionServiceContext::CreateService, | 1113 base::Bind(&PermissionServiceContext::CreateService, |
| 1026 base::Unretained(permission_service_context_.get()))); | 1114 base::Unretained(permission_service_context_.get()))); |
| 1027 | 1115 |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1635 | 1723 |
| 1636 // Set this before ProcessDied() so observers can tell if the render process | 1724 // Set this before ProcessDied() so observers can tell if the render process |
| 1637 // died due to fast shutdown versus another cause. | 1725 // died due to fast shutdown versus another cause. |
| 1638 fast_shutdown_started_ = true; | 1726 fast_shutdown_started_ = true; |
| 1639 | 1727 |
| 1640 ProcessDied(false /* already_dead */, nullptr); | 1728 ProcessDied(false /* already_dead */, nullptr); |
| 1641 return true; | 1729 return true; |
| 1642 } | 1730 } |
| 1643 | 1731 |
| 1644 bool RenderProcessHostImpl::Send(IPC::Message* msg) { | 1732 bool RenderProcessHostImpl::Send(IPC::Message* msg) { |
| 1645 TRACE_EVENT0("renderer_host", "RenderProcessHostImpl::Send"); | 1733 return SendImpl(msg, false /* send_now */); |
| 1646 #if !defined(OS_ANDROID) | |
| 1647 DCHECK(!msg->is_sync()); | |
| 1648 #endif | |
| 1649 | |
| 1650 if (!channel_) { | |
| 1651 #if defined(OS_ANDROID) | |
| 1652 if (msg->is_sync()) { | |
| 1653 delete msg; | |
| 1654 return false; | |
| 1655 } | |
| 1656 #endif | |
| 1657 if (!is_initialized_) { | |
| 1658 queued_messages_.push(msg); | |
| 1659 return true; | |
| 1660 } else { | |
| 1661 delete msg; | |
| 1662 return false; | |
| 1663 } | |
| 1664 } | |
| 1665 | |
| 1666 if (child_process_launcher_.get() && child_process_launcher_->IsStarting()) { | |
| 1667 #if defined(OS_ANDROID) | |
| 1668 if (msg->is_sync()) { | |
| 1669 delete msg; | |
| 1670 return false; | |
| 1671 } | |
| 1672 #endif | |
| 1673 queued_messages_.push(msg); | |
| 1674 return true; | |
| 1675 } | |
| 1676 | |
| 1677 return channel_->Send(msg); | |
| 1678 } | 1734 } |
| 1679 | 1735 |
| 1680 bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { | 1736 bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { |
| 1681 // If we're about to be deleted, or have initiated the fast shutdown sequence, | 1737 // If we're about to be deleted, or have initiated the fast shutdown sequence, |
| 1682 // we ignore incoming messages. | 1738 // we ignore incoming messages. |
| 1683 | 1739 |
| 1684 if (deleting_soon_ || fast_shutdown_started_) | 1740 if (deleting_soon_ || fast_shutdown_started_) |
| 1685 return false; | 1741 return false; |
| 1686 | 1742 |
| 1687 mark_child_process_activity_time(); | 1743 mark_child_process_activity_time(); |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2023 p2p_socket_dispatcher_host_); | 2079 p2p_socket_dispatcher_host_); |
| 2024 } | 2080 } |
| 2025 return stop_rtp_dump_callback_; | 2081 return stop_rtp_dump_callback_; |
| 2026 } | 2082 } |
| 2027 #endif | 2083 #endif |
| 2028 | 2084 |
| 2029 IPC::ChannelProxy* RenderProcessHostImpl::GetChannel() { | 2085 IPC::ChannelProxy* RenderProcessHostImpl::GetChannel() { |
| 2030 return channel_.get(); | 2086 return channel_.get(); |
| 2031 } | 2087 } |
| 2032 | 2088 |
| 2089 IPC::Sender* RenderProcessHostImpl::GetImmediateSender() { |
| 2090 return safe_sender_->immediate_sender(); |
| 2091 } |
| 2092 |
| 2093 IPC::Sender* RenderProcessHostImpl::GetIOThreadSender() { |
| 2094 return safe_sender_->io_thread_sender(); |
| 2095 } |
| 2096 |
| 2033 void RenderProcessHostImpl::AddFilter(BrowserMessageFilter* filter) { | 2097 void RenderProcessHostImpl::AddFilter(BrowserMessageFilter* filter) { |
| 2034 channel_->AddFilter(filter->GetFilter()); | 2098 channel_->AddFilter(filter->GetFilter()); |
| 2035 } | 2099 } |
| 2036 | 2100 |
| 2037 bool RenderProcessHostImpl::FastShutdownForPageCount(size_t count) { | 2101 bool RenderProcessHostImpl::FastShutdownForPageCount(size_t count) { |
| 2038 if (GetActiveViewCount() == count) | 2102 if (GetActiveViewCount() == count) |
| 2039 return FastShutdownIfPossible(); | 2103 return FastShutdownIfPossible(); |
| 2040 return false; | 2104 return false; |
| 2041 } | 2105 } |
| 2042 | 2106 |
| (...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2760 | 2824 |
| 2761 // Skip widgets in other processes. | 2825 // Skip widgets in other processes. |
| 2762 if (rvh->GetProcess()->GetID() != GetID()) | 2826 if (rvh->GetProcess()->GetID() != GetID()) |
| 2763 continue; | 2827 continue; |
| 2764 | 2828 |
| 2765 rvh->OnWebkitPreferencesChanged(); | 2829 rvh->OnWebkitPreferencesChanged(); |
| 2766 } | 2830 } |
| 2767 } | 2831 } |
| 2768 | 2832 |
| 2769 } // namespace content | 2833 } // namespace content |
| OLD | NEW |