OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/sad_tab_helper.h" | 5 #include "chrome/browser/ui/sad_tab_helper.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/browser_shutdown.h" | 8 #include "chrome/browser/browser_shutdown.h" |
9 #include "chrome/browser/ui/sad_tab.h" | 9 #include "chrome/browser/ui/sad_tab.h" |
10 #include "content/public/browser/notification_source.h" | |
11 #include "content/public/browser/notification_types.h" | |
12 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
13 #include "content/public/browser/web_contents_view.h" | 11 #include "content/public/browser/web_contents_view.h" |
14 | 12 |
15 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SadTabHelper); | 13 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SadTabHelper); |
16 | 14 |
17 SadTabHelper::~SadTabHelper() { | 15 SadTabHelper::~SadTabHelper() { |
18 } | 16 } |
19 | 17 |
20 SadTabHelper::SadTabHelper(content::WebContents* web_contents) | 18 SadTabHelper::SadTabHelper(content::WebContents* web_contents) |
21 : content::WebContentsObserver(web_contents) { | 19 : content::WebContentsObserver(web_contents) { |
22 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, | 20 } |
23 content::Source<content::WebContents>(web_contents)); | 21 |
| 22 void SadTabHelper::RenderViewReady() { |
| 23 if (sad_tab_) { |
| 24 sad_tab_->Close(); |
| 25 sad_tab_.reset(); |
| 26 } |
24 } | 27 } |
25 | 28 |
26 void SadTabHelper::RenderProcessGone(base::TerminationStatus status) { | 29 void SadTabHelper::RenderProcessGone(base::TerminationStatus status) { |
27 // Only show the sad tab if we're not in browser shutdown, so that WebContents | 30 // Only show the sad tab if we're not in browser shutdown, so that WebContents |
28 // objects that are not in a browser (e.g., HTML dialogs) and thus are | 31 // objects that are not in a browser (e.g., HTML dialogs) and thus are |
29 // visible do not flash a sad tab page. | 32 // visible do not flash a sad tab page. |
30 if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID) | 33 if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID) |
31 return; | 34 return; |
32 | 35 |
33 if (sad_tab_) | 36 if (sad_tab_) |
34 return; | 37 return; |
35 | 38 |
36 if (chrome::SadTab::ShouldShow(status)) | 39 if (chrome::SadTab::ShouldShow(status)) |
37 InstallSadTab(status); | 40 InstallSadTab(status); |
38 } | 41 } |
39 | 42 |
40 void SadTabHelper::Observe(int type, | |
41 const content::NotificationSource& source, | |
42 const content::NotificationDetails& details) { | |
43 DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_CONNECTED, type); | |
44 if (sad_tab_) { | |
45 sad_tab_->Close(); | |
46 sad_tab_.reset(); | |
47 } | |
48 } | |
49 | |
50 void SadTabHelper::InstallSadTab(base::TerminationStatus status) { | 43 void SadTabHelper::InstallSadTab(base::TerminationStatus status) { |
51 chrome::SadTabKind kind = | 44 chrome::SadTabKind kind = |
52 (status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED) ? | 45 (status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED) ? |
53 chrome::SAD_TAB_KIND_KILLED : chrome::SAD_TAB_KIND_CRASHED; | 46 chrome::SAD_TAB_KIND_KILLED : chrome::SAD_TAB_KIND_CRASHED; |
54 sad_tab_.reset(chrome::SadTab::Create(web_contents(), kind)); | 47 sad_tab_.reset(chrome::SadTab::Create(web_contents(), kind)); |
55 sad_tab_->Show(); | 48 sad_tab_->Show(); |
56 } | 49 } |
OLD | NEW |