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

Unified Diff: content/browser/web_contents/web_contents_impl.cc

Issue 857213003: Refactor sudden termination (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Charlie's comments 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/web_contents/web_contents_impl.cc
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 507ebbe57de5de78422bdf86c398e0b70c9e7e00..861a927a6f8692a4958232f421f69b25fb13766d 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -202,6 +202,35 @@ void SetAccessibilityModeOnFrame(AccessibilityMode mode,
static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
}
+// Enable sudden termination for the current RenderFrameHost of
+// |frame_tree_node| if its SiteInstance is |site_instance|. Used with
+// FrameTree::ForEach.
+bool EnableSuddenTermination(scoped_refptr<SiteInstance> site_instance,
Charlie Reis 2015/02/03 19:33:15 Again, just a raw pointer is fine here.
clamy 2015/02/04 13:16:19 As explained in the other file, I went with using
+ FrameTreeNode* frame_tree_node) {
+ if (frame_tree_node->current_frame_host()->GetSiteInstance()
+ == site_instance.get()) {
+ frame_tree_node->current_frame_host()
+ ->set_override_sudden_termination_status(true);
+ }
+ return true;
+}
+
+// Returns false and sets |sudden_termination_allowed| to false if sudden
+// termination is not allowed for the current RenderFrameHost of
+// |frame_tree_node| (if its SiteInstance is |site_instance|). Used with
+// FrameTree::ForEach.
+bool SuddenTerminationAllowed(bool* sudden_termination_allowed,
+ scoped_refptr<SiteInstance> site_instance,
+ FrameTreeNode* frame_tree_node) {
+ if (frame_tree_node->current_frame_host()->SuddenTerminationAllowed() ||
+ frame_tree_node->current_frame_host()->GetSiteInstance()
+ != site_instance.get()) {
+ return true;
+ }
+ *sudden_termination_allowed = false;
+ return false;
+}
+
} // namespace
WebContents* WebContents::Create(const WebContents::CreateParams& params) {
@@ -641,7 +670,7 @@ RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
return host ? host->GetProcess() : NULL;
}
-RenderFrameHost* WebContentsImpl::GetMainFrame() {
+RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
return frame_tree_.root()->current_frame_host();
}
@@ -782,7 +811,7 @@ bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
void WebContentsImpl::SetParentNativeViewAccessible(
gfx::NativeViewAccessible accessible_parent) {
accessible_parent_ = accessible_parent;
- RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
+ RenderFrameHostImpl* rfh = GetMainFrame();
if (rfh)
rfh->SetParentNativeViewAccessible(accessible_parent);
}
@@ -1111,16 +1140,19 @@ void WebContentsImpl::WasUnOccluded() {
}
bool WebContentsImpl::NeedToFireBeforeUnload() {
+ bool sudden_termination_allowed = true;
+ frame_tree_.ForEach(base::Bind(
+ &SuddenTerminationAllowed,
+ &sudden_termination_allowed,
+ scoped_refptr<SiteInstance>(GetRenderViewHost()->GetSiteInstance())));
// TODO(creis): Should we fire even for interstitial pages?
return WillNotifyDisconnection() &&
!ShowingInterstitialPage() &&
- !static_cast<RenderViewHostImpl*>(
- GetRenderViewHost())->SuddenTerminationAllowed();
+ !sudden_termination_allowed;
}
void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
- static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload(
- for_cross_site_transition);
+ GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition);
}
void WebContentsImpl::Stop() {
@@ -1354,7 +1386,7 @@ void WebContentsImpl::RenderWidgetGotFocus(
void WebContentsImpl::RenderWidgetWasResized(
RenderWidgetHostImpl* render_widget_host,
bool width_changed) {
- RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
+ RenderFrameHostImpl* rfh = GetMainFrame();
if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
return;
@@ -1811,7 +1843,7 @@ WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
// Resume blocked requests for both the RenderViewHost and RenderFrameHost.
// TODO(brettw): It seems bogus to reach into here and initialize the host.
static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
- static_cast<RenderFrameHostImpl*>(new_contents->GetMainFrame())->Init();
+ new_contents->GetMainFrame()->Init();
return new_contents;
}
@@ -1928,13 +1960,13 @@ void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
BrowserAccessibilityManager*
WebContentsImpl::GetRootBrowserAccessibilityManager() {
- RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
+ RenderFrameHostImpl* rfh = GetMainFrame();
return rfh ? rfh->browser_accessibility_manager() : NULL;
}
BrowserAccessibilityManager*
WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
- RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
+ RenderFrameHostImpl* rfh = GetMainFrame();
return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : NULL;
}
@@ -4062,7 +4094,9 @@ void WebContentsImpl::RendererUnresponsive(RenderViewHost* render_view_host) {
rfhi->IsWaitingForUnloadACK()) {
// Hang occurred while firing the beforeunload/unload handler.
// Pretend the handler fired so tab closing continues as if it had.
- rvhi->set_sudden_termination_allowed(true);
+ frame_tree_.ForEach(base::Bind(
+ &EnableSuddenTermination,
+ scoped_refptr<SiteInstance>(rvhi->GetSiteInstance())));
Charlie Reis 2015/02/03 19:33:15 No scoped_refptr.
if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
return;

Powered by Google App Engine
This is Rietveld 408576698