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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 : render_view_host_(render_view_host), | 188 : render_view_host_(render_view_host), |
189 delegate_(delegate), | 189 delegate_(delegate), |
190 site_instance_(static_cast<SiteInstanceImpl*>(site_instance)), | 190 site_instance_(static_cast<SiteInstanceImpl*>(site_instance)), |
191 process_(site_instance->GetProcess()), | 191 process_(site_instance->GetProcess()), |
192 cross_process_frame_connector_(NULL), | 192 cross_process_frame_connector_(NULL), |
193 render_frame_proxy_host_(NULL), | 193 render_frame_proxy_host_(NULL), |
194 frame_tree_(frame_tree), | 194 frame_tree_(frame_tree), |
195 frame_tree_node_(frame_tree_node), | 195 frame_tree_node_(frame_tree_node), |
196 render_widget_host_(nullptr), | 196 render_widget_host_(nullptr), |
197 routing_id_(routing_id), | 197 routing_id_(routing_id), |
198 rfh_state_(STATE_DEFAULT), | |
198 render_frame_created_(false), | 199 render_frame_created_(false), |
199 navigations_suspended_(false), | 200 navigations_suspended_(false), |
200 is_waiting_for_beforeunload_ack_(false), | 201 is_waiting_for_beforeunload_ack_(false), |
201 unload_ack_is_for_navigation_(false), | 202 unload_ack_is_for_navigation_(false), |
202 is_loading_(false), | 203 is_loading_(false), |
203 pending_commit_(false), | 204 pending_commit_(false), |
204 nav_entry_id_(0), | 205 nav_entry_id_(0), |
205 accessibility_reset_token_(0), | 206 accessibility_reset_token_(0), |
206 accessibility_reset_count_(0), | 207 accessibility_reset_count_(0), |
207 no_create_browser_accessibility_manager_for_testing_(false), | 208 no_create_browser_accessibility_manager_for_testing_(false), |
208 web_ui_type_(WebUI::kNoWebUI), | 209 web_ui_type_(WebUI::kNoWebUI), |
209 pending_web_ui_type_(WebUI::kNoWebUI), | 210 pending_web_ui_type_(WebUI::kNoWebUI), |
210 should_reuse_web_ui_(false), | 211 should_reuse_web_ui_(false), |
211 weak_ptr_factory_(this) { | 212 weak_ptr_factory_(this) { |
212 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); | |
213 bool hidden = !!(flags & CREATE_RF_HIDDEN); | 213 bool hidden = !!(flags & CREATE_RF_HIDDEN); |
214 frame_tree_->AddRenderViewHostRef(render_view_host_); | 214 frame_tree_->AddRenderViewHostRef(render_view_host_); |
215 GetProcess()->AddRoute(routing_id_, this); | 215 GetProcess()->AddRoute(routing_id_, this); |
216 g_routing_id_frame_map.Get().insert(std::make_pair( | 216 g_routing_id_frame_map.Get().insert(std::make_pair( |
217 RenderFrameHostID(GetProcess()->GetID(), routing_id_), | 217 RenderFrameHostID(GetProcess()->GetID(), routing_id_), |
218 this)); | 218 this)); |
219 site_instance_->AddObserver(this); | 219 site_instance_->AddObserver(this); |
220 | 220 GetSiteInstance()->IncrementActiveFrameCount(); |
221 if (is_swapped_out) { | |
222 rfh_state_ = STATE_SWAPPED_OUT; | |
223 } else { | |
224 rfh_state_ = STATE_DEFAULT; | |
225 GetSiteInstance()->IncrementActiveFrameCount(); | |
226 } | |
227 | 221 |
228 // New child frames should inherit the nav_entry_id of their parent. | 222 // New child frames should inherit the nav_entry_id of their parent. |
229 if (frame_tree_node_->parent()) { | 223 if (frame_tree_node_->parent()) { |
230 set_nav_entry_id( | 224 set_nav_entry_id( |
231 frame_tree_node_->parent()->current_frame_host()->nav_entry_id()); | 225 frame_tree_node_->parent()->current_frame_host()->nav_entry_id()); |
232 } | 226 } |
233 | 227 |
234 SetUpMojoIfNeeded(); | 228 SetUpMojoIfNeeded(); |
235 swapout_event_monitor_timeout_.reset(new TimeoutMonitor(base::Bind( | 229 swapout_event_monitor_timeout_.reset(new TimeoutMonitor(base::Bind( |
236 &RenderFrameHostImpl::OnSwappedOut, weak_ptr_factory_.GetWeakPtr()))); | 230 &RenderFrameHostImpl::OnSwappedOut, weak_ptr_factory_.GetWeakPtr()))); |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
465 } | 459 } |
466 | 460 |
467 return GetProcess()->Send(message); | 461 return GetProcess()->Send(message); |
468 } | 462 } |
469 | 463 |
470 bool RenderFrameHostImpl::OnMessageReceived(const IPC::Message &msg) { | 464 bool RenderFrameHostImpl::OnMessageReceived(const IPC::Message &msg) { |
471 // Only process messages if the RenderFrame is alive. | 465 // Only process messages if the RenderFrame is alive. |
472 if (!render_frame_created_) | 466 if (!render_frame_created_) |
473 return false; | 467 return false; |
474 | 468 |
475 // Filter out most IPC messages if this frame is swapped out. | |
Charlie Reis
2016/03/14 20:12:57
I am so excited about removing this. :)
nasko
2016/03/14 21:32:30
Same here :).
| |
476 // We still want to handle certain ACKs to keep our state consistent. | |
477 if (is_swapped_out()) { | |
478 if (!SwappedOutMessages::CanHandleWhileSwappedOut(msg)) { | |
479 // If this is a synchronous message and we decided not to handle it, | |
480 // we must send an error reply, or else the renderer will be stuck | |
481 // and won't respond to future requests. | |
482 if (msg.is_sync()) { | |
483 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); | |
484 reply->set_reply_error(); | |
485 Send(reply); | |
486 } | |
487 // Don't continue looking for someone to handle it. | |
488 return true; | |
489 } | |
490 } | |
491 | |
492 // 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 |
493 // be dispatched to other objects. | 470 // be dispatched to other objects. |
494 bool handled = true; | 471 bool handled = true; |
495 IPC_BEGIN_MESSAGE_MAP(RenderFrameHostImpl, msg) | 472 IPC_BEGIN_MESSAGE_MAP(RenderFrameHostImpl, msg) |
496 // 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 |
497 // RenderProcessHost. | 474 // RenderProcessHost. |
498 IPC_MESSAGE_HANDLER(FrameHostMsg_RenderProcessGone, OnRenderProcessGone) | 475 IPC_MESSAGE_HANDLER(FrameHostMsg_RenderProcessGone, OnRenderProcessGone) |
499 IPC_MESSAGE_UNHANDLED(handled = false) | 476 IPC_MESSAGE_UNHANDLED(handled = false) |
500 IPC_END_MESSAGE_MAP() | 477 IPC_END_MESSAGE_MAP() |
501 | 478 |
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1314 if (frame_tree_node_->IsMainFrame()) { | 1291 if (frame_tree_node_->IsMainFrame()) { |
1315 // 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 |
1316 // need to know why it died. | 1293 // need to know why it died. |
1317 render_view_host_->render_view_termination_status_ = | 1294 render_view_host_->render_view_termination_status_ = |
1318 static_cast<base::TerminationStatus>(status); | 1295 static_cast<base::TerminationStatus>(status); |
1319 } | 1296 } |
1320 | 1297 |
1321 // Reset frame tree state associated with this process. This must happen | 1298 // Reset frame tree state associated with this process. This must happen |
1322 // before RenderViewTerminated because observers expect the subframes of any | 1299 // before RenderViewTerminated because observers expect the subframes of any |
1323 // affected frames to be cleared first. | 1300 // affected frames to be cleared first. |
1324 // Note: When a RenderFrameHost is swapped out there is a different one | 1301 frame_tree_node_->ResetForNewProcess(); |
1325 // which is the current host. In this case, the FrameTreeNode state must | |
1326 // not be reset. | |
1327 if (!is_swapped_out()) | |
1328 frame_tree_node_->ResetForNewProcess(); | |
1329 | 1302 |
1330 // Reset state for the current RenderFrameHost once the FrameTreeNode has been | 1303 // Reset state for the current RenderFrameHost once the FrameTreeNode has been |
1331 // reset. | 1304 // reset. |
1332 SetRenderFrameCreated(false); | 1305 SetRenderFrameCreated(false); |
1333 InvalidateMojoConnection(); | 1306 InvalidateMojoConnection(); |
1334 | 1307 |
1335 // Execute any pending AX tree snapshot callbacks with an empty response, | 1308 // Execute any pending AX tree snapshot callbacks with an empty response, |
1336 // 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. |
1337 for (const auto& iter : ax_tree_snapshot_callbacks_) | 1310 for (const auto& iter : ax_tree_snapshot_callbacks_) |
1338 iter.second.Run(ui::AXTreeUpdate()); | 1311 iter.second.Run(ui::AXTreeUpdate()); |
(...skipping 21 matching lines...) Expand all Loading... | |
1360 frame_tree_node_->render_manager()->IsPendingDeletion(this)) { | 1333 frame_tree_node_->render_manager()->IsPendingDeletion(this)) { |
1361 render_view_host_->set_is_active(false); | 1334 render_view_host_->set_is_active(false); |
1362 render_view_host_->set_is_swapped_out(true); | 1335 render_view_host_->set_is_swapped_out(true); |
1363 } | 1336 } |
1364 | 1337 |
1365 if (frame_tree_node_->render_manager()->DeleteFromPendingList(this)) { | 1338 if (frame_tree_node_->render_manager()->DeleteFromPendingList(this)) { |
1366 // We are now deleted. | 1339 // We are now deleted. |
1367 return; | 1340 return; |
1368 } | 1341 } |
1369 | 1342 |
1370 // If this RFH wasn't pending deletion, then it is now swapped out. | 1343 CHECK(false); |
Charlie Reis
2016/03/14 20:12:57
Might be clearer if we CHECK the return value of D
nasko
2016/03/14 21:32:30
Good idea. Done, but keeping a variable around to
| |
1371 SetState(RenderFrameHostImpl::STATE_SWAPPED_OUT); | |
1372 } | 1344 } |
1373 | 1345 |
1374 void RenderFrameHostImpl::OnContextMenu(const ContextMenuParams& params) { | 1346 void RenderFrameHostImpl::OnContextMenu(const ContextMenuParams& params) { |
1375 // Validate the URLs in |params|. If the renderer can't request the URLs | 1347 // Validate the URLs in |params|. If the renderer can't request the URLs |
1376 // directly, don't show them in the context menu. | 1348 // directly, don't show them in the context menu. |
1377 ContextMenuParams validated_params(params); | 1349 ContextMenuParams validated_params(params); |
1378 RenderProcessHost* process = GetProcess(); | 1350 RenderProcessHost* process = GetProcess(); |
1379 | 1351 |
1380 // We don't validate |unfiltered_link_url| so that this field can be used | 1352 // We don't validate |unfiltered_link_url| so that this field can be used |
1381 // when users want to copy the original link URL. | 1353 // when users want to copy the original link URL. |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1886 GetServiceRegistry()->AddService<VRService>( | 1858 GetServiceRegistry()->AddService<VRService>( |
1887 base::Bind(&VRDeviceManager::BindRequest)); | 1859 base::Bind(&VRDeviceManager::BindRequest)); |
1888 } | 1860 } |
1889 #endif | 1861 #endif |
1890 | 1862 |
1891 GetContentClient()->browser()->RegisterRenderFrameMojoServices( | 1863 GetContentClient()->browser()->RegisterRenderFrameMojoServices( |
1892 GetServiceRegistry(), this); | 1864 GetServiceRegistry(), this); |
1893 } | 1865 } |
1894 | 1866 |
1895 void RenderFrameHostImpl::SetState(RenderFrameHostImplState rfh_state) { | 1867 void RenderFrameHostImpl::SetState(RenderFrameHostImplState rfh_state) { |
1896 // Only main frames should be swapped out and retained inside a proxy host. | 1868 // We update the number of RenderFrameHosts in a SiteInstance when the status |
1897 if (rfh_state == STATE_SWAPPED_OUT) | 1869 // of a RenderFrameHost gets flipped to/from active. |
Charlie Reis
2016/03/14 20:12:57
Is it even possible for the state to go from inact
nasko
2016/03/14 21:32:30
Done.
| |
1898 CHECK(!GetParent()); | |
1899 | |
1900 // We update the number of RenderFrameHosts in a SiteInstance when the swapped | |
1901 // out status of a RenderFrameHost gets flipped to/from active. | |
1902 if (!IsRFHStateActive(rfh_state_) && IsRFHStateActive(rfh_state)) | 1870 if (!IsRFHStateActive(rfh_state_) && IsRFHStateActive(rfh_state)) |
1903 GetSiteInstance()->IncrementActiveFrameCount(); | 1871 GetSiteInstance()->IncrementActiveFrameCount(); |
1904 else if (IsRFHStateActive(rfh_state_) && !IsRFHStateActive(rfh_state)) | 1872 else if (IsRFHStateActive(rfh_state_) && !IsRFHStateActive(rfh_state)) |
1905 GetSiteInstance()->DecrementActiveFrameCount(); | 1873 GetSiteInstance()->DecrementActiveFrameCount(); |
1906 | 1874 |
1907 // The active and swapped out state of the RVH is determined by its main | 1875 // The active state of the RVH is determined by its main frame, since |
1908 // frame, since subframes should have their own widgets. | 1876 // subframes should have their own widgets. |
1909 if (frame_tree_node_->IsMainFrame()) { | 1877 if (frame_tree_node_->IsMainFrame()) |
1910 render_view_host_->set_is_active(IsRFHStateActive(rfh_state)); | 1878 render_view_host_->set_is_active(IsRFHStateActive(rfh_state)); |
1911 render_view_host_->set_is_swapped_out(rfh_state == STATE_SWAPPED_OUT); | |
1912 } | |
1913 | 1879 |
1914 // Whenever we change the RFH state to and from active or swapped out state, | 1880 // Whenever we change the RFH state to and from active state, we should not be |
1915 // we should not be waiting for beforeunload or close acks. We clear them | 1881 // waiting for beforeunload or close acks. We clear them here to be safe, |
1916 // here to be safe, since they can cause navigations to be ignored in | 1882 // since they can cause navigations to be ignored in |
1917 // OnDidCommitProvisionalLoad. | 1883 // OnDidCommitProvisionalLoad. |
1918 // TODO(creis): Move is_waiting_for_beforeunload_ack_ into the state machine. | 1884 // TODO(creis): Move is_waiting_for_beforeunload_ack_ into the state machine. |
1919 if (rfh_state == STATE_DEFAULT || | 1885 if (rfh_state == STATE_DEFAULT || rfh_state_ == STATE_DEFAULT) { |
1920 rfh_state == STATE_SWAPPED_OUT || | |
1921 rfh_state_ == STATE_DEFAULT || | |
1922 rfh_state_ == STATE_SWAPPED_OUT) { | |
1923 if (is_waiting_for_beforeunload_ack_) { | 1886 if (is_waiting_for_beforeunload_ack_) { |
1924 is_waiting_for_beforeunload_ack_ = false; | 1887 is_waiting_for_beforeunload_ack_ = false; |
1925 render_view_host_->GetWidget()->decrement_in_flight_event_count(); | 1888 render_view_host_->GetWidget()->decrement_in_flight_event_count(); |
1926 render_view_host_->GetWidget()->StopHangMonitorTimeout(); | 1889 render_view_host_->GetWidget()->StopHangMonitorTimeout(); |
1927 } | 1890 } |
1928 send_before_unload_start_time_ = base::TimeTicks(); | 1891 send_before_unload_start_time_ = base::TimeTicks(); |
1929 render_view_host_->is_waiting_for_close_ack_ = false; | 1892 render_view_host_->is_waiting_for_close_ack_ = false; |
1930 } | 1893 } |
1931 rfh_state_ = rfh_state; | 1894 rfh_state_ = rfh_state; |
1932 } | 1895 } |
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2712 FrameTreeNode* focused_frame_tree_node = frame_tree_->GetFocusedFrame(); | 2675 FrameTreeNode* focused_frame_tree_node = frame_tree_->GetFocusedFrame(); |
2713 if (!focused_frame_tree_node) | 2676 if (!focused_frame_tree_node) |
2714 return; | 2677 return; |
2715 RenderFrameHostImpl* focused_frame = | 2678 RenderFrameHostImpl* focused_frame = |
2716 focused_frame_tree_node->current_frame_host(); | 2679 focused_frame_tree_node->current_frame_host(); |
2717 DCHECK(focused_frame); | 2680 DCHECK(focused_frame); |
2718 dst->focused_tree_id = focused_frame->GetAXTreeID(); | 2681 dst->focused_tree_id = focused_frame->GetAXTreeID(); |
2719 } | 2682 } |
2720 | 2683 |
2721 } // namespace content | 2684 } // namespace content |
OLD | NEW |