This relands commit d362fb38ef.
This was reverted due to failures in
ExtensionCrashRecoveryBrowsertest, which were caused by reloading an
extension and not properly waiting for the background context to be
active, and then asserting that it was registered in the
ProcessManager. This is fixed by properly waiting for the background
context (when possible) in ExtensionBrowserTest::ReloadExtension().
Original change's description:
> [Extensions] Move frame registration to document commit time
>
> Based on nasko@'s CL at
> https://chromium-review.googlesource.com/c/chromium/src/+/5525999
>
> When a navigation requires a new RenderFrameHost to be created for it,
> the RenderFrameCreated observer method is called earlier in the
> navigation process. There is potentially state that is incorrect at that
> time, for example the SiteInstance for the navigation. When initializing
> state related to the new document, a better point in time to do so is
> the ReadyToCommitNavigation point in the timeline.
>
> This CL moves the extensions WebContents observer code to use the
> ReadyToCommit signal and does so behind a flag to ensure we can quickly
> revert in case of regressions.
>
> This also required a number of test updates, including:
> * Properly waiting for a background page when installing an extension.
> Previously, we relied on the extension background page being
> registered in the process manager by the time the extension was added,
> which wasn't really guaranteed, but happened because we registered it
> earlier.
> * Updating a BackgroundContents test to also wait for a hosted app's
> background contents to fully initialize.
> * Updating a NaCl test to keep an extension background page alive long
> enough for a tab to load (which then keeps it alive indefinitely).
>
> Bug: 334991035
> Change-Id: Icc858c5c3b35970a4ead322c94f79c0f955afe46
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6005549
> Reviewed-by: Nasko Oskov <nasko@chromium.org>
> Commit-Queue: Devlin Cronin <rdevlin.cronin@chromium.org>
> Reviewed-by: Ahmed Fakhry <afakhry@chromium.org>
> Reviewed-by: Derek Schuff <dschuff@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1381961}
Bug: 334991035
Change-Id: I1b123fb0bdd5f6fd9a76bd1313162de5bc3f9b58
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6014682
Reviewed-by: Ahmed Fakhry <afakhry@chromium.org>
Commit-Queue: Devlin Cronin <rdevlin.cronin@chromium.org>
Reviewed-by: Tim <tjudkins@chromium.org>
Reviewed-by: Derek Schuff <dschuff@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1382603}