| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "apps/app_restore_service.h" | 10 #include "apps/app_restore_service.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | 33 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
| 34 #include "chrome/browser/defaults.h" | 34 #include "chrome/browser/defaults.h" |
| 35 #include "chrome/browser/extensions/extension_creator.h" | 35 #include "chrome/browser/extensions/extension_creator.h" |
| 36 #include "chrome/browser/extensions/extension_util.h" | 36 #include "chrome/browser/extensions/extension_util.h" |
| 37 #include "chrome/browser/extensions/launch_util.h" | 37 #include "chrome/browser/extensions/launch_util.h" |
| 38 #include "chrome/browser/extensions/pack_extension_job.h" | 38 #include "chrome/browser/extensions/pack_extension_job.h" |
| 39 #include "chrome/browser/first_run/first_run.h" | 39 #include "chrome/browser/first_run/first_run.h" |
| 40 #include "chrome/browser/infobars/infobar_service.h" | 40 #include "chrome/browser/infobars/infobar_service.h" |
| 41 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 41 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 42 #include "chrome/browser/prefs/session_startup_pref.h" | 42 #include "chrome/browser/prefs/session_startup_pref.h" |
| 43 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h" |
| 44 #include "chrome/browser/profile_resetter/triggered_profile_resetter_factory.h" |
| 43 #include "chrome/browser/profiles/profile.h" | 45 #include "chrome/browser/profiles/profile.h" |
| 44 #include "chrome/browser/profiles/profile_io_data.h" | 46 #include "chrome/browser/profiles/profile_io_data.h" |
| 45 #include "chrome/browser/sessions/session_restore.h" | 47 #include "chrome/browser/sessions/session_restore.h" |
| 46 #include "chrome/browser/sessions/session_service.h" | 48 #include "chrome/browser/sessions/session_service.h" |
| 47 #include "chrome/browser/sessions/session_service_factory.h" | 49 #include "chrome/browser/sessions/session_service_factory.h" |
| 48 #include "chrome/browser/shell_integration.h" | 50 #include "chrome/browser/shell_integration.h" |
| 49 #include "chrome/browser/signin/signin_promo.h" | 51 #include "chrome/browser/signin/signin_promo.h" |
| 50 #include "chrome/browser/ui/app_list/app_list_service.h" | 52 #include "chrome/browser/ui/app_list/app_list_service.h" |
| 51 #include "chrome/browser/ui/browser_commands.h" | 53 #include "chrome/browser/ui/browser_commands.h" |
| 52 #include "chrome/browser/ui/browser_finder.h" | 54 #include "chrome/browser/ui/browser_finder.h" |
| 53 #include "chrome/browser/ui/browser_list.h" | 55 #include "chrome/browser/ui/browser_list.h" |
| 54 #include "chrome/browser/ui/browser_navigator.h" | 56 #include "chrome/browser/ui/browser_navigator.h" |
| 55 #include "chrome/browser/ui/browser_tabrestore.h" | 57 #include "chrome/browser/ui/browser_tabrestore.h" |
| 56 #include "chrome/browser/ui/browser_tabstrip.h" | 58 #include "chrome/browser/ui/browser_tabstrip.h" |
| 57 #include "chrome/browser/ui/browser_window.h" | 59 #include "chrome/browser/ui/browser_window.h" |
| 60 #include "chrome/browser/ui/chrome_pages.h" |
| 58 #include "chrome/browser/ui/extensions/app_launch_params.h" | 61 #include "chrome/browser/ui/extensions/app_launch_params.h" |
| 59 #include "chrome/browser/ui/extensions/application_launch.h" | 62 #include "chrome/browser/ui/extensions/application_launch.h" |
| 60 #include "chrome/browser/ui/host_desktop.h" | 63 #include "chrome/browser/ui/host_desktop.h" |
| 61 #include "chrome/browser/ui/startup/autolaunch_prompt.h" | 64 #include "chrome/browser/ui/startup/autolaunch_prompt.h" |
| 62 #include "chrome/browser/ui/startup/bad_flags_prompt.h" | 65 #include "chrome/browser/ui/startup/bad_flags_prompt.h" |
| 63 #include "chrome/browser/ui/startup/default_browser_prompt.h" | 66 #include "chrome/browser/ui/startup/default_browser_prompt.h" |
| 64 #include "chrome/browser/ui/startup/google_api_keys_infobar_delegate.h" | 67 #include "chrome/browser/ui/startup/google_api_keys_infobar_delegate.h" |
| 65 #include "chrome/browser/ui/startup/obsolete_system_infobar_delegate.h" | 68 #include "chrome/browser/ui/startup/obsolete_system_infobar_delegate.h" |
| 66 #include "chrome/browser/ui/startup/session_crashed_infobar_delegate.h" | 69 #include "chrome/browser/ui/startup/session_crashed_infobar_delegate.h" |
| 67 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 70 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 const Extension* extension = | 251 const Extension* extension = |
| 249 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( | 252 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
| 250 extension_id, extensions::ExtensionRegistry::EVERYTHING); | 253 extension_id, extensions::ExtensionRegistry::EVERYTHING); |
| 251 return extension && extension->is_platform_app() ? extension : NULL; | 254 return extension && extension->is_platform_app() ? extension : NULL; |
| 252 } | 255 } |
| 253 | 256 |
| 254 } // namespace | 257 } // namespace |
| 255 | 258 |
| 256 namespace internals { | 259 namespace internals { |
| 257 | 260 |
| 261 GURL GetResetSettingsURL() { |
| 262 return GURL(chrome::GetSettingsUrl(chrome::kResetProfileSettingsSubPage)); |
| 263 } |
| 264 |
| 258 GURL GetWelcomePageURL() { | 265 GURL GetWelcomePageURL() { |
| 259 std::string welcome_url = l10n_util::GetStringUTF8(IDS_WELCOME_PAGE_URL); | 266 return GURL(l10n_util::GetStringUTF8(IDS_WELCOME_PAGE_URL)); |
| 260 return GURL(welcome_url); | |
| 261 } | 267 } |
| 262 | 268 |
| 263 } // namespace internals | 269 } // namespace internals |
| 264 | 270 |
| 265 StartupBrowserCreatorImpl::StartupBrowserCreatorImpl( | 271 StartupBrowserCreatorImpl::StartupBrowserCreatorImpl( |
| 266 const base::FilePath& cur_dir, | 272 const base::FilePath& cur_dir, |
| 267 const base::CommandLine& command_line, | 273 const base::CommandLine& command_line, |
| 268 chrome::startup::IsFirstRun is_first_run) | 274 chrome::startup::IsFirstRun is_first_run) |
| 269 : cur_dir_(cur_dir), | 275 : cur_dir_(cur_dir), |
| 270 command_line_(command_line), | 276 command_line_(command_line), |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 // Chrome may have been running in the background due to an app with a | 529 // Chrome may have been running in the background due to an app with a |
| 524 // background page being installed, or running with only an app window | 530 // background page being installed, or running with only an app window |
| 525 // displayed. | 531 // displayed. |
| 526 SessionService* service = | 532 SessionService* service = |
| 527 SessionServiceFactory::GetForProfileForSessionRestore(profile_); | 533 SessionServiceFactory::GetForProfileForSessionRestore(profile_); |
| 528 if (service && service->ShouldNewWindowStartSession()) { | 534 if (service && service->ShouldNewWindowStartSession()) { |
| 529 // Restore the last session if any, optionally including the welcome page | 535 // Restore the last session if any, optionally including the welcome page |
| 530 // if desired. | 536 // if desired. |
| 531 if (!HasPendingUncleanExit(profile_)) { | 537 if (!HasPendingUncleanExit(profile_)) { |
| 532 std::vector<GURL> adjusted_urls(urls_to_open); | 538 std::vector<GURL> adjusted_urls(urls_to_open); |
| 533 if (welcome_run_type_ == WelcomeRunType::FIRST_TAB) { | 539 AddSpecialURLs(&adjusted_urls); |
| 534 adjusted_urls.insert(adjusted_urls.begin(), | |
| 535 internals::GetWelcomePageURL()); | |
| 536 } | |
| 537 if (service->RestoreIfNecessary(adjusted_urls)) | 540 if (service->RestoreIfNecessary(adjusted_urls)) |
| 538 return; | 541 return; |
| 539 } | 542 } |
| 540 | 543 |
| 541 // Open user-specified URLs like pinned tabs and startup tabs. | 544 // Open user-specified URLs like pinned tabs and startup tabs. |
| 542 Browser* browser = ProcessSpecifiedURLs(urls_to_open, desktop_type); | 545 Browser* browser = ProcessSpecifiedURLs(urls_to_open, desktop_type); |
| 543 if (browser) { | 546 if (browser) { |
| 544 AddInfoBarsIfNecessary(browser, is_process_startup); | 547 AddInfoBarsIfNecessary(browser, is_process_startup); |
| 545 return; | 548 return; |
| 546 } | 549 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 #if defined(OS_MACOSX) | 610 #if defined(OS_MACOSX) |
| 608 // On Mac, when restoring a session with no windows, suppress the creation | 611 // On Mac, when restoring a session with no windows, suppress the creation |
| 609 // of a new window in the case where the system is launching Chrome via a | 612 // of a new window in the case where the system is launching Chrome via a |
| 610 // login item or Lion's resume feature. | 613 // login item or Lion's resume feature. |
| 611 if (base::mac::WasLaunchedAsLoginOrResumeItem()) { | 614 if (base::mac::WasLaunchedAsLoginOrResumeItem()) { |
| 612 restore_behavior = restore_behavior & | 615 restore_behavior = restore_behavior & |
| 613 ~SessionRestore::ALWAYS_CREATE_TABBED_BROWSER; | 616 ~SessionRestore::ALWAYS_CREATE_TABBED_BROWSER; |
| 614 } | 617 } |
| 615 #endif | 618 #endif |
| 616 | 619 |
| 617 // Optionally include the welcome page. | |
| 618 std::vector<GURL> adjusted_urls(urls_to_open); | 620 std::vector<GURL> adjusted_urls(urls_to_open); |
| 619 if (welcome_run_type_ == WelcomeRunType::FIRST_TAB) { | 621 AddSpecialURLs(&adjusted_urls); |
| 620 adjusted_urls.insert(adjusted_urls.begin(), | |
| 621 internals::GetWelcomePageURL()); | |
| 622 } | |
| 623 | 622 |
| 624 // The startup code only executes for browsers launched in desktop mode. | 623 // The startup code only executes for browsers launched in desktop mode. |
| 625 // i.e. HOST_DESKTOP_TYPE_NATIVE. Ash should never get here. | 624 // i.e. HOST_DESKTOP_TYPE_NATIVE. Ash should never get here. |
| 626 Browser* browser = SessionRestore::RestoreSession( | 625 Browser* browser = SessionRestore::RestoreSession( |
| 627 profile_, NULL, desktop_type, restore_behavior, adjusted_urls); | 626 profile_, NULL, desktop_type, restore_behavior, adjusted_urls); |
| 628 | 627 |
| 629 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP); | 628 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP); |
| 630 return true; | 629 return true; |
| 631 } | 630 } |
| 632 | 631 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 // If urls were specified on the command line, use them. | 669 // If urls were specified on the command line, use them. |
| 671 UrlsToTabs(urls_to_open, &tabs); | 670 UrlsToTabs(urls_to_open, &tabs); |
| 672 } else if (pref.type == SessionStartupPref::DEFAULT || | 671 } else if (pref.type == SessionStartupPref::DEFAULT || |
| 673 (is_first_run_ && | 672 (is_first_run_ && |
| 674 browser_creator_ && !browser_creator_->first_run_tabs_.empty())) { | 673 browser_creator_ && !browser_creator_->first_run_tabs_.empty())) { |
| 675 std::vector<GURL> urls; | 674 std::vector<GURL> urls; |
| 676 AddStartupURLs(&urls); | 675 AddStartupURLs(&urls); |
| 677 UrlsToTabs(urls, &tabs); | 676 UrlsToTabs(urls, &tabs); |
| 678 } else if (pref.type == SessionStartupPref::URLS && !pref.urls.empty() && | 677 } else if (pref.type == SessionStartupPref::URLS && !pref.urls.empty() && |
| 679 !HasPendingUncleanExit(profile_)) { | 678 !HasPendingUncleanExit(profile_)) { |
| 680 // Optionally include the welcome page first. | 679 std::vector<GURL> extra_urls; |
| 681 if (welcome_run_type_ == WelcomeRunType::FIRST_TAB) | 680 AddSpecialURLs(&extra_urls); |
| 682 UrlsToTabs(std::vector<GURL>(1, internals::GetWelcomePageURL()), &tabs); | 681 UrlsToTabs(extra_urls, &tabs); |
| 682 |
| 683 // Only use the set of urls specified in preferences if nothing was | 683 // Only use the set of urls specified in preferences if nothing was |
| 684 // specified on the command line. Filter out any urls that are to be | 684 // specified on the command line. Filter out any urls that are to be |
| 685 // restored by virtue of having been previously pinned. | 685 // restored by virtue of having been previously pinned. |
| 686 AddUniqueURLs(pref.urls, &tabs); | 686 AddUniqueURLs(pref.urls, &tabs); |
| 687 } else if (pref.type == SessionStartupPref::HOMEPAGE) { | 687 } else if (pref.type == SessionStartupPref::HOMEPAGE) { |
| 688 // If 'homepage' selected, either by the user or by a policy, we should | 688 // If 'homepage' selected, either by the user or by a policy, we should |
| 689 // have migrated them to another value. | 689 // have migrated them to another value. |
| 690 NOTREACHED() << "SessionStartupPref has deprecated type HOMEPAGE"; | 690 NOTREACHED() << "SessionStartupPref has deprecated type HOMEPAGE"; |
| 691 } | 691 } |
| 692 | 692 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 startup_urls->push_back(internals::GetWelcomePageURL()); | 854 startup_urls->push_back(internals::GetWelcomePageURL()); |
| 855 } else { | 855 } else { |
| 856 startup_urls->push_back(*it); | 856 startup_urls->push_back(*it); |
| 857 } | 857 } |
| 858 ++it; | 858 ++it; |
| 859 } | 859 } |
| 860 browser_creator_->first_run_tabs_.clear(); | 860 browser_creator_->first_run_tabs_.clear(); |
| 861 } | 861 } |
| 862 } | 862 } |
| 863 | 863 |
| 864 // Otherwise open at least the new tab page (and optionally the welcome page | 864 // Otherwise open at least the new tab page (and any pages deemed needed by |
| 865 // at the front or back as indicated by welcome_run_type_), or the set of URLs | 865 // AddSpecialURLs()), or the set of URLs specified on the command line. |
| 866 // specified on the command line. | |
| 867 if (startup_urls->empty()) { | 866 if (startup_urls->empty()) { |
| 868 if (welcome_run_type_ == WelcomeRunType::FIRST_TAB) | 867 AddSpecialURLs(startup_urls); |
| 869 startup_urls->push_back(internals::GetWelcomePageURL()); | |
| 870 startup_urls->push_back(GURL(chrome::kChromeUINewTabURL)); | 868 startup_urls->push_back(GURL(chrome::kChromeUINewTabURL)); |
| 869 |
| 870 // Special case the FIRST_RUN_LAST_TAB case of the welcome page. |
| 871 if (welcome_run_type_ == WelcomeRunType::FIRST_RUN_LAST_TAB) | 871 if (welcome_run_type_ == WelcomeRunType::FIRST_RUN_LAST_TAB) |
| 872 startup_urls->push_back(internals::GetWelcomePageURL()); | 872 startup_urls->push_back(internals::GetWelcomePageURL()); |
| 873 } | 873 } |
| 874 | 874 |
| 875 if (signin::ShouldShowPromoAtStartup(profile_, is_first_run_)) { | 875 if (signin::ShouldShowPromoAtStartup(profile_, is_first_run_)) { |
| 876 signin::DidShowPromoAtStartup(profile_); | 876 signin::DidShowPromoAtStartup(profile_); |
| 877 | 877 |
| 878 const GURL sync_promo_url = signin::GetPromoURL( | 878 const GURL sync_promo_url = signin::GetPromoURL( |
| 879 signin_metrics::SOURCE_START_PAGE, false); | 879 signin_metrics::SOURCE_START_PAGE, false); |
| 880 | 880 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 894 // causes a redirect to the NTP. | 894 // causes a redirect to the NTP. |
| 895 if (!startup_urls->empty() && | 895 if (!startup_urls->empty() && |
| 896 startup_urls->at(0) == GURL(chrome::kChromeUINewTabURL)) | 896 startup_urls->at(0) == GURL(chrome::kChromeUINewTabURL)) |
| 897 startup_urls->at(0) = sync_promo_url; | 897 startup_urls->at(0) = sync_promo_url; |
| 898 else | 898 else |
| 899 startup_urls->insert(startup_urls->begin(), sync_promo_url); | 899 startup_urls->insert(startup_urls->begin(), sync_promo_url); |
| 900 } | 900 } |
| 901 } | 901 } |
| 902 } | 902 } |
| 903 | 903 |
| 904 void StartupBrowserCreatorImpl::AddSpecialURLs( |
| 905 std::vector<GURL>* url_list) const { |
| 906 // Optionally include the welcome page. |
| 907 if (welcome_run_type_ == WelcomeRunType::FIRST_TAB) |
| 908 url_list->insert(url_list->begin(), internals::GetWelcomePageURL()); |
| 909 |
| 910 // If this Profile is marked for a reset prompt, ensure the reset |
| 911 // settings dialog appears. |
| 912 if (CheckAndClearProfileResetTrigger()) |
| 913 url_list->insert(url_list->begin(), internals::GetResetSettingsURL()); |
| 914 } |
| 915 |
| 904 // For first-run, the type will be FIRST_RUN_LAST for all systems except for | 916 // For first-run, the type will be FIRST_RUN_LAST for all systems except for |
| 905 // Windows 10+, where it will be FIRST_RUN_FIRST. For non-first run, the type | 917 // Windows 10+, where it will be FIRST_RUN_FIRST. For non-first run, the type |
| 906 // will be NONE for all systems except for Windows 10+, where it will be | 918 // will be NONE for all systems except for Windows 10+, where it will be |
| 907 // ANY_RUN_FIRST if this is the first somewhat normal launch since an OS | 919 // ANY_RUN_FIRST if this is the first somewhat normal launch since an OS |
| 908 // upgrade. | 920 // upgrade. |
| 909 void StartupBrowserCreatorImpl::InitializeWelcomeRunType( | 921 void StartupBrowserCreatorImpl::InitializeWelcomeRunType( |
| 910 const std::vector<GURL>& urls_to_open) { | 922 const std::vector<GURL>& urls_to_open) { |
| 911 DCHECK_EQ(static_cast<int>(WelcomeRunType::NONE), | 923 DCHECK_EQ(static_cast<int>(WelcomeRunType::NONE), |
| 912 static_cast<int>(welcome_run_type_)); | 924 static_cast<int>(welcome_run_type_)); |
| 913 #if defined(OS_WIN) | 925 #if defined(OS_WIN) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 #endif // !OS_WIN | 984 #endif // !OS_WIN |
| 973 } | 985 } |
| 974 | 986 |
| 975 void StartupBrowserCreatorImpl::RecordRapporOnStartupURLs( | 987 void StartupBrowserCreatorImpl::RecordRapporOnStartupURLs( |
| 976 const std::vector<GURL>& urls_to_open) { | 988 const std::vector<GURL>& urls_to_open) { |
| 977 for (const GURL& url : urls_to_open) { | 989 for (const GURL& url : urls_to_open) { |
| 978 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), | 990 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), |
| 979 "Startup.BrowserLaunchURL", url); | 991 "Startup.BrowserLaunchURL", url); |
| 980 } | 992 } |
| 981 } | 993 } |
| 994 |
| 995 bool StartupBrowserCreatorImpl::CheckAndClearProfileResetTrigger() const { |
| 996 bool has_reset_trigger = false; |
| 997 #if defined(OS_WIN) |
| 998 TriggeredProfileResetter* triggered_profile_resetter = |
| 999 TriggeredProfileResetterFactory::GetForBrowserContext(profile_); |
| 1000 // TriggeredProfileResetter instance will be nullptr for incognito profiles. |
| 1001 if (triggered_profile_resetter) { |
| 1002 has_reset_trigger = triggered_profile_resetter->HasResetTrigger(); |
| 1003 triggered_profile_resetter->ClearResetTrigger(); |
| 1004 } |
| 1005 #endif // defined(OS_WIN) |
| 1006 return has_reset_trigger; |
| 1007 } |
| OLD | NEW |