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/startup/session_crashed_prompt.h" | 5 #include "chrome/browser/ui/startup/session_crashed_prompt.h" |
6 | 6 |
7 #include "chrome/browser/infobars/infobar_tab_helper.h" | 7 #include "chrome/browser/infobars/infobar_tab_helper.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/sessions/session_restore.h" | 9 #include "chrome/browser/sessions/session_restore.h" |
10 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 10 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
11 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 11 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
| 14 #include "chrome/browser/ui/browser_tabstrip.h" |
14 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
16 #include "grit/chromium_strings.h" | 17 #include "grit/chromium_strings.h" |
17 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
18 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
19 #include "grit/theme_resources_standard.h" | 20 #include "grit/theme_resources_standard.h" |
20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
21 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
22 | 23 |
23 namespace { | 24 namespace { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 InfoBarButton button) const { | 66 InfoBarButton button) const { |
66 DCHECK_EQ(BUTTON_OK, button); | 67 DCHECK_EQ(BUTTON_OK, button); |
67 return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_VIEW_RESTORE_BUTTON); | 68 return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_VIEW_RESTORE_BUTTON); |
68 } | 69 } |
69 | 70 |
70 bool SessionCrashedInfoBarDelegate::Accept() { | 71 bool SessionCrashedInfoBarDelegate::Accept() { |
71 uint32 behavior = 0; | 72 uint32 behavior = 0; |
72 Browser* browser = | 73 Browser* browser = |
73 browser::FindBrowserWithWebContents(owner()->web_contents()); | 74 browser::FindBrowserWithWebContents(owner()->web_contents()); |
74 if (browser->tab_count() == 1 && | 75 if (browser->tab_count() == 1 && |
75 browser->GetWebContentsAt(0)->GetURL() == | 76 chrome::GetWebContentsAt(browser, 0)->GetURL() == |
76 GURL(chrome::kChromeUINewTabURL)) { | 77 GURL(chrome::kChromeUINewTabURL)) { |
77 // There is only one tab and its the new tab page, make session restore | 78 // There is only one tab and its the new tab page, make session restore |
78 // clobber it. | 79 // clobber it. |
79 behavior = SessionRestore::CLOBBER_CURRENT_TAB; | 80 behavior = SessionRestore::CLOBBER_CURRENT_TAB; |
80 } | 81 } |
81 SessionRestore::RestoreSession( | 82 SessionRestore::RestoreSession( |
82 browser->profile(), browser, behavior, std::vector<GURL>()); | 83 browser->profile(), browser, behavior, std::vector<GURL>()); |
83 return true; | 84 return true; |
84 } | 85 } |
85 | 86 |
86 } // namespace | 87 } // namespace |
87 | 88 |
88 | 89 |
89 namespace browser { | 90 namespace browser { |
90 | 91 |
91 void ShowSessionCrashedPrompt(Browser* browser) { | 92 void ShowSessionCrashedPrompt(Browser* browser) { |
92 // Assume that if the user is launching incognito they were previously | 93 // Assume that if the user is launching incognito they were previously |
93 // running incognito so that we have nothing to restore from. | 94 // running incognito so that we have nothing to restore from. |
94 if (browser->profile()->IsOffTheRecord()) | 95 if (browser->profile()->IsOffTheRecord()) |
95 return; | 96 return; |
96 | 97 |
97 // In ChromeBot tests, there might be a race. This line appears to get | 98 // In ChromeBot tests, there might be a race. This line appears to get |
98 // called during shutdown and |tab| can be NULL. | 99 // called during shutdown and |tab| can be NULL. |
99 TabContents* tab = browser->GetActiveTabContents(); | 100 TabContents* tab = chrome::GetActiveTabContents(browser); |
100 if (!tab) | 101 if (!tab) |
101 return; | 102 return; |
102 | 103 |
103 // Don't show the info-bar if there are already info-bars showing. | 104 // Don't show the info-bar if there are already info-bars showing. |
104 if (tab->infobar_tab_helper()->infobar_count() > 0) | 105 if (tab->infobar_tab_helper()->infobar_count() > 0) |
105 return; | 106 return; |
106 | 107 |
107 tab->infobar_tab_helper()->AddInfoBar( | 108 tab->infobar_tab_helper()->AddInfoBar( |
108 new SessionCrashedInfoBarDelegate(tab->infobar_tab_helper())); | 109 new SessionCrashedInfoBarDelegate(tab->infobar_tab_helper())); |
109 } | 110 } |
110 | 111 |
111 } // namespace browser | 112 } // namespace browser |
112 | 113 |
OLD | NEW |