Fix focus after an interstitial is destroyed.
When an interstitial is created, it steals the page's focus. When it is
destroyed, it is supposed to return focus to the page, however, since
the WebContents still thinks an interstitial is being displayed, the
RenderWidgetHostImpl tries to maintain the focus on the interstitial.
This CL fixes that by moving the Focus() call into
WebContentsImpl::DetachInterstitialPage, instead of being called in
InterstitialPageImpl::Hide.
Bug: 739676
Change-Id: I9eff1af3cb1500cc3f38400ae9e13e553bb0cf54
Reviewed-on: https://chromium-review.googlesource.com/565172
Reviewed-by: Charlie Reis <[email protected]>
Reviewed-by: Alex Moshchuk <[email protected]>
Commit-Queue: Lucas Gadani <[email protected]>
Cr-Commit-Position: refs/heads/master@{#485782}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index e5c923a..0970706 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -2919,11 +2919,17 @@
LoadingStateChanged(true, true, nullptr);
}
-void WebContentsImpl::DetachInterstitialPage() {
+void WebContentsImpl::DetachInterstitialPage(bool has_focus) {
bool interstitial_pausing_throbber =
ShowingInterstitialPage() && interstitial_page_->pause_throbber();
if (ShowingInterstitialPage())
interstitial_page_ = nullptr;
+
+ // If the focus was on the interstitial, let's keep it to the page.
+ // (Note that in unit-tests the RVH may not have a view).
+ if (has_focus && GetRenderViewHost()->GetWidget()->GetView())
+ GetRenderViewHost()->GetWidget()->GetView()->Focus();
+
for (auto& observer : observers_)
observer.DidDetachInterstitialPage();