[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 9cddb1a2 | 2011-11-15 15:04:27 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 79b1896 | 2012-03-06 06:16:15 | [diff] [blame] | 5 | #include "chrome/browser/ui/sad_tab_helper.h" |
[email protected] | 9cddb1a2 | 2011-11-15 15:04:27 | [diff] [blame] | 6 | |
[email protected] | c47317e | 2012-06-20 22:35:31 | [diff] [blame] | 7 | #include "base/logging.h" |
[email protected] | 9cddb1a2 | 2011-11-15 15:04:27 | [diff] [blame] | 8 | #include "chrome/browser/browser_shutdown.h" |
[email protected] | 01a0026 | 2012-12-06 12:28:15 | [diff] [blame] | 9 | #include "chrome/browser/ui/sad_tab.h" |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 10 | #include "content/public/browser/web_contents.h" |
[email protected] | 9cddb1a2 | 2011-11-15 15:04:27 | [diff] [blame] | 11 | |
[email protected] | dc8b0fc | 2013-01-07 20:39:24 | [diff] [blame] | 12 | DEFINE_WEB_CONTENTS_USER_DATA_KEY(SadTabHelper); |
[email protected] | e81f50d | 2012-09-19 18:42:38 | [diff] [blame] | 13 | |
[email protected] | 721048d | 2012-12-13 19:15:32 | [diff] [blame] | 14 | SadTabHelper::~SadTabHelper() { |
15 | } | ||||
16 | |||||
[email protected] | a506c5f | 2012-07-10 13:09:06 | [diff] [blame] | 17 | SadTabHelper::SadTabHelper(content::WebContents* web_contents) |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 18 | : content::WebContentsObserver(web_contents) { |
[email protected] | b8cd8703 | 2013-09-04 23:53:47 | [diff] [blame] | 19 | } |
20 | |||||
21 | void SadTabHelper::RenderViewReady() { | ||||
22 | if (sad_tab_) { | ||||
23 | sad_tab_->Close(); | ||||
24 | sad_tab_.reset(); | ||||
25 | } | ||||
[email protected] | 9cddb1a2 | 2011-11-15 15:04:27 | [diff] [blame] | 26 | } |
27 | |||||
[email protected] | 58d5cfe | 2013-07-10 02:40:52 | [diff] [blame] | 28 | void SadTabHelper::RenderProcessGone(base::TerminationStatus status) { |
[email protected] | 3dfa7f3c | 2012-04-18 18:01:32 | [diff] [blame] | 29 | // Only show the sad tab if we're not in browser shutdown, so that WebContents |
[email protected] | 9cddb1a2 | 2011-11-15 15:04:27 | [diff] [blame] | 30 | // 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] | 721048d | 2012-12-13 19:15:32 | [diff] [blame] | 35 | if (sad_tab_) |
[email protected] | 9cddb1a2 | 2011-11-15 15:04:27 | [diff] [blame] | 36 | return; |
37 | |||||
[email protected] | 13155a2 | 2013-03-19 23:33:54 | [diff] [blame] | 38 | if (chrome::SadTab::ShouldShow(status)) |
[email protected] | caf7c8f8 | 2012-10-18 23:53:58 | [diff] [blame] | 39 | InstallSadTab(status); |
[email protected] | 9cddb1a2 | 2011-11-15 15:04:27 | [diff] [blame] | 40 | } |
41 | |||||
[email protected] | 79b1896 | 2012-03-06 06:16:15 | [diff] [blame] | 42 | void SadTabHelper::InstallSadTab(base::TerminationStatus status) { |
[email protected] | a506c5f | 2012-07-10 13:09:06 | [diff] [blame] | 43 | chrome::SadTabKind kind = |
44 | (status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED) ? | ||||
45 | chrome::SAD_TAB_KIND_KILLED : chrome::SAD_TAB_KIND_CRASHED; | ||||
[email protected] | 01a0026 | 2012-12-06 12:28:15 | [diff] [blame] | 46 | sad_tab_.reset(chrome::SadTab::Create(web_contents(), kind)); |
[email protected] | b137c12 | 2012-11-20 00:12:00 | [diff] [blame] | 47 | sad_tab_->Show(); |
[email protected] | 9cddb1a2 | 2011-11-15 15:04:27 | [diff] [blame] | 48 | } |