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 "components/sad_tab/sad_tab_helper.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "components/sad_tab/sad_tab.h" |
8 #include "chrome/browser/browser_shutdown.h" | 8 #include "components/sad_tab/sad_tab_client.h" |
9 #include "chrome/browser/ui/sad_tab.h" | |
10 #include "content/public/browser/web_contents.h" | |
11 | 9 |
12 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SadTabHelper); | 10 DEFINE_WEB_CONTENTS_USER_DATA_KEY(sad_tab::SadTabHelper); |
| 11 |
| 12 namespace sad_tab { |
| 13 |
| 14 // static |
| 15 void SadTabHelper::CreateForWebContentsWithClient( |
| 16 content::WebContents* contents, |
| 17 scoped_ptr<SadTabClient> client) { |
| 18 if (!FromWebContents(contents)) { |
| 19 contents->SetUserData(UserDataKey(), |
| 20 new SadTabHelper(contents, client.Pass())); |
| 21 } |
| 22 } |
13 | 23 |
14 SadTabHelper::~SadTabHelper() { | 24 SadTabHelper::~SadTabHelper() { |
15 } | 25 } |
16 | 26 |
17 SadTabHelper::SadTabHelper(content::WebContents* web_contents) | 27 SadTabHelper::SadTabHelper(content::WebContents* web_contents, |
18 : content::WebContentsObserver(web_contents) { | 28 scoped_ptr<SadTabClient> client) |
| 29 : content::WebContentsObserver(web_contents), |
| 30 client_(client.Pass()) { |
19 } | 31 } |
20 | 32 |
21 void SadTabHelper::RenderViewReady() { | 33 void SadTabHelper::RenderViewReady() { |
22 if (sad_tab_) { | 34 if (sad_tab_) { |
23 sad_tab_->Close(); | 35 sad_tab_->Close(); |
24 sad_tab_.reset(); | 36 sad_tab_.reset(); |
25 } | 37 } |
26 } | 38 } |
27 | 39 |
28 void SadTabHelper::RenderProcessGone(base::TerminationStatus status) { | 40 void SadTabHelper::RenderProcessGone(base::TerminationStatus status) { |
29 // Only show the sad tab if we're not in browser shutdown, so that WebContents | 41 // Only show the sad tab if we're not in browser shutdown, so that WebContents |
30 // objects that are not in a browser (e.g., HTML dialogs) and thus are | 42 // objects that are not in a browser (e.g., HTML dialogs) and thus are |
31 // visible do not flash a sad tab page. | 43 // visible do not flash a sad tab page. |
32 if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID) | 44 if (client_->IsInBrowserShutdown()) |
33 return; | 45 return; |
34 | 46 |
35 if (sad_tab_) | 47 if (sad_tab_) |
36 return; | 48 return; |
37 | 49 |
38 if (chrome::SadTab::ShouldShow(status)) | 50 if (SadTab::ShouldShow(status)) |
39 InstallSadTab(status); | 51 InstallSadTab(status); |
40 } | 52 } |
41 | 53 |
42 void SadTabHelper::InstallSadTab(base::TerminationStatus status) { | 54 void SadTabHelper::InstallSadTab(base::TerminationStatus status) { |
43 chrome::SadTabKind kind = | 55 SadTabKind kind = (status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED) ? |
44 (status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED) ? | 56 SAD_TAB_KIND_KILLED : SAD_TAB_KIND_CRASHED; |
45 chrome::SAD_TAB_KIND_KILLED : chrome::SAD_TAB_KIND_CRASHED; | 57 sad_tab_.reset(SadTab::Create(web_contents(), kind, client_.get())); |
46 sad_tab_.reset(chrome::SadTab::Create(web_contents(), kind)); | |
47 sad_tab_->Show(); | 58 sad_tab_->Show(); |
48 } | 59 } |
| 60 |
| 61 } // namespace sad_tab |
OLD | NEW |