Don't try to close first-navigation tabs when showing the supervised user interstitial inside a <webview>.
A WebContents in a <webview> is under the control of the embedding page, so we
can't simply close it (and there isn't a browser or tab strip for it anyway).
BUG=545394
Review URL: https://codereview.chromium.org/1417813004
Cr-Commit-Position: refs/heads/master@{#355300}
diff --git a/chrome/browser/supervised_user/supervised_user_interstitial.cc b/chrome/browser/supervised_user/supervised_user_interstitial.cc
index dcb91a2..3810abd 100644
--- a/chrome/browser/supervised_user/supervised_user_interstitial.cc
+++ b/chrome/browser/supervised_user/supervised_user_interstitial.cc
@@ -61,7 +61,20 @@
}
class TabCloser : public content::WebContentsUserData<TabCloser> {
- // To use, call TabCloser::CreateForWebContents.
+ public:
+ static void MaybeClose(WebContents* web_contents) {
+ // Close the tab if there is no history entry to go back to and there is a
+ // browser for the tab (which is not the case for example in a <webview>).
+ if (!web_contents->GetController().IsInitialBlankNavigation())
+ return;
+
+#if !defined(OS_ANDROID)
+ if (!chrome::FindBrowserWithWebContents(web_contents))
+ return;
+#endif
+ TabCloser::CreateForWebContents(web_contents);
+ }
+
private:
friend class content::WebContentsUserData<TabCloser>;
@@ -305,10 +318,7 @@
DCHECK(web_contents->GetController().GetTransientEntry());
interstitial_page_->DontProceed();
- // Close the tab if there is no history entry to go back to.
- if (web_contents->GetController().IsInitialBlankNavigation())
- TabCloser::CreateForWebContents(web_contents);
-
+ TabCloser::MaybeClose(web_contents);
return;
}