| 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/startup_browser_creator_impl.h" | 5 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 } | 334 } |
| 335 | 335 |
| 336 // Open the required browser windows and tabs. First, see if | 336 // Open the required browser windows and tabs. First, see if |
| 337 // we're being run as an application window. If so, the user | 337 // we're being run as an application window. If so, the user |
| 338 // opened an app shortcut. Don't restore tabs or open initial | 338 // opened an app shortcut. Don't restore tabs or open initial |
| 339 // URLs in that case. The user should see the window as an app, | 339 // URLs in that case. The user should see the window as an app, |
| 340 // not as chrome. | 340 // not as chrome. |
| 341 // Special case is when app switches are passed but we do want to restore | 341 // Special case is when app switches are passed but we do want to restore |
| 342 // session. In that case open app window + focus it after session is restored. | 342 // session. In that case open app window + focus it after session is restored. |
| 343 content::WebContents* app_contents = NULL; | 343 content::WebContents* app_contents = NULL; |
| 344 if (OpenApplicationWindow(profile, &app_contents) && | 344 if (OpenApplicationWindow(profile, &app_contents)) { |
| 345 !browser_defaults::kAppRestoreSession) { | |
| 346 RecordLaunchModeHistogram(LM_AS_WEBAPP); | 345 RecordLaunchModeHistogram(LM_AS_WEBAPP); |
| 347 } else { | 346 } else { |
| 348 RecordLaunchModeHistogram(urls_to_open.empty() ? | 347 RecordLaunchModeHistogram(urls_to_open.empty() ? |
| 349 LM_TO_BE_DECIDED : LM_WITH_URLS); | 348 LM_TO_BE_DECIDED : LM_WITH_URLS); |
| 350 | 349 |
| 351 // Notify user if the Preferences backup is invalid or changes to settings | 350 // Notify user if the Preferences backup is invalid or changes to settings |
| 352 // affecting browser startup have been detected. | 351 // affecting browser startup have been detected. |
| 353 CheckPreferencesBackup(profile); | 352 CheckPreferencesBackup(profile); |
| 354 | 353 |
| 355 // Watch for |app_contents| closing since ProcessLaunchURLs might run a | |
| 356 // synchronous session restore which has a nested message loop and could | |
| 357 // close |app_contents|. | |
| 358 WebContentsCloseObserver app_contents_observer; | |
| 359 if (browser_defaults::kAppRestoreSession && app_contents) | |
| 360 app_contents_observer.SetContents(app_contents); | |
| 361 | |
| 362 ProcessLaunchURLs(process_startup, urls_to_open); | 354 ProcessLaunchURLs(process_startup, urls_to_open); |
| 363 | 355 |
| 364 // If this is an app launch, but we didn't open an app window, it may | 356 // If this is an app launch, but we didn't open an app window, it may |
| 365 // be an app tab. | 357 // be an app tab. |
| 366 OpenApplicationTab(profile); | 358 OpenApplicationTab(profile); |
| 367 | 359 |
| 368 // In case of app mode + session restore we want to focus that app. | |
| 369 if (app_contents_observer.contents()) | |
| 370 app_contents_observer.contents()->GetView()->SetInitialFocus(); | |
| 371 | |
| 372 if (process_startup) { | 360 if (process_startup) { |
| 373 if (browser_defaults::kOSSupportsOtherBrowsers && | 361 if (browser_defaults::kOSSupportsOtherBrowsers && |
| 374 !command_line_.HasSwitch(switches::kNoDefaultBrowserCheck)) { | 362 !command_line_.HasSwitch(switches::kNoDefaultBrowserCheck)) { |
| 375 // Generally, the default browser prompt should not be shown on first | 363 // Generally, the default browser prompt should not be shown on first |
| 376 // run. However, when the set-as-default dialog has been suppressed, we | 364 // run. However, when the set-as-default dialog has been suppressed, we |
| 377 // need to allow it. | 365 // need to allow it. |
| 378 if ((!is_first_run_ || | 366 if ((!is_first_run_ || |
| 379 (browser_creator_ && | 367 (browser_creator_ && |
| 380 browser_creator_->is_default_browser_dialog_suppressed())) && | 368 browser_creator_->is_default_browser_dialog_suppressed())) && |
| 381 !chrome::ShowAutolaunchPrompt(profile)) { | 369 !chrome::ShowAutolaunchPrompt(profile)) { |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 if (!profile_->DidLastSessionExitCleanly() && | 596 if (!profile_->DidLastSessionExitCleanly() && |
| 609 !command_line_.HasSwitch(switches::kRestoreLastSession)) { | 597 !command_line_.HasSwitch(switches::kRestoreLastSession)) { |
| 610 // The last session crashed. It's possible automatically loading the | 598 // The last session crashed. It's possible automatically loading the |
| 611 // page will trigger another crash, locking the user out of chrome. | 599 // page will trigger another crash, locking the user out of chrome. |
| 612 // To avoid this, don't restore on startup but instead show the crashed | 600 // To avoid this, don't restore on startup but instead show the crashed |
| 613 // infobar. | 601 // infobar. |
| 614 VLOG(1) << "Unclean exit; not processing"; | 602 VLOG(1) << "Unclean exit; not processing"; |
| 615 return false; | 603 return false; |
| 616 } | 604 } |
| 617 | 605 |
| 618 uint32 restore_behavior = SessionRestore::SYNCHRONOUS | | 606 uint32 restore_behavior = SessionRestore::SYNCHRONOUS; |
| 619 SessionRestore::ALWAYS_CREATE_TABBED_BROWSER; | 607 if (browser_defaults::kAlwaysCreateTabbedBrowserOnSessionRestore || |
| 608 CommandLine::ForCurrentProcess()->HasSwitch( |
| 609 switches::kCreateBrowserOnStartupForTests)) { |
| 610 restore_behavior |= SessionRestore::ALWAYS_CREATE_TABBED_BROWSER; |
| 611 } |
| 612 |
| 620 #if defined(OS_MACOSX) | 613 #if defined(OS_MACOSX) |
| 621 // On Mac, when restoring a session with no windows, suppress the creation | 614 // On Mac, when restoring a session with no windows, suppress the creation |
| 622 // of a new window in the case where the system is launching Chrome via a | 615 // of a new window in the case where the system is launching Chrome via a |
| 623 // login item or Lion's resume feature. | 616 // login item or Lion's resume feature. |
| 624 if (base::mac::WasLaunchedAsLoginOrResumeItem()) { | 617 if (base::mac::WasLaunchedAsLoginOrResumeItem()) { |
| 625 restore_behavior = restore_behavior & | 618 restore_behavior = restore_behavior & |
| 626 ~SessionRestore::ALWAYS_CREATE_TABBED_BROWSER; | 619 ~SessionRestore::ALWAYS_CREATE_TABBED_BROWSER; |
| 627 } | 620 } |
| 628 #endif | 621 #endif |
| 629 | 622 |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 // New: | 940 // New: |
| 948 prefs->GetString(prefs::kHomePage), | 941 prefs->GetString(prefs::kHomePage), |
| 949 prefs->GetBoolean(prefs::kHomePageIsNewTabPage), | 942 prefs->GetBoolean(prefs::kHomePageIsNewTabPage), |
| 950 prefs->GetBoolean(prefs::kShowHomeButton), | 943 prefs->GetBoolean(prefs::kShowHomeButton), |
| 951 // Backup: | 944 // Backup: |
| 952 backup_homepage, | 945 backup_homepage, |
| 953 backup_homepage_is_ntp, | 946 backup_homepage_is_ntp, |
| 954 backup_show_home_button)); | 947 backup_show_home_button)); |
| 955 } | 948 } |
| 956 } | 949 } |
| OLD | NEW |