OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser_init.h" | 5 #include "chrome/browser/ui/browser_init.h" |
6 | 6 |
7 #include <algorithm> // For max(). | 7 #include <algorithm> // For max(). |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 278 matching lines...) Loading... |
289 new NotifyNotDefaultBrowserTask()); | 289 new NotifyNotDefaultBrowserTask()); |
290 } | 290 } |
291 | 291 |
292 | 292 |
293 // SessionCrashedInfoBarDelegate ---------------------------------------------- | 293 // SessionCrashedInfoBarDelegate ---------------------------------------------- |
294 | 294 |
295 // A delegate for the InfoBar shown when the previous session has crashed. | 295 // A delegate for the InfoBar shown when the previous session has crashed. |
296 class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate { | 296 class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate { |
297 public: | 297 public: |
298 SessionCrashedInfoBarDelegate(Profile* profile, | 298 SessionCrashedInfoBarDelegate(Profile* profile, |
299 InfoBarTabHelper* infobar_helper); | 299 InfoBarTabHelper* infobar_helper, |
| 300 bool session_restore_enabled); |
300 | 301 |
301 private: | 302 private: |
302 virtual ~SessionCrashedInfoBarDelegate(); | 303 virtual ~SessionCrashedInfoBarDelegate(); |
303 | 304 |
304 // ConfirmInfoBarDelegate: | 305 // ConfirmInfoBarDelegate: |
305 virtual gfx::Image* GetIcon() const OVERRIDE; | 306 virtual gfx::Image* GetIcon() const OVERRIDE; |
306 virtual string16 GetMessageText() const OVERRIDE; | 307 virtual string16 GetMessageText() const OVERRIDE; |
307 virtual int GetButtons() const OVERRIDE; | 308 virtual int GetButtons() const OVERRIDE; |
308 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 309 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
309 virtual bool Accept() OVERRIDE; | 310 virtual bool Accept() OVERRIDE; |
| 311 virtual void InfoBarDismissed() OVERRIDE; |
| 312 virtual void InfoBarClosing() OVERRIDE; |
310 | 313 |
311 // The Profile that we restore sessions from. | 314 // The Profile that we restore sessions from. |
312 Profile* profile_; | 315 Profile* profile_; |
| 316 bool session_restore_enabled_; |
| 317 bool action_taken_; |
313 | 318 |
314 DISALLOW_COPY_AND_ASSIGN(SessionCrashedInfoBarDelegate); | 319 DISALLOW_COPY_AND_ASSIGN(SessionCrashedInfoBarDelegate); |
315 }; | 320 }; |
316 | 321 |
317 SessionCrashedInfoBarDelegate::SessionCrashedInfoBarDelegate( | 322 SessionCrashedInfoBarDelegate::SessionCrashedInfoBarDelegate( |
318 Profile* profile, | 323 Profile* profile, |
319 InfoBarTabHelper* infobar_helper) | 324 InfoBarTabHelper* infobar_helper, |
| 325 bool session_restore_enabled) |
320 : ConfirmInfoBarDelegate(infobar_helper), | 326 : ConfirmInfoBarDelegate(infobar_helper), |
321 profile_(profile) { | 327 profile_(profile), |
| 328 session_restore_enabled_(session_restore_enabled), |
| 329 action_taken_(false) { |
322 } | 330 } |
323 | 331 |
324 SessionCrashedInfoBarDelegate::~SessionCrashedInfoBarDelegate() { | 332 SessionCrashedInfoBarDelegate::~SessionCrashedInfoBarDelegate() { |
325 } | 333 } |
326 | 334 |
327 gfx::Image* SessionCrashedInfoBarDelegate::GetIcon() const { | 335 gfx::Image* SessionCrashedInfoBarDelegate::GetIcon() const { |
328 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 336 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
329 IDR_INFOBAR_RESTORE_SESSION); | 337 IDR_INFOBAR_RESTORE_SESSION); |
330 } | 338 } |
331 | 339 |
332 string16 SessionCrashedInfoBarDelegate::GetMessageText() const { | 340 string16 SessionCrashedInfoBarDelegate::GetMessageText() const { |
333 return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_VIEW_MESSAGE); | 341 return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_VIEW_MESSAGE); |
334 } | 342 } |
335 | 343 |
336 int SessionCrashedInfoBarDelegate::GetButtons() const { | 344 int SessionCrashedInfoBarDelegate::GetButtons() const { |
337 return BUTTON_OK; | 345 return BUTTON_OK; |
338 } | 346 } |
339 | 347 |
340 string16 SessionCrashedInfoBarDelegate::GetButtonLabel( | 348 string16 SessionCrashedInfoBarDelegate::GetButtonLabel( |
341 InfoBarButton button) const { | 349 InfoBarButton button) const { |
342 DCHECK_EQ(BUTTON_OK, button); | 350 DCHECK_EQ(BUTTON_OK, button); |
343 return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_VIEW_RESTORE_BUTTON); | 351 return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_VIEW_RESTORE_BUTTON); |
344 } | 352 } |
345 | 353 |
346 bool SessionCrashedInfoBarDelegate::Accept() { | 354 bool SessionCrashedInfoBarDelegate::Accept() { |
| 355 action_taken_ = true; |
347 uint32 behavior = 0; | 356 uint32 behavior = 0; |
348 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); | 357 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); |
349 if (browser && browser->tab_count() == 1 | 358 if (browser && browser->tab_count() == 1 |
350 && browser->GetTabContentsAt(0)->GetURL() == | 359 && browser->GetTabContentsAt(0)->GetURL() == |
351 GURL(chrome::kChromeUINewTabURL)) { | 360 GURL(chrome::kChromeUINewTabURL)) { |
352 // There is only one tab and its the new tab page, make session restore | 361 // There is only one tab and its the new tab page, make session restore |
353 // clobber it. | 362 // clobber it. |
354 behavior = SessionRestore::CLOBBER_CURRENT_TAB; | 363 behavior = SessionRestore::CLOBBER_CURRENT_TAB; |
355 } | 364 } |
| 365 if (session_restore_enabled_) |
| 366 profile_->RestoreSessionState(); |
356 SessionRestore::RestoreSession( | 367 SessionRestore::RestoreSession( |
357 profile_, browser, behavior, std::vector<GURL>()); | 368 profile_, browser, behavior, std::vector<GURL>()); |
358 return true; | 369 return true; |
359 } | 370 } |
360 | 371 |
| 372 void SessionCrashedInfoBarDelegate::InfoBarDismissed() { |
| 373 action_taken_ = true; |
| 374 if (session_restore_enabled_) |
| 375 profile_->DiscardSessionState(); |
| 376 } |
| 377 |
| 378 void SessionCrashedInfoBarDelegate::InfoBarClosing() { |
| 379 if (!action_taken_ && session_restore_enabled_) |
| 380 profile_->DiscardSessionState(); |
| 381 } |
361 | 382 |
362 // Utility functions ---------------------------------------------------------- | 383 // Utility functions ---------------------------------------------------------- |
363 | 384 |
364 bool IncognitoIsForced(const CommandLine& command_line, | 385 bool IncognitoIsForced(const CommandLine& command_line, |
365 const PrefService* prefs) { | 386 const PrefService* prefs) { |
366 IncognitoModePrefs::Availability incognito_avail = | 387 IncognitoModePrefs::Availability incognito_avail = |
367 IncognitoModePrefs::GetAvailability(prefs); | 388 IncognitoModePrefs::GetAvailability(prefs); |
368 return incognito_avail != IncognitoModePrefs::DISABLED && | 389 return incognito_avail != IncognitoModePrefs::DISABLED && |
369 (command_line.HasSwitch(switches::kIncognito) || | 390 (command_line.HasSwitch(switches::kIncognito) || |
370 incognito_avail == IncognitoModePrefs::FORCED); | 391 incognito_avail == IncognitoModePrefs::FORCED); |
(...skipping 538 matching lines...) Loading... |
909 | 930 |
910 if (pref.type == SessionStartupPref::LAST) { | 931 if (pref.type == SessionStartupPref::LAST) { |
911 if (!profile_->DidLastSessionExitCleanly() && | 932 if (!profile_->DidLastSessionExitCleanly() && |
912 !command_line_.HasSwitch(switches::kRestoreLastSession)) { | 933 !command_line_.HasSwitch(switches::kRestoreLastSession)) { |
913 // The last session crashed. It's possible automatically loading the | 934 // The last session crashed. It's possible automatically loading the |
914 // page will trigger another crash, locking the user out of chrome. | 935 // page will trigger another crash, locking the user out of chrome. |
915 // To avoid this, don't restore on startup but instead show the crashed | 936 // To avoid this, don't restore on startup but instead show the crashed |
916 // infobar. | 937 // infobar. |
917 return false; | 938 return false; |
918 } | 939 } |
| 940 if (command_line_.HasSwitch(switches::kEnableRestoreSessionState) && |
| 941 command_line_.HasSwitch(switches::kRestoreLastSession)) { |
| 942 profile_->RestoreSessionState(); |
| 943 } |
919 | 944 |
920 uint32 restore_behavior = SessionRestore::SYNCHRONOUS | | 945 uint32 restore_behavior = SessionRestore::SYNCHRONOUS | |
921 SessionRestore::ALWAYS_CREATE_TABBED_BROWSER; | 946 SessionRestore::ALWAYS_CREATE_TABBED_BROWSER; |
922 #if defined(OS_MACOSX) | 947 #if defined(OS_MACOSX) |
923 // On Mac, when restoring a session with no windows, suppress the creation | 948 // On Mac, when restoring a session with no windows, suppress the creation |
924 // of a new window in the case where the system is launching Chrome via a | 949 // of a new window in the case where the system is launching Chrome via a |
925 // login item or Lion's resume feature. | 950 // login item or Lion's resume feature. |
926 if (base::mac::WasLaunchedAsLoginOrResumeItem()) { | 951 if (base::mac::WasLaunchedAsLoginOrResumeItem()) { |
927 restore_behavior = restore_behavior & | 952 restore_behavior = restore_behavior & |
928 ~SessionRestore::ALWAYS_CREATE_TABBED_BROWSER; | 953 ~SessionRestore::ALWAYS_CREATE_TABBED_BROWSER; |
(...skipping 157 matching lines...) Loading... |
1086 | 1111 |
1087 void BrowserInit::LaunchWithProfile::AddCrashedInfoBarIfNecessary( | 1112 void BrowserInit::LaunchWithProfile::AddCrashedInfoBarIfNecessary( |
1088 Browser* browser, | 1113 Browser* browser, |
1089 TabContentsWrapper* tab) { | 1114 TabContentsWrapper* tab) { |
1090 // Assume that if the user is launching incognito they were previously | 1115 // Assume that if the user is launching incognito they were previously |
1091 // running incognito so that we have nothing to restore from. | 1116 // running incognito so that we have nothing to restore from. |
1092 if (!profile_->DidLastSessionExitCleanly() && !profile_->IsOffTheRecord()) { | 1117 if (!profile_->DidLastSessionExitCleanly() && !profile_->IsOffTheRecord()) { |
1093 // The last session didn't exit cleanly. Show an infobar to the user | 1118 // The last session didn't exit cleanly. Show an infobar to the user |
1094 // so that they can restore if they want. The delegate deletes itself when | 1119 // so that they can restore if they want. The delegate deletes itself when |
1095 // it is closed. | 1120 // it is closed. |
| 1121 bool session_restore_enabled = |
| 1122 command_line_.HasSwitch(switches::kEnableRestoreSessionState); |
1096 tab->infobar_tab_helper()->AddInfoBar( | 1123 tab->infobar_tab_helper()->AddInfoBar( |
1097 new SessionCrashedInfoBarDelegate(profile_, tab->infobar_tab_helper())); | 1124 new SessionCrashedInfoBarDelegate(profile_, tab->infobar_tab_helper(), |
| 1125 session_restore_enabled)); |
1098 } | 1126 } |
1099 } | 1127 } |
1100 | 1128 |
1101 void BrowserInit::LaunchWithProfile::AddBadFlagsInfoBarIfNecessary( | 1129 void BrowserInit::LaunchWithProfile::AddBadFlagsInfoBarIfNecessary( |
1102 TabContentsWrapper* tab) { | 1130 TabContentsWrapper* tab) { |
1103 // Unsupported flags for which to display a warning that "stability and | 1131 // Unsupported flags for which to display a warning that "stability and |
1104 // security will suffer". | 1132 // security will suffer". |
1105 static const char* kBadFlags[] = { | 1133 static const char* kBadFlags[] = { |
1106 // These imply disabling the sandbox. | 1134 // These imply disabling the sandbox. |
1107 switches::kSingleProcess, | 1135 switches::kSingleProcess, |
(...skipping 413 matching lines...) Loading... |
1521 if (!automation->InitializeChannel(channel_id)) | 1549 if (!automation->InitializeChannel(channel_id)) |
1522 return false; | 1550 return false; |
1523 automation->SetExpectedTabCount(expected_tabs); | 1551 automation->SetExpectedTabCount(expected_tabs); |
1524 | 1552 |
1525 AutomationProviderList* list = g_browser_process->GetAutomationProviderList(); | 1553 AutomationProviderList* list = g_browser_process->GetAutomationProviderList(); |
1526 DCHECK(list); | 1554 DCHECK(list); |
1527 list->AddProvider(automation); | 1555 list->AddProvider(automation); |
1528 | 1556 |
1529 return true; | 1557 return true; |
1530 } | 1558 } |
OLD | NEW |