Make RenderFrameHost responsible for initializing its RenderWidgetHost
Currently we have WebContentsImpl and RenderViewHost share
responsibility for initializing the RenderWidgetHost that is for a
main frame RenderFrameHost, as the logical "ownership" of
RenderWidgetHost used to be from the RenderViewHost. While the pointer
is still owned there, now each local root RenderFrameHost is
responsible for its RenderWidgetHost, and the main frame one should be
likewise.
This makes RenderFrameCreated() initialize the RenderWidgetHost before
calling the delegate. The code used to work in the wrong order
because WebContents was also initializing the RenderWidgetHost and/or
marking the RenderViewHost as live.
Now RenderViewHost will only mark the top-level RenderWidgetHost as
live if it will not have a local main frame, in which case the
RenderViewHost is still responsible for the very unfortunate semi-
dead RenderWidgetHost.
We split off a RenderWidgetHostImpl::Init() as InitForPopup() and only
call that from WebContents if its a popup widget.
We also eliminate branches in RenderWidgetHostImpl that handled its
initialize paths being called in multiple orders and for both popups
and frames. And we remove the notification back to RenderViewHost
that the widget was initialized. The RenderViewHost will call
PostRenderViewReady() when the RenderView is created already, and the
notice from RenderWidgetHost initialization was causing two calls out
to WebContentsObservers. The RenderWidgetHost was notifying the
RenderView due to the RenderWidgetHost being "live" is what also marks
the RenderViewHost as "live". But since RenderViewHost will either
a) call RenderFrameCreated() which will initialize the
RenderWdigetHost, or
b) set the RenderWidgetHost as live when there is no main frame,
we know that the RenderWidgetHost/RenderViewHost are considered "live"
when RenderViewCreated() is done, so its PostRenderViewReady() is
sufficient.
We add plumbing for RenderWidgetHostImpl that mirrors the main frame
RenderFrameHostImpl to set a waiting_for_init_ flag, which delays
WasShown, SynchronizeVisualProperties, and SendScreenRects IPCs. Once
Init() is called on the main frame RenderFrameHost it will also Init()
the RenderWidgetHost and unblock those IPCs.
We drop code in BackgroundContents saying that we're waiting for the
renderer to show the window before we Init(). We were then promptly
calling Init() while creating the WebContents, so the whole thing was
not doing much. This way we don't try to Init() the WebContents,
pretending to be the renderer, before we have created the renderer-side
frame/widget objects. This was not possible before, as seen by the CL
https://chromium-review.googlesource.com/c/chromium/src/+/2606521, but
it is with these changes to sort out the order of Init() for the widget.
R=nasko@chromium.org
Bug: 1158869
Change-Id: I7d0943a4df20caeedecc8b165aeb1d196b3331a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2597851
Commit-Queue: danakj <danakj@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Nasko Oskov <nasko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839791}
diff --git a/content/browser/renderer_host/frame_tree.h b/content/browser/renderer_host/frame_tree.h
index bbf18355..da1aa9c 100644
--- a/content/browser/renderer_host/frame_tree.h
+++ b/content/browser/renderer_host/frame_tree.h
@@ -216,7 +216,8 @@
scoped_refptr<RenderViewHostImpl> CreateRenderViewHost(
SiteInstance* site_instance,
int32_t main_frame_routing_id,
- bool swapped_out);
+ bool swapped_out,
+ bool renderer_initiated_creation);
// Returns the existing RenderViewHost for a new RenderFrameHost.
// There should always be such a RenderViewHost, because the main frame