Revert "Refactor sudden termination"

This reverts commit df1975e5b02f1d53b35d7fceaa14c081a6097a03
(https://codereview.chromium.org/857213003). This caused an issue with the
flash video player stopping playing when going from fullscreen back to normal
on certain pages.

BUG=461530
[email protected]

Review URL: https://codereview.chromium.org/1014623002

Cr-Commit-Position: refs/heads/master@{#322017}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 906e19a..9fb8cacb 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -236,30 +236,6 @@
   static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
 }
 
-// Enable sudden termination for the current RenderFrameHost of
-// |frame_tree_node| if the ID of its SiteInstance is |site_instance_id|.  Used
-// with FrameTree::ForEach.
-bool EnableSuddenTermination(int32 site_instance_id,
-                             FrameTreeNode* frame_tree_node) {
-  if (frame_tree_node->current_frame_host()->GetSiteInstance()->GetId()
-      == site_instance_id) {
-    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|. Used with FrameTree::ForEach.
-bool SuddenTerminationAllowed(bool* sudden_termination_allowed,
-                              FrameTreeNode* frame_tree_node) {
-  if (frame_tree_node->current_frame_host()->SuddenTerminationAllowed())
-    return true;
-  *sudden_termination_allowed = false;
-  return false;
-}
-
 // Returns true if at least one of the nodes in the |frame_tree| is loading.
 bool IsFrameTreeLoading(FrameTree& frame_tree) {
   bool is_loading = false;
@@ -855,7 +831,7 @@
 void WebContentsImpl::SetParentNativeViewAccessible(
 gfx::NativeViewAccessible accessible_parent) {
   accessible_parent_ = accessible_parent;
-  RenderFrameHostImpl* rfh = GetMainFrame();
+  RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
   if (rfh)
     rfh->SetParentNativeViewAccessible(accessible_parent);
 }
@@ -1189,17 +1165,16 @@
 }
 
 bool WebContentsImpl::NeedToFireBeforeUnload() {
-  bool sudden_termination_allowed = true;
-  frame_tree_.ForEach(base::Bind(
-        &SuddenTerminationAllowed, &sudden_termination_allowed));
   // TODO(creis): Should we fire even for interstitial pages?
   return WillNotifyDisconnection() &&
       !ShowingInterstitialPage() &&
-      !sudden_termination_allowed;
+      !static_cast<RenderViewHostImpl*>(
+          GetRenderViewHost())->SuddenTerminationAllowed();
 }
 
 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
-  GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition);
+  static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload(
+      for_cross_site_transition);
 }
 
 void WebContentsImpl::Stop() {
@@ -1448,7 +1423,7 @@
 void WebContentsImpl::RenderWidgetWasResized(
     RenderWidgetHostImpl* render_widget_host,
     bool width_changed) {
-  RenderFrameHostImpl* rfh = GetMainFrame();
+  RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
   if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
     return;
 
@@ -1881,7 +1856,7 @@
   // 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();
-  new_contents->GetMainFrame()->Init();
+  static_cast<RenderFrameHostImpl*>(new_contents->GetMainFrame())->Init();
 
   return new_contents;
 }
@@ -1999,13 +1974,13 @@
 
 BrowserAccessibilityManager*
     WebContentsImpl::GetRootBrowserAccessibilityManager() {
-  RenderFrameHostImpl* rfh = GetMainFrame();
+  RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
   return rfh ? rfh->browser_accessibility_manager() : NULL;
 }
 
 BrowserAccessibilityManager*
     WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
-  RenderFrameHostImpl* rfh = GetMainFrame();
+  RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
   return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : NULL;
 }
 
@@ -4209,8 +4184,7 @@
       rfhi->IsWaitingForUnloadACK()) {
     // Hang occurred while firing the beforeunload/unload handler.
     // Pretend the handler fired so tab closing continues as if it had.
-    frame_tree_.ForEach(base::Bind(
-          &EnableSuddenTermination, rvhi->GetSiteInstance()->GetId()));
+    rvhi->set_sudden_termination_allowed(true);
 
     if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
       return;