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