Fix JS dialog interaction with bfcache

Problem: When a tab navigates away from a page and then back again, if
the page goes into bfcache, JS dialogs no longer appear.

Cause: In SwapOutOldFrame, before deciding whether the page goes into
bfcache we call SuppressFurtherDialogs but if the page is going into
bfcache, this prevents all future dialogs from appearing.

Fix: Replace IsWaitingForUnloadACK with !is_active() on the renderer
side when deciding whether to show a dialog or immediately drop it and
reply to the renderer as if the dialog was dismissed.

After discussion and digging, altimin@ thinks this is safe. We will stop
showing new dialogs as intended.

The concern about nested event loops at the point of entry to bfcache is
not a worry as the dialog nested event loop does nothing except handle
the dialog response IPC, everything else is queued for the outer loop.

Dialogs already stop blocking in JS when the user switches tabs (the
dialog stays on-screen but the JS call to e.g. window.alert() returns.
So no site should be relying on their dialog being dismissed by real user
interaction.

This adds a will_enter_back_forward_cache_callback_for_testing_ callback
to allow more control of the timing of the JS run. The test that uses it
fails if I replace !is_active with IsWaitingForUnloadACK.

Bug: 1030133
Change-Id: I25ab4518399d82187028bbefb22b5722475d0cb3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1955245
Commit-Queue: Fergal Daly <fergal@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Charlie Reis <creis@chromium.org>
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: Alexander Timin <altimin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726656}
11 files changed