Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(590)

Side by Side Diff: content/browser/frame_host/render_frame_host_impl.cc

Issue 857213003: Refactor sudden termination (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/containers/hash_tables.h" 9 #include "base/containers/hash_tables.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 frame_tree_(frame_tree), 130 frame_tree_(frame_tree),
131 frame_tree_node_(frame_tree_node), 131 frame_tree_node_(frame_tree_node),
132 routing_id_(routing_id), 132 routing_id_(routing_id),
133 render_frame_created_(false), 133 render_frame_created_(false),
134 navigations_suspended_(false), 134 navigations_suspended_(false),
135 is_waiting_for_beforeunload_ack_(false), 135 is_waiting_for_beforeunload_ack_(false),
136 unload_ack_is_for_cross_site_transition_(false), 136 unload_ack_is_for_cross_site_transition_(false),
137 accessibility_reset_token_(0), 137 accessibility_reset_token_(0),
138 accessibility_reset_count_(0), 138 accessibility_reset_count_(0),
139 no_create_browser_accessibility_manager_for_testing_(false), 139 no_create_browser_accessibility_manager_for_testing_(false),
140 has_beforeunload_handlers_(false),
141 has_unload_handlers_(false),
142 override_sudden_termination_status_(false),
140 weak_ptr_factory_(this) { 143 weak_ptr_factory_(this) {
141 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); 144 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT);
142 frame_tree_->RegisterRenderFrameHost(this); 145 frame_tree_->RegisterRenderFrameHost(this);
143 GetProcess()->AddRoute(routing_id_, this); 146 GetProcess()->AddRoute(routing_id_, this);
144 g_routing_id_frame_map.Get().insert(std::make_pair( 147 g_routing_id_frame_map.Get().insert(std::make_pair(
145 RenderFrameHostID(GetProcess()->GetID(), routing_id_), 148 RenderFrameHostID(GetProcess()->GetID(), routing_id_),
146 this)); 149 this));
147 150
148 if (is_swapped_out) { 151 if (is_swapped_out) {
149 rfh_state_ = STATE_SWAPPED_OUT; 152 rfh_state_ = STATE_SWAPPED_OUT;
150 } else { 153 } else {
151 rfh_state_ = STATE_DEFAULT; 154 rfh_state_ = STATE_DEFAULT;
152 GetSiteInstance()->increment_active_frame_count(); 155 GetSiteInstance()->increment_active_frame_count();
153 } 156 }
154 157
155 SetUpMojoIfNeeded(); 158 SetUpMojoIfNeeded();
156 swapout_event_monitor_timeout_.reset(new TimeoutMonitor(base::Bind( 159 swapout_event_monitor_timeout_.reset(new TimeoutMonitor(base::Bind(
157 &RenderFrameHostImpl::OnSwappedOut, weak_ptr_factory_.GetWeakPtr()))); 160 &RenderFrameHostImpl::OnSwappedOut, weak_ptr_factory_.GetWeakPtr())));
158 } 161 }
159 162
160 RenderFrameHostImpl::~RenderFrameHostImpl() { 163 RenderFrameHostImpl::~RenderFrameHostImpl() {
164 if (!SuddenTerminationAllowed())
165 GetProcess()->SuddenTerminationChangedForFrame(true);
Charlie Reis 2015/01/23 06:01:32 I don't think RPH should be tracking this state.
clamy 2015/01/26 16:38:39 Done.
161 GetProcess()->RemoveRoute(routing_id_); 166 GetProcess()->RemoveRoute(routing_id_);
162 g_routing_id_frame_map.Get().erase( 167 g_routing_id_frame_map.Get().erase(
163 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); 168 RenderFrameHostID(GetProcess()->GetID(), routing_id_));
164 169
165 if (delegate_) 170 if (delegate_)
166 delegate_->RenderFrameDeleted(this); 171 delegate_->RenderFrameDeleted(this);
167 172
168 FrameAccessibility::GetInstance()->OnRenderFrameHostDestroyed(this); 173 FrameAccessibility::GetInstance()->OnRenderFrameHostDestroyed(this);
169 174
170 // If this was swapped out, it already decremented the active frame count of 175 // If this was swapped out, it already decremented the active frame count of
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation, 334 IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation,
330 OnBeginNavigation) 335 OnBeginNavigation)
331 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse, 336 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse,
332 OnTextSurroundingSelectionResponse) 337 OnTextSurroundingSelectionResponse)
333 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_Events, OnAccessibilityEvents) 338 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_Events, OnAccessibilityEvents)
334 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_LocationChanges, 339 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_LocationChanges,
335 OnAccessibilityLocationChanges) 340 OnAccessibilityLocationChanges)
336 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_FindInPageResult, 341 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_FindInPageResult,
337 OnAccessibilityFindInPageResult) 342 OnAccessibilityFindInPageResult)
338 IPC_MESSAGE_HANDLER(FrameHostMsg_ToggleFullscreen, OnToggleFullscreen) 343 IPC_MESSAGE_HANDLER(FrameHostMsg_ToggleFullscreen, OnToggleFullscreen)
344 IPC_MESSAGE_HANDLER(FrameHostMsg_BeforeUnloadHandlersPresenceChanged,
Charlie Reis 2015/01/23 06:01:32 nit: Put these just before OnBeforeUnloadACK, sinc
clamy 2015/01/26 16:38:39 Done.
345 OnBeforeUnloadHandlersPresenceChanged)
346 IPC_MESSAGE_HANDLER(FrameHostMsg_UnloadHandlersPresenceChanged,
347 OnUnloadHandlersPresenceChanged)
339 #if defined(OS_MACOSX) || defined(OS_ANDROID) 348 #if defined(OS_MACOSX) || defined(OS_ANDROID)
340 IPC_MESSAGE_HANDLER(FrameHostMsg_ShowPopup, OnShowPopup) 349 IPC_MESSAGE_HANDLER(FrameHostMsg_ShowPopup, OnShowPopup)
341 IPC_MESSAGE_HANDLER(FrameHostMsg_HidePopup, OnHidePopup) 350 IPC_MESSAGE_HANDLER(FrameHostMsg_HidePopup, OnHidePopup)
342 #endif 351 #endif
343 IPC_END_MESSAGE_MAP() 352 IPC_END_MESSAGE_MAP()
344 353
345 // No further actions here, since we may have been deleted. 354 // No further actions here, since we may have been deleted.
346 return handled; 355 return handled;
347 } 356 }
348 357
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 // If canceled, notify the delegate to cancel its pending navigation entry. 890 // If canceled, notify the delegate to cancel its pending navigation entry.
882 if (!proceed) 891 if (!proceed)
883 render_view_host_->GetDelegate()->DidCancelLoading(); 892 render_view_host_->GetDelegate()->DidCancelLoading();
884 } 893 }
885 894
886 bool RenderFrameHostImpl::IsWaitingForUnloadACK() const { 895 bool RenderFrameHostImpl::IsWaitingForUnloadACK() const {
887 return render_view_host_->is_waiting_for_close_ack_ || 896 return render_view_host_->is_waiting_for_close_ack_ ||
888 rfh_state_ == STATE_PENDING_SWAP_OUT; 897 rfh_state_ == STATE_PENDING_SWAP_OUT;
889 } 898 }
890 899
900 bool RenderFrameHostImpl::SuddenTerminationAllowed() const {
901 return override_sudden_termination_status_ ||
902 (!has_beforeunload_handlers_ && !has_unload_handlers_);
903 }
904
891 void RenderFrameHostImpl::OnSwapOutACK() { 905 void RenderFrameHostImpl::OnSwapOutACK() {
892 OnSwappedOut(); 906 OnSwappedOut();
893 } 907 }
894 908
895 void RenderFrameHostImpl::OnSwappedOut() { 909 void RenderFrameHostImpl::OnSwappedOut() {
896 // Ignore spurious swap out ack. 910 // Ignore spurious swap out ack.
897 if (rfh_state_ != STATE_PENDING_SWAP_OUT) 911 if (rfh_state_ != STATE_PENDING_SWAP_OUT)
898 return; 912 return;
899 913
900 TRACE_EVENT_ASYNC_END0("navigation", "RenderFrameHostImpl::SwapOut", this); 914 TRACE_EVENT_ASYNC_END0("navigation", "RenderFrameHostImpl::SwapOut", this);
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 if (enter_fullscreen) 1159 if (enter_fullscreen)
1146 delegate_->EnterFullscreenMode(GetLastCommittedURL().GetOrigin()); 1160 delegate_->EnterFullscreenMode(GetLastCommittedURL().GetOrigin());
1147 else 1161 else
1148 delegate_->ExitFullscreenMode(); 1162 delegate_->ExitFullscreenMode();
1149 1163
1150 // The previous call might change the fullscreen state. We need to make sure 1164 // The previous call might change the fullscreen state. We need to make sure
1151 // the renderer is aware of that, which is done via the resize message. 1165 // the renderer is aware of that, which is done via the resize message.
1152 render_view_host_->WasResized(); 1166 render_view_host_->WasResized();
1153 } 1167 }
1154 1168
1169 void RenderFrameHostImpl::OnBeforeUnloadHandlersPresenceChanged(bool present) {
1170 HandleSuddenTerminationDisablerPresenceChange(
1171 &has_beforeunload_handlers_, present);
1172 }
1173
1174 void RenderFrameHostImpl::OnUnloadHandlersPresenceChanged(bool present) {
1175 HandleSuddenTerminationDisablerPresenceChange(
1176 &has_unload_handlers_, present);
1177 }
1178
1155 #if defined(OS_MACOSX) || defined(OS_ANDROID) 1179 #if defined(OS_MACOSX) || defined(OS_ANDROID)
1156 void RenderFrameHostImpl::OnShowPopup( 1180 void RenderFrameHostImpl::OnShowPopup(
1157 const FrameHostMsg_ShowPopup_Params& params) { 1181 const FrameHostMsg_ShowPopup_Params& params) {
1158 RenderViewHostDelegateView* view = 1182 RenderViewHostDelegateView* view =
1159 render_view_host_->delegate_->GetDelegateView(); 1183 render_view_host_->delegate_->GetDelegateView();
1160 if (view) { 1184 if (view) {
1161 view->ShowPopupMenu(this, 1185 view->ShowPopupMenu(this,
1162 params.bounds, 1186 params.bounds,
1163 params.item_height, 1187 params.item_height,
1164 params.item_font_size, 1188 params.item_font_size,
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 1665
1642 void RenderFrameHostImpl::DidUseGeolocationPermission() { 1666 void RenderFrameHostImpl::DidUseGeolocationPermission() {
1643 RenderFrameHost* top_frame = frame_tree_node()->frame_tree()->GetMainFrame(); 1667 RenderFrameHost* top_frame = frame_tree_node()->frame_tree()->GetMainFrame();
1644 GetContentClient()->browser()->RegisterPermissionUsage( 1668 GetContentClient()->browser()->RegisterPermissionUsage(
1645 PERMISSION_GEOLOCATION, 1669 PERMISSION_GEOLOCATION,
1646 delegate_->GetAsWebContents(), 1670 delegate_->GetAsWebContents(),
1647 GetLastCommittedURL().GetOrigin(), 1671 GetLastCommittedURL().GetOrigin(),
1648 top_frame->GetLastCommittedURL().GetOrigin()); 1672 top_frame->GetLastCommittedURL().GetOrigin());
1649 } 1673 }
1650 1674
1675 void RenderFrameHostImpl::HandleSuddenTerminationDisablerPresenceChange(
Charlie Reis 2015/01/23 06:01:32 Hmm, this method seems awkward to me. - The metho
clamy 2015/01/26 16:38:39 Done. If we don't signal the RPHI then only the bo
1676 bool* disabler_presence,
1677 bool new_value) {
1678 bool sudden_termination_before = SuddenTerminationAllowed();
1679 *disabler_presence = new_value;
1680 if (sudden_termination_before != SuddenTerminationAllowed()) {
1681 GetProcess()->SuddenTerminationChangedForFrame(
1682 SuddenTerminationAllowed());
1683 }
1684 }
1685
1651 } // namespace content 1686 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698