Chromium Code Reviews| 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..63de64b6bcd83cb187b4563bd899e875e962e846 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 RenderViewHost is |render_view_host|. |
| +// Used with FrameTree::ForEach. |
| +bool EnableSuddenTermination(RenderViewHost* render_view_host, |
|
clamy
2015/02/02 16:16:28
Another possibility would be to provide two functi
Charlie Reis
2015/02/02 20:14:50
What you have is fine. We probably shouldn't add
clamy
2015/02/03 12:54:02
Acknowledged (that's why I did not do it in the fi
|
| + FrameTreeNode* frame_tree_node) { |
| + if (frame_tree_node->current_frame_host()->render_view_host() |
| + == render_view_host) { |
|
Charlie Reis
2015/02/02 20:14:50
Let's pass in the SiteInstance rather than the RVH
clamy
2015/02/03 12:54:03
Done.
|
| + 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 RenderViewHost is |render_view_host|). Used with |
| +// FrameTree::ForEach. |
| +bool SuddenTerminationAllowed(bool* sudden_termination_allowed, |
| + RenderViewHost* render_view_host, |
|
Charlie Reis
2015/02/02 20:14:50
Same: Use SiteInstance here.
clamy
2015/02/03 12:54:03
Done.
|
| + FrameTreeNode* frame_tree_node) { |
| + if (frame_tree_node->current_frame_host()->SuddenTerminationAllowed() || |
| + frame_tree_node->current_frame_host()->render_view_host() |
| + != render_view_host) { |
| + 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,18 @@ void WebContentsImpl::WasUnOccluded() { |
| } |
| bool WebContentsImpl::NeedToFireBeforeUnload() { |
| + bool sudden_termination_allowed = true; |
| + frame_tree_.ForEach(base::Bind(&SuddenTerminationAllowed, |
| + &sudden_termination_allowed, |
| + GetRenderViewHost())); |
| // 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 +1385,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 +1842,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 +1959,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 +4093,7 @@ 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, rvhi)); |
| if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer()) |
| return; |