Fix focus for PDF in mainframe, add test.

This CL started out as a re-implementation of
WebPluginContainerTest.PluginDocumentPluginIsFocused to work without
BrowserPlugin, but in the process I realized that we had regressed
the behaviour that was originally fixed in
https://codereview.chromium.org/1389093002.

That regression is also fixed in this CL.

Bug: 1019360, 536637, 1022469
Change-Id: I25bbe47fb602b8a3ef5d9be931e7d5fe486c4008
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1903653
Commit-Queue: James MacLean <[email protected]>
Reviewed-by: Lei Zhang <[email protected]>
Reviewed-by: Alex Moshchuk <[email protected]>
Cr-Commit-Position: refs/heads/master@{#714635}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 15e5b38..fdd66fa 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -1768,7 +1768,8 @@
 
 void WebContentsImpl::AttachInnerWebContents(
     std::unique_ptr<WebContents> inner_web_contents,
-    RenderFrameHost* render_frame_host) {
+    RenderFrameHost* render_frame_host,
+    bool is_full_page) {
   WebContentsImpl* inner_web_contents_impl =
       static_cast<WebContentsImpl*>(inner_web_contents.get());
   DCHECK(!inner_web_contents_impl->node_.outer_web_contents());
@@ -1833,6 +1834,14 @@
         render_frame_host_impl->GetSiteInstance());
   }
   outer_render_manager->set_attach_complete();
+
+  // If the inner WebContents is full frame, give it focus.
+  if (is_full_page) {
+    // There should only ever be one inner WebContents when |is_full_page| is
+    // true, and it is the one we just attached.
+    DCHECK_EQ(1u, node_.GetInnerWebContents().size());
+    inner_web_contents_impl->SetAsFocusedWebContentsIfNecessary();
+  }
 }
 
 std::unique_ptr<WebContents> WebContentsImpl::DetachFromOuterWebContents() {