[MimeHandlerView] Async Attach: Content API

This CL will rework the attaching logic for frame-based
MimeHandlerViewGuest. The notable change is the addition of a new public
API to RenderFrameHost which will (asynchronously) prepare the
FrameTreeNode for attaching an inner WebContents so that its usage with
the attaching API, WebContents::AttachToOuterContentsFrame is safe.
Previously this was achieved by navigating the current RenderFrameHost
to "about:blank" but that proved to have certain issues such as
navigation races as well as inefficient handling of the 'beforeunload'
handlers (from outside content layer it is nearly impossible to determine
whether a beforeunload modal is shown and is blocking the
navigation).

In summary, with this CL:
  1- There is no longer a need for a navigation to about:blank for
  every embedded PDF.
  2- There is no need for adding navigation throttles.
  3- beforeunload is properly addressed (an improvement over the
  previous approach of waiting for a timeout to decide navigation was
  actually blocked).
  4- Less lines of code and a more tractable attaching code.

Bug: 659750, 911161
Change-Id: Ib8981744b5683bb1cb8d557322bfc40f08bb4ccb
Reviewed-on: https://chromium-review.googlesource.com/c/1407596
Commit-Queue: Ehsan Karamad <[email protected]>
Reviewed-by: Lucas Gadani <[email protected]>
Reviewed-by: Alex Moshchuk <[email protected]>
Reviewed-by: James MacLean <[email protected]>
Cr-Commit-Position: refs/heads/master@{#635607}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 79cc8128..c714e69 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -1808,28 +1808,17 @@
   GetMainFrame()->DispatchBeforeUnload(before_unload_type, false);
 }
 
-bool WebContentsImpl::CanAttachToOuterContentsFrame(
-    RenderFrameHost* outer_contents_frame) {
-  bool web_contents_valid = !node_.outer_web_contents() &&
-                            FromRenderFrameHost(outer_contents_frame) != this;
-  bool rfh_valid = outer_contents_frame->GetParent()->GetSiteInstance() ==
-                   outer_contents_frame->GetSiteInstance();
-  bool rfh_is_loading = static_cast<RenderFrameHostImpl*>(outer_contents_frame)
-                            ->frame_tree_node()
-                            ->IsLoading();
-  return web_contents_valid && rfh_valid && !rfh_is_loading;
-}
-
 void WebContentsImpl::AttachToOuterWebContentsFrame(
     std::unique_ptr<WebContents> current_web_contents,
     RenderFrameHost* outer_contents_frame) {
   DCHECK(!node_.outer_web_contents());
   DCHECK_EQ(current_web_contents.get(), this);
-  DCHECK(CanAttachToOuterContentsFrame(outer_contents_frame));
   auto* outer_contents_frame_impl =
       static_cast<RenderFrameHostImpl*>(outer_contents_frame);
 
   RenderFrameHostManager* render_manager = GetRenderManager();
+  auto* outer_contnets_render_manager =
+      outer_contents_frame_impl->frame_tree_node()->render_manager();
 
   // When attaching a WebContents as an inner WebContents, we need to replace
   // the Webcontents' view with a WebContentsViewChildFrame.
@@ -1872,6 +1861,7 @@
     SetFocusedFrame(frame_tree_.root(),
                     outer_contents_frame->GetSiteInstance());
   }
+  outer_contnets_render_manager->set_attach_complete();
 }
 
 std::unique_ptr<WebContents> WebContentsImpl::DetachFromOuterWebContents() {