blob: ab8a6e034ea0d62936f59147d5f36a64856817e1 [file] [log] [blame]
[email protected]8643e6d2012-01-18 20:26:101// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]9cddb1a22011-11-15 15:04:272// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]79b18962012-03-06 06:16:155#include "chrome/browser/ui/sad_tab_helper.h"
[email protected]9cddb1a22011-11-15 15:04:276
[email protected]c47317e2012-06-20 22:35:317#include "base/logging.h"
[email protected]9cddb1a22011-11-15 15:04:278#include "chrome/browser/browser_shutdown.h"
[email protected]01a00262012-12-06 12:28:159#include "chrome/browser/ui/sad_tab.h"
[email protected]83ff91c2012-01-05 20:54:1310#include "content/public/browser/web_contents.h"
[email protected]9cddb1a22011-11-15 15:04:2711
[email protected]dc8b0fc2013-01-07 20:39:2412DEFINE_WEB_CONTENTS_USER_DATA_KEY(SadTabHelper);
[email protected]e81f50d2012-09-19 18:42:3813
[email protected]721048d2012-12-13 19:15:3214SadTabHelper::~SadTabHelper() {
15}
16
[email protected]a506c5f2012-07-10 13:09:0617SadTabHelper::SadTabHelper(content::WebContents* web_contents)
[email protected]83ff91c2012-01-05 20:54:1318 : content::WebContentsObserver(web_contents) {
[email protected]b8cd87032013-09-04 23:53:4719}
20
21void SadTabHelper::RenderViewReady() {
22 if (sad_tab_) {
23 sad_tab_->Close();
24 sad_tab_.reset();
25 }
[email protected]9cddb1a22011-11-15 15:04:2726}
27
[email protected]58d5cfe2013-07-10 02:40:5228void SadTabHelper::RenderProcessGone(base::TerminationStatus status) {
[email protected]3dfa7f3c2012-04-18 18:01:3229 // Only show the sad tab if we're not in browser shutdown, so that WebContents
[email protected]9cddb1a22011-11-15 15:04:2730 // objects that are not in a browser (e.g., HTML dialogs) and thus are
31 // visible do not flash a sad tab page.
32 if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID)
33 return;
34
[email protected]721048d2012-12-13 19:15:3235 if (sad_tab_)
[email protected]9cddb1a22011-11-15 15:04:2736 return;
37
[email protected]13155a22013-03-19 23:33:5438 if (chrome::SadTab::ShouldShow(status))
[email protected]caf7c8f82012-10-18 23:53:5839 InstallSadTab(status);
[email protected]9cddb1a22011-11-15 15:04:2740}
41
[email protected]79b18962012-03-06 06:16:1542void SadTabHelper::InstallSadTab(base::TerminationStatus status) {
[email protected]a506c5f2012-07-10 13:09:0643 chrome::SadTabKind kind =
44 (status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED) ?
45 chrome::SAD_TAB_KIND_KILLED : chrome::SAD_TAB_KIND_CRASHED;
[email protected]01a00262012-12-06 12:28:1546 sad_tab_.reset(chrome::SadTab::Create(web_contents(), kind));
[email protected]b137c122012-11-20 00:12:0047 sad_tab_->Show();
[email protected]9cddb1a22011-11-15 15:04:2748}