Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "content/browser/frame_host/render_frame_host_impl.h" | 5 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 } | 459 } |
| 460 | 460 |
| 461 return GetProcess()->Send(message); | 461 return GetProcess()->Send(message); |
| 462 } | 462 } |
| 463 | 463 |
| 464 bool RenderFrameHostImpl::OnMessageReceived(const IPC::Message &msg) { | 464 bool RenderFrameHostImpl::OnMessageReceived(const IPC::Message &msg) { |
| 465 // Only process messages if the RenderFrame is alive. | 465 // Only process messages if the RenderFrame is alive. |
| 466 if (!render_frame_created_) | 466 if (!render_frame_created_) |
| 467 return false; | 467 return false; |
| 468 | 468 |
| 469 // Filter out most IPC messages if this frame is swapped out. | |
| 470 // We still want to handle certain ACKs to keep our state consistent. | |
| 471 if (is_swapped_out()) { | |
| 472 if (!SwappedOutMessages::CanHandleWhileSwappedOut(msg)) { | |
| 473 // If this is a synchronous message and we decided not to handle it, | |
| 474 // we must send an error reply, or else the renderer will be stuck | |
| 475 // and won't respond to future requests. | |
| 476 if (msg.is_sync()) { | |
| 477 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); | |
| 478 reply->set_reply_error(); | |
| 479 Send(reply); | |
| 480 } | |
| 481 // Don't continue looking for someone to handle it. | |
| 482 return true; | |
| 483 } | |
| 484 } | |
| 485 | |
| 486 // This message map is for handling internal IPC messages which should not | 469 // This message map is for handling internal IPC messages which should not |
| 487 // be dispatched to other objects. | 470 // be dispatched to other objects. |
| 488 bool handled = true; | 471 bool handled = true; |
| 489 IPC_BEGIN_MESSAGE_MAP(RenderFrameHostImpl, msg) | 472 IPC_BEGIN_MESSAGE_MAP(RenderFrameHostImpl, msg) |
| 490 // This message is synthetic and doesn't come from RenderFrame, but from | 473 // This message is synthetic and doesn't come from RenderFrame, but from |
| 491 // RenderProcessHost. | 474 // RenderProcessHost. |
| 492 IPC_MESSAGE_HANDLER(FrameHostMsg_RenderProcessGone, OnRenderProcessGone) | 475 IPC_MESSAGE_HANDLER(FrameHostMsg_RenderProcessGone, OnRenderProcessGone) |
| 493 IPC_MESSAGE_UNHANDLED(handled = false) | 476 IPC_MESSAGE_UNHANDLED(handled = false) |
| 494 IPC_END_MESSAGE_MAP() | 477 IPC_END_MESSAGE_MAP() |
| 495 | 478 |
| (...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1308 if (frame_tree_node_->IsMainFrame()) { | 1291 if (frame_tree_node_->IsMainFrame()) { |
| 1309 // Keep the termination status so we can get at it later when we | 1292 // Keep the termination status so we can get at it later when we |
| 1310 // need to know why it died. | 1293 // need to know why it died. |
| 1311 render_view_host_->render_view_termination_status_ = | 1294 render_view_host_->render_view_termination_status_ = |
| 1312 static_cast<base::TerminationStatus>(status); | 1295 static_cast<base::TerminationStatus>(status); |
| 1313 } | 1296 } |
| 1314 | 1297 |
| 1315 // Reset frame tree state associated with this process. This must happen | 1298 // Reset frame tree state associated with this process. This must happen |
| 1316 // before RenderViewTerminated because observers expect the subframes of any | 1299 // before RenderViewTerminated because observers expect the subframes of any |
| 1317 // affected frames to be cleared first. | 1300 // affected frames to be cleared first. |
| 1318 // Note: When a RenderFrameHost is swapped out there is a different one | 1301 frame_tree_node_->ResetForNewProcess(); |
| 1319 // which is the current host. In this case, the FrameTreeNode state must | |
| 1320 // not be reset. | |
| 1321 if (!is_swapped_out()) | |
| 1322 frame_tree_node_->ResetForNewProcess(); | |
| 1323 | 1302 |
| 1324 // Reset state for the current RenderFrameHost once the FrameTreeNode has been | 1303 // Reset state for the current RenderFrameHost once the FrameTreeNode has been |
| 1325 // reset. | 1304 // reset. |
| 1326 SetRenderFrameCreated(false); | 1305 SetRenderFrameCreated(false); |
| 1327 InvalidateMojoConnection(); | 1306 InvalidateMojoConnection(); |
| 1328 | 1307 |
| 1329 // Execute any pending AX tree snapshot callbacks with an empty response, | 1308 // Execute any pending AX tree snapshot callbacks with an empty response, |
| 1330 // since we're never going to get a response from this renderer. | 1309 // since we're never going to get a response from this renderer. |
| 1331 for (const auto& iter : ax_tree_snapshot_callbacks_) | 1310 for (const auto& iter : ax_tree_snapshot_callbacks_) |
| 1332 iter.second.Run(ui::AXTreeUpdate()); | 1311 iter.second.Run(ui::AXTreeUpdate()); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1349 | 1328 |
| 1350 // If this is a main frame RFH that's about to be deleted, update its RVH's | 1329 // If this is a main frame RFH that's about to be deleted, update its RVH's |
| 1351 // swapped-out state here, since SetState won't be called once this RFH is | 1330 // swapped-out state here, since SetState won't be called once this RFH is |
| 1352 // deleted below. https://crbug.com/505887 | 1331 // deleted below. https://crbug.com/505887 |
| 1353 if (frame_tree_node_->IsMainFrame() && | 1332 if (frame_tree_node_->IsMainFrame() && |
| 1354 frame_tree_node_->render_manager()->IsPendingDeletion(this)) { | 1333 frame_tree_node_->render_manager()->IsPendingDeletion(this)) { |
| 1355 render_view_host_->set_is_active(false); | 1334 render_view_host_->set_is_active(false); |
| 1356 render_view_host_->set_is_swapped_out(true); | 1335 render_view_host_->set_is_swapped_out(true); |
| 1357 } | 1336 } |
| 1358 | 1337 |
| 1359 if (frame_tree_node_->render_manager()->DeleteFromPendingList(this)) { | 1338 bool deleted = |
| 1360 // We are now deleted. | 1339 frame_tree_node_->render_manager()->DeleteFromPendingList(this); |
| 1361 return; | 1340 CHECK(deleted); |
| 1362 } | |
| 1363 | |
| 1364 // If this RFH wasn't pending deletion, then it is now swapped out. | |
| 1365 SetState(RenderFrameHostImpl::STATE_SWAPPED_OUT); | |
| 1366 } | 1341 } |
| 1367 | 1342 |
| 1368 void RenderFrameHostImpl::OnContextMenu(const ContextMenuParams& params) { | 1343 void RenderFrameHostImpl::OnContextMenu(const ContextMenuParams& params) { |
| 1369 // Validate the URLs in |params|. If the renderer can't request the URLs | 1344 // Validate the URLs in |params|. If the renderer can't request the URLs |
| 1370 // directly, don't show them in the context menu. | 1345 // directly, don't show them in the context menu. |
| 1371 ContextMenuParams validated_params(params); | 1346 ContextMenuParams validated_params(params); |
| 1372 RenderProcessHost* process = GetProcess(); | 1347 RenderProcessHost* process = GetProcess(); |
| 1373 | 1348 |
| 1374 // We don't validate |unfiltered_link_url| so that this field can be used | 1349 // We don't validate |unfiltered_link_url| so that this field can be used |
| 1375 // when users want to copy the original link URL. | 1350 // when users want to copy the original link URL. |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1880 GetServiceRegistry()->AddService<VRService>( | 1855 GetServiceRegistry()->AddService<VRService>( |
| 1881 base::Bind(&VRDeviceManager::BindRequest)); | 1856 base::Bind(&VRDeviceManager::BindRequest)); |
| 1882 } | 1857 } |
| 1883 #endif | 1858 #endif |
| 1884 | 1859 |
| 1885 GetContentClient()->browser()->RegisterRenderFrameMojoServices( | 1860 GetContentClient()->browser()->RegisterRenderFrameMojoServices( |
| 1886 GetServiceRegistry(), this); | 1861 GetServiceRegistry(), this); |
| 1887 } | 1862 } |
| 1888 | 1863 |
| 1889 void RenderFrameHostImpl::SetState(RenderFrameHostImplState rfh_state) { | 1864 void RenderFrameHostImpl::SetState(RenderFrameHostImplState rfh_state) { |
| 1890 // Only main frames should be swapped out and retained inside a proxy host. | 1865 // We decrement the number of RenderFrameHosts in a SiteInstance when the |
| 1891 if (rfh_state == STATE_SWAPPED_OUT) | 1866 // status of a RenderFrameHost gets flipped from active. |
| 1892 CHECK(!GetParent()); | 1867 if (IsRFHStateActive(rfh_state_) && !IsRFHStateActive(rfh_state)) |
| 1893 | |
| 1894 // We update the number of RenderFrameHosts in a SiteInstance when the swapped | |
| 1895 // out status of a RenderFrameHost gets flipped to/from active. | |
| 1896 if (!IsRFHStateActive(rfh_state_) && IsRFHStateActive(rfh_state)) | |
| 1897 GetSiteInstance()->IncrementActiveFrameCount(); | |
| 1898 else if (IsRFHStateActive(rfh_state_) && !IsRFHStateActive(rfh_state)) | |
| 1899 GetSiteInstance()->DecrementActiveFrameCount(); | 1868 GetSiteInstance()->DecrementActiveFrameCount(); |
| 1900 | 1869 |
| 1901 // The active and swapped out state of the RVH is determined by its main | 1870 // The active state of the RVH is determined by its main frame, since |
| 1902 // frame, since subframes should have their own widgets. | 1871 // subframes should have their own widgets. |
| 1903 if (frame_tree_node_->IsMainFrame()) { | 1872 if (frame_tree_node_->IsMainFrame()) |
| 1904 render_view_host_->set_is_active(IsRFHStateActive(rfh_state)); | 1873 render_view_host_->set_is_active(IsRFHStateActive(rfh_state)); |
| 1905 render_view_host_->set_is_swapped_out(rfh_state == STATE_SWAPPED_OUT); | |
| 1906 } | |
| 1907 | 1874 |
| 1908 // Whenever we change the RFH state to and from active or swapped out state, | 1875 // Whenever we change the RFH state to and from active state, we should not be |
|
Charlie Reis
2016/03/14 21:49:15
Let's come back to cleaning up this method after t
| |
| 1909 // we should not be waiting for beforeunload or close acks. We clear them | 1876 // waiting for beforeunload or close acks. We clear them here to be safe, |
| 1910 // here to be safe, since they can cause navigations to be ignored in | 1877 // since they can cause navigations to be ignored in |
| 1911 // OnDidCommitProvisionalLoad. | 1878 // OnDidCommitProvisionalLoad. |
| 1912 // TODO(creis): Move is_waiting_for_beforeunload_ack_ into the state machine. | 1879 // TODO(creis): Move is_waiting_for_beforeunload_ack_ into the state machine. |
| 1913 if (rfh_state == STATE_DEFAULT || | 1880 if (rfh_state == STATE_DEFAULT || rfh_state_ == STATE_DEFAULT) { |
| 1914 rfh_state == STATE_SWAPPED_OUT || | |
| 1915 rfh_state_ == STATE_DEFAULT || | |
| 1916 rfh_state_ == STATE_SWAPPED_OUT) { | |
| 1917 if (is_waiting_for_beforeunload_ack_) { | 1881 if (is_waiting_for_beforeunload_ack_) { |
| 1918 is_waiting_for_beforeunload_ack_ = false; | 1882 is_waiting_for_beforeunload_ack_ = false; |
| 1919 render_view_host_->GetWidget()->decrement_in_flight_event_count(); | 1883 render_view_host_->GetWidget()->decrement_in_flight_event_count(); |
| 1920 render_view_host_->GetWidget()->StopHangMonitorTimeout(); | 1884 render_view_host_->GetWidget()->StopHangMonitorTimeout(); |
| 1921 } | 1885 } |
| 1922 send_before_unload_start_time_ = base::TimeTicks(); | 1886 send_before_unload_start_time_ = base::TimeTicks(); |
| 1923 render_view_host_->is_waiting_for_close_ack_ = false; | 1887 render_view_host_->is_waiting_for_close_ack_ = false; |
| 1924 } | 1888 } |
| 1925 rfh_state_ = rfh_state; | 1889 rfh_state_ = rfh_state; |
| 1926 } | 1890 } |
| (...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2706 FrameTreeNode* focused_frame_tree_node = frame_tree_->GetFocusedFrame(); | 2670 FrameTreeNode* focused_frame_tree_node = frame_tree_->GetFocusedFrame(); |
| 2707 if (!focused_frame_tree_node) | 2671 if (!focused_frame_tree_node) |
| 2708 return; | 2672 return; |
| 2709 RenderFrameHostImpl* focused_frame = | 2673 RenderFrameHostImpl* focused_frame = |
| 2710 focused_frame_tree_node->current_frame_host(); | 2674 focused_frame_tree_node->current_frame_host(); |
| 2711 DCHECK(focused_frame); | 2675 DCHECK(focused_frame); |
| 2712 dst->focused_tree_id = focused_frame->GetAXTreeID(); | 2676 dst->focused_tree_id = focused_frame->GetAXTreeID(); |
| 2713 } | 2677 } |
| 2714 | 2678 |
| 2715 } // namespace content | 2679 } // namespace content |
| OLD | NEW |