| 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 // 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 20 matching lines...) Expand all Loading... |
| 31 #include "base/stl_util.h" | 31 #include "base/stl_util.h" |
| 32 #include "base/strings/string_util.h" | 32 #include "base/strings/string_util.h" |
| 33 #include "base/supports_user_data.h" | 33 #include "base/supports_user_data.h" |
| 34 #include "base/sys_info.h" | 34 #include "base/sys_info.h" |
| 35 #include "base/threading/thread.h" | 35 #include "base/threading/thread.h" |
| 36 #include "base/threading/thread_restrictions.h" | 36 #include "base/threading/thread_restrictions.h" |
| 37 #include "base/tracked_objects.h" | 37 #include "base/tracked_objects.h" |
| 38 #include "cc/base/switches.h" | 38 #include "cc/base/switches.h" |
| 39 #include "content/browser/appcache/appcache_dispatcher_host.h" | 39 #include "content/browser/appcache/appcache_dispatcher_host.h" |
| 40 #include "content/browser/appcache/chrome_appcache_service.h" | 40 #include "content/browser/appcache/chrome_appcache_service.h" |
| 41 #include "content/browser/browser_child_process_host_impl.h" |
| 41 #include "content/browser/browser_main.h" | 42 #include "content/browser/browser_main.h" |
| 42 #include "content/browser/browser_main_loop.h" | 43 #include "content/browser/browser_main_loop.h" |
| 43 #include "content/browser/browser_plugin/browser_plugin_message_filter.h" | 44 #include "content/browser/browser_plugin/browser_plugin_message_filter.h" |
| 44 #include "content/browser/child_process_security_policy_impl.h" | 45 #include "content/browser/child_process_security_policy_impl.h" |
| 45 #include "content/browser/device_sensors/device_motion_message_filter.h" | 46 #include "content/browser/device_sensors/device_motion_message_filter.h" |
| 46 #include "content/browser/device_sensors/device_orientation_message_filter.h" | 47 #include "content/browser/device_sensors/device_orientation_message_filter.h" |
| 47 #include "content/browser/dom_storage/dom_storage_context_wrapper.h" | 48 #include "content/browser/dom_storage/dom_storage_context_wrapper.h" |
| 48 #include "content/browser/dom_storage/dom_storage_message_filter.h" | 49 #include "content/browser/dom_storage/dom_storage_message_filter.h" |
| 49 #include "content/browser/download/mhtml_generation_manager.h" | 50 #include "content/browser/download/mhtml_generation_manager.h" |
| 50 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 51 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
| (...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1301 bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { | 1302 bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { |
| 1302 // If we're about to be deleted, or have initiated the fast shutdown sequence, | 1303 // If we're about to be deleted, or have initiated the fast shutdown sequence, |
| 1303 // we ignore incoming messages. | 1304 // we ignore incoming messages. |
| 1304 | 1305 |
| 1305 if (deleting_soon_ || fast_shutdown_started_) | 1306 if (deleting_soon_ || fast_shutdown_started_) |
| 1306 return false; | 1307 return false; |
| 1307 | 1308 |
| 1308 mark_child_process_activity_time(); | 1309 mark_child_process_activity_time(); |
| 1309 if (msg.routing_id() == MSG_ROUTING_CONTROL) { | 1310 if (msg.routing_id() == MSG_ROUTING_CONTROL) { |
| 1310 // Dispatch control messages. | 1311 // Dispatch control messages. |
| 1311 bool msg_is_ok = true; | 1312 IPC_BEGIN_MESSAGE_MAP(RenderProcessHostImpl, msg) |
| 1312 IPC_BEGIN_MESSAGE_MAP_EX(RenderProcessHostImpl, msg, msg_is_ok) | |
| 1313 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_ShutdownRequest, | 1313 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_ShutdownRequest, |
| 1314 OnShutdownRequest) | 1314 OnShutdownRequest) |
| 1315 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_DumpHandlesDone, | 1315 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_DumpHandlesDone, |
| 1316 OnDumpHandlesDone) | 1316 OnDumpHandlesDone) |
| 1317 IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged, | 1317 IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged, |
| 1318 SuddenTerminationChanged) | 1318 SuddenTerminationChanged) |
| 1319 IPC_MESSAGE_HANDLER(ViewHostMsg_UserMetricsRecordAction, | 1319 IPC_MESSAGE_HANDLER(ViewHostMsg_UserMetricsRecordAction, |
| 1320 OnUserMetricsRecordAction) | 1320 OnUserMetricsRecordAction) |
| 1321 IPC_MESSAGE_HANDLER(ViewHostMsg_SavedPageAsMHTML, OnSavedPageAsMHTML) | 1321 IPC_MESSAGE_HANDLER(ViewHostMsg_SavedPageAsMHTML, OnSavedPageAsMHTML) |
| 1322 // Adding single handlers for your service here is fine, but once your | 1322 // Adding single handlers for your service here is fine, but once your |
| 1323 // service needs more than one handler, please extract them into a new | 1323 // service needs more than one handler, please extract them into a new |
| 1324 // message filter and add that filter to CreateMessageFilters(). | 1324 // message filter and add that filter to CreateMessageFilters(). |
| 1325 IPC_END_MESSAGE_MAP_EX() | 1325 IPC_END_MESSAGE_MAP() |
| 1326 | 1326 |
| 1327 if (!msg_is_ok) { | |
| 1328 // The message had a handler, but its de-serialization failed. | |
| 1329 // We consider this a capital crime. Kill the renderer if we have one. | |
| 1330 LOG(ERROR) << "bad message " << msg.type() << " terminating renderer."; | |
| 1331 RecordAction(base::UserMetricsAction("BadMessageTerminate_BRPH")); | |
| 1332 ReceivedBadMessage(); | |
| 1333 } | |
| 1334 return true; | 1327 return true; |
| 1335 } | 1328 } |
| 1336 | 1329 |
| 1337 // Dispatch incoming messages to the appropriate IPC::Listener. | 1330 // Dispatch incoming messages to the appropriate IPC::Listener. |
| 1338 IPC::Listener* listener = listeners_.Lookup(msg.routing_id()); | 1331 IPC::Listener* listener = listeners_.Lookup(msg.routing_id()); |
| 1339 if (!listener) { | 1332 if (!listener) { |
| 1340 if (msg.is_sync()) { | 1333 if (msg.is_sync()) { |
| 1341 // The listener has gone away, so we must respond or else the caller will | 1334 // The listener has gone away, so we must respond or else the caller will |
| 1342 // hang waiting for a reply. | 1335 // hang waiting for a reply. |
| 1343 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); | 1336 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); |
| 1344 reply->set_reply_error(); | 1337 reply->set_reply_error(); |
| 1345 Send(reply); | 1338 Send(reply); |
| 1346 } | 1339 } |
| 1347 | 1340 |
| 1348 // If this is a SwapBuffers, we need to ack it if we're not going to handle | 1341 // If this is a SwapBuffers, we need to ack it if we're not going to handle |
| 1349 // it so that the GPU process doesn't get stuck in unscheduled state. | 1342 // it so that the GPU process doesn't get stuck in unscheduled state. |
| 1350 bool msg_is_ok = true; | 1343 IPC_BEGIN_MESSAGE_MAP(RenderProcessHostImpl, msg) |
| 1351 IPC_BEGIN_MESSAGE_MAP_EX(RenderProcessHostImpl, msg, msg_is_ok) | |
| 1352 IPC_MESSAGE_HANDLER(ViewHostMsg_CompositorSurfaceBuffersSwapped, | 1344 IPC_MESSAGE_HANDLER(ViewHostMsg_CompositorSurfaceBuffersSwapped, |
| 1353 OnCompositorSurfaceBuffersSwappedNoHost) | 1345 OnCompositorSurfaceBuffersSwappedNoHost) |
| 1354 IPC_END_MESSAGE_MAP_EX() | 1346 IPC_END_MESSAGE_MAP() |
| 1355 return true; | 1347 return true; |
| 1356 } | 1348 } |
| 1357 return listener->OnMessageReceived(msg); | 1349 return listener->OnMessageReceived(msg); |
| 1358 } | 1350 } |
| 1359 | 1351 |
| 1360 void RenderProcessHostImpl::OnChannelConnected(int32 peer_pid) { | 1352 void RenderProcessHostImpl::OnChannelConnected(int32 peer_pid) { |
| 1361 #if defined(IPC_MESSAGE_LOG_ENABLED) | 1353 #if defined(IPC_MESSAGE_LOG_ENABLED) |
| 1362 Send(new ChildProcessMsg_SetIPCLoggingEnabled( | 1354 Send(new ChildProcessMsg_SetIPCLoggingEnabled( |
| 1363 IPC::Logging::GetInstance()->Enabled())); | 1355 IPC::Logging::GetInstance()->Enabled())); |
| 1364 #endif | 1356 #endif |
| 1365 | 1357 |
| 1366 tracked_objects::ThreadData::Status status = | 1358 tracked_objects::ThreadData::Status status = |
| 1367 tracked_objects::ThreadData::status(); | 1359 tracked_objects::ThreadData::status(); |
| 1368 Send(new ChildProcessMsg_SetProfilerStatus(status)); | 1360 Send(new ChildProcessMsg_SetProfilerStatus(status)); |
| 1369 } | 1361 } |
| 1370 | 1362 |
| 1371 void RenderProcessHostImpl::OnChannelError() { | 1363 void RenderProcessHostImpl::OnChannelError() { |
| 1372 ProcessDied(true /* already_dead */); | 1364 ProcessDied(true /* already_dead */); |
| 1373 } | 1365 } |
| 1374 | 1366 |
| 1367 void RenderProcessHostImpl::OnBadMessageReceived(const IPC::Message& message) { |
| 1368 // Message de-serialization failed. We consider this a capital crime. Kill the |
| 1369 // renderer if we have one. |
| 1370 LOG(ERROR) << "bad message " << message.type() << " terminating renderer."; |
| 1371 BrowserChildProcessHostImpl::HistogramBadMessageTerminated( |
| 1372 PROCESS_TYPE_RENDERER); |
| 1373 ReceivedBadMessage(); |
| 1374 } |
| 1375 |
| 1375 BrowserContext* RenderProcessHostImpl::GetBrowserContext() const { | 1376 BrowserContext* RenderProcessHostImpl::GetBrowserContext() const { |
| 1376 return browser_context_; | 1377 return browser_context_; |
| 1377 } | 1378 } |
| 1378 | 1379 |
| 1379 bool RenderProcessHostImpl::InSameStoragePartition( | 1380 bool RenderProcessHostImpl::InSameStoragePartition( |
| 1380 StoragePartition* partition) const { | 1381 StoragePartition* partition) const { |
| 1381 return storage_partition_impl_ == partition; | 1382 return storage_partition_impl_ == partition; |
| 1382 } | 1383 } |
| 1383 | 1384 |
| 1384 int RenderProcessHostImpl::GetID() const { | 1385 int RenderProcessHostImpl::GetID() const { |
| (...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2075 mojo::ScopedMessagePipeHandle handle) { | 2076 mojo::ScopedMessagePipeHandle handle) { |
| 2076 mojo_activation_required_ = true; | 2077 mojo_activation_required_ = true; |
| 2077 MaybeActivateMojo(); | 2078 MaybeActivateMojo(); |
| 2078 | 2079 |
| 2079 mojo::AllocationScope scope; | 2080 mojo::AllocationScope scope; |
| 2080 mojo_application_host_->shell_client()->AcceptConnection(service_name, | 2081 mojo_application_host_->shell_client()->AcceptConnection(service_name, |
| 2081 handle.Pass()); | 2082 handle.Pass()); |
| 2082 } | 2083 } |
| 2083 | 2084 |
| 2084 } // namespace content | 2085 } // namespace content |
| OLD | NEW |