Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "apps/app_restore_service.h" | 14 #include "apps/app_restore_service.h" |
| 15 #include "apps/app_restore_service_factory.h" | 15 #include "apps/app_restore_service_factory.h" |
| 16 #include "base/bind.h" | 16 #include "base/bind.h" |
| 17 #include "base/bind_helpers.h" | 17 #include "base/bind_helpers.h" |
| 18 #include "base/command_line.h" | 18 #include "base/command_line.h" |
| 19 #include "base/compiler_specific.h" | 19 #include "base/compiler_specific.h" |
| 20 #include "base/environment.h" | 20 #include "base/environment.h" |
| 21 #include "base/feature_list.h" | |
| 21 #include "base/lazy_instance.h" | 22 #include "base/lazy_instance.h" |
| 22 #include "base/metrics/histogram_macros.h" | 23 #include "base/metrics/histogram_macros.h" |
| 23 #include "base/metrics/statistics_recorder.h" | 24 #include "base/metrics/statistics_recorder.h" |
| 24 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
| 25 #include "base/strings/string_split.h" | 26 #include "base/strings/string_split.h" |
| 26 #include "base/strings/string_util.h" | 27 #include "base/strings/string_util.h" |
| 27 #include "base/strings/stringprintf.h" | 28 #include "base/strings/stringprintf.h" |
| 28 #include "base/strings/utf_string_conversions.h" | 29 #include "base/strings/utf_string_conversions.h" |
| 29 #include "base/threading/thread_restrictions.h" | 30 #include "base/threading/thread_restrictions.h" |
| 30 #include "build/build_config.h" | 31 #include "build/build_config.h" |
| 31 #include "chrome/browser/apps/install_chrome_app.h" | 32 #include "chrome/browser/apps/install_chrome_app.h" |
| 32 #include "chrome/browser/browser_process.h" | 33 #include "chrome/browser/browser_process.h" |
| 33 #include "chrome/browser/chrome_notification_types.h" | 34 #include "chrome/browser/chrome_notification_types.h" |
| 34 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 35 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 35 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | 36 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
| 36 #include "chrome/browser/defaults.h" | 37 #include "chrome/browser/defaults.h" |
| 37 #include "chrome/browser/extensions/extension_creator.h" | 38 #include "chrome/browser/extensions/extension_creator.h" |
| 38 #include "chrome/browser/extensions/extension_util.h" | 39 #include "chrome/browser/extensions/extension_util.h" |
| 39 #include "chrome/browser/extensions/launch_util.h" | 40 #include "chrome/browser/extensions/launch_util.h" |
| 40 #include "chrome/browser/extensions/pack_extension_job.h" | 41 #include "chrome/browser/extensions/pack_extension_job.h" |
| 41 #include "chrome/browser/first_run/first_run.h" | 42 #include "chrome/browser/first_run/first_run.h" |
| 43 #include "chrome/browser/first_run/first_run_features.h" | |
| 42 #include "chrome/browser/infobars/infobar_service.h" | 44 #include "chrome/browser/infobars/infobar_service.h" |
| 43 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 45 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 44 #include "chrome/browser/prefs/session_startup_pref.h" | 46 #include "chrome/browser/prefs/session_startup_pref.h" |
| 45 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h" | 47 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h" |
| 46 #include "chrome/browser/profile_resetter/triggered_profile_resetter_factory.h" | 48 #include "chrome/browser/profile_resetter/triggered_profile_resetter_factory.h" |
| 47 #include "chrome/browser/profiles/profile.h" | 49 #include "chrome/browser/profiles/profile.h" |
| 48 #include "chrome/browser/profiles/profile_io_data.h" | 50 #include "chrome/browser/profiles/profile_io_data.h" |
| 49 #include "chrome/browser/sessions/session_restore.h" | 51 #include "chrome/browser/sessions/session_restore.h" |
| 50 #include "chrome/browser/sessions/session_service.h" | 52 #include "chrome/browser/sessions/session_service.h" |
| 51 #include "chrome/browser/sessions/session_service_factory.h" | 53 #include "chrome/browser/sessions/session_service_factory.h" |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 WebContents* app_tab = ::OpenAppShortcutWindow(profile, url); | 494 WebContents* app_tab = ::OpenAppShortcutWindow(profile, url); |
| 493 return (app_tab != NULL); | 495 return (app_tab != NULL); |
| 494 } | 496 } |
| 495 } | 497 } |
| 496 return false; | 498 return false; |
| 497 } | 499 } |
| 498 | 500 |
| 499 void StartupBrowserCreatorImpl::ProcessLaunchURLs( | 501 void StartupBrowserCreatorImpl::ProcessLaunchURLs( |
| 500 bool process_startup, | 502 bool process_startup, |
| 501 const std::vector<GURL>& urls_to_open) { | 503 const std::vector<GURL>& urls_to_open) { |
| 504 if (base::FeatureList::IsEnabled(features::kUseConsolidatedFirstRun)) { | |
| 505 ProcessLaunchURLsUsingConsolidatedFlow(process_startup, urls_to_open); | |
| 506 return; | |
| 507 } | |
| 508 | |
| 502 // Don't open any browser windows if we're starting up in "background mode". | 509 // Don't open any browser windows if we're starting up in "background mode". |
| 503 if (process_startup && command_line_.HasSwitch(switches::kNoStartupWindow)) | 510 if (process_startup && command_line_.HasSwitch(switches::kNoStartupWindow)) |
| 504 return; | 511 return; |
| 505 | 512 |
| 506 // Determine whether or not this launch must include the welcome page. | 513 // Determine whether or not this launch must include the welcome page. |
| 507 InitializeWelcomeRunType(urls_to_open); | 514 InitializeWelcomeRunType(urls_to_open); |
| 508 | 515 |
| 509 // TODO(tapted): Move this to startup_browser_creator_win.cc after refactor. | |
| 510 #if defined(OS_WIN) | |
| 511 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { | |
| 512 // See if there are apps for this profile that should be launched on startup | |
| 513 // due to a switch from Metro mode. | |
| 514 app_metro_launch::HandleAppLaunchForMetroRestart(profile_); | |
| 515 } | |
| 516 #endif | |
| 517 | |
| 518 if (process_startup && ProcessStartupURLs(urls_to_open)) { | 516 if (process_startup && ProcessStartupURLs(urls_to_open)) { |
| 519 // ProcessStartupURLs processed the urls, nothing else to do. | 517 // ProcessStartupURLs processed the urls, nothing else to do. |
| 520 return; | 518 return; |
| 521 } | 519 } |
| 522 | 520 |
| 523 chrome::startup::IsProcessStartup is_process_startup = process_startup ? | 521 chrome::startup::IsProcessStartup is_process_startup = process_startup ? |
| 524 chrome::startup::IS_PROCESS_STARTUP : | 522 chrome::startup::IS_PROCESS_STARTUP : |
| 525 chrome::startup::IS_NOT_PROCESS_STARTUP; | 523 chrome::startup::IS_NOT_PROCESS_STARTUP; |
| 526 if (!process_startup) { | 524 if (!process_startup) { |
| 527 // Even if we're not starting a new process, this may conceptually be | 525 // Even if we're not starting a new process, this may conceptually be |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 559 // Always open a list of urls in a window on the native desktop. | 557 // Always open a list of urls in a window on the native desktop. |
| 560 browser = chrome::FindTabbedBrowser(profile_, false); | 558 browser = chrome::FindTabbedBrowser(profile_, false); |
| 561 } | 559 } |
| 562 // This will launch a browser; prevent session restore. | 560 // This will launch a browser; prevent session restore. |
| 563 StartupBrowserCreator::in_synchronous_profile_launch_ = true; | 561 StartupBrowserCreator::in_synchronous_profile_launch_ = true; |
| 564 browser = OpenURLsInBrowser(browser, process_startup, adjusted_urls); | 562 browser = OpenURLsInBrowser(browser, process_startup, adjusted_urls); |
| 565 StartupBrowserCreator::in_synchronous_profile_launch_ = false; | 563 StartupBrowserCreator::in_synchronous_profile_launch_ = false; |
| 566 AddInfoBarsIfNecessary(browser, is_process_startup); | 564 AddInfoBarsIfNecessary(browser, is_process_startup); |
| 567 } | 565 } |
| 568 | 566 |
| 567 void StartupBrowserCreatorImpl::ProcessLaunchURLsUsingConsolidatedFlow( | |
| 568 bool process_startup, | |
| 569 const std::vector<GURL>& urls_to_open) { | |
| 570 std::vector<GURL> adjusted_urls(urls_to_open); | |
| 571 | |
| 572 // Don't open any browser windows if we're starting up in "background mode". | |
| 573 if (process_startup && command_line_.HasSwitch(switches::kNoStartupWindow)) | |
| 574 return; | |
| 575 | |
| 576 // TODO(tapted): Move this to startup_browser_creator_win.cc after refactor. | |
|
grt (UTC plus 2)
2016/08/01 06:23:14
nuke this one, too?
| |
| 577 #if defined(OS_WIN) | |
| 578 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { | |
| 579 // See if there are apps for this profile that should be launched on startup | |
| 580 // due to a switch from Metro mode. | |
| 581 app_metro_launch::HandleAppLaunchForMetroRestart(profile_); | |
| 582 } | |
| 583 #endif | |
| 584 | |
| 585 // If Master Prefs contains any first run tabs, use only those. | |
| 586 std::vector<GURL> tabs_to_insert; | |
| 587 if (browser_creator_) { | |
| 588 tabs_to_insert = | |
| 589 first_run::ProcessMasterPrefsTabs(browser_creator_->first_run_tabs_); | |
| 590 browser_creator_->first_run_tabs_.clear(); | |
| 591 } | |
| 592 // Otherwise, use the standard Onboarding logic to determine which, if any, | |
| 593 // tabs need to be surfaced. | |
| 594 if (tabs_to_insert.empty()) { | |
| 595 tabs_to_insert = first_run::GetOnboardingTabs(); | |
| 596 } | |
| 597 | |
| 598 // If this profile is marked for a reset prompt, put this before all other | |
| 599 // tabs. | |
| 600 if (ProfileHasResetTrigger()) { | |
| 601 tabs_to_insert.insert(tabs_to_insert.begin(), | |
| 602 internals::GetTriggeredResetSettingsURL()); | |
| 603 } | |
| 604 | |
| 605 // TODO(tmartino): Function for processing pinned tabs. | |
| 606 | |
| 607 // Prepend the resulting list of tabs to those passed in. | |
| 608 if (!tabs_to_insert.empty()) { | |
| 609 adjusted_urls.insert(adjusted_urls.begin(), tabs_to_insert.begin(), | |
| 610 tabs_to_insert.end()); | |
| 611 } | |
| 612 | |
| 613 // TODO(tmartino): If this is not process startup, we need to restore | |
| 614 // asynchronously and return here. | |
| 615 | |
| 616 // See if we can or should restore an old session synchronously. | |
| 617 Browser* browser = MaybeRestoreSession(process_startup, adjusted_urls); | |
| 618 | |
| 619 // Otherwise, open. | |
| 620 if (!browser) { | |
| 621 browser = OpenURLsInBrowser(browser, process_startup, adjusted_urls); | |
| 622 } | |
| 623 | |
| 624 // Finally, add info bars. | |
| 625 chrome::startup::IsProcessStartup is_process_startup = | |
| 626 process_startup ? chrome::startup::IS_PROCESS_STARTUP | |
| 627 : chrome::startup::IS_NOT_PROCESS_STARTUP; | |
| 628 AddInfoBarsIfNecessary(browser, is_process_startup); | |
| 629 } | |
| 630 | |
| 631 Browser* StartupBrowserCreatorImpl::MaybeRestoreSession( | |
| 632 bool process_startup, | |
| 633 const std::vector<GURL>& urls) { | |
| 634 // TODO(tmartino): Move session restore logic into this function. | |
| 635 return NULL; | |
| 636 } | |
| 637 | |
| 569 bool StartupBrowserCreatorImpl::ProcessStartupURLs( | 638 bool StartupBrowserCreatorImpl::ProcessStartupURLs( |
| 570 const std::vector<GURL>& urls_to_open) { | 639 const std::vector<GURL>& urls_to_open) { |
| 571 VLOG(1) << "StartupBrowserCreatorImpl::ProcessStartupURLs"; | 640 VLOG(1) << "StartupBrowserCreatorImpl::ProcessStartupURLs"; |
| 572 SessionStartupPref pref = | 641 SessionStartupPref pref = |
| 573 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_); | 642 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_); |
| 574 if (pref.type == SessionStartupPref::LAST) | 643 if (pref.type == SessionStartupPref::LAST) |
| 575 VLOG(1) << "Pref: last"; | 644 VLOG(1) << "Pref: last"; |
| 576 else if (pref.type == SessionStartupPref::URLS) | 645 else if (pref.type == SessionStartupPref::URLS) |
| 577 VLOG(1) << "Pref: urls"; | 646 VLOG(1) << "Pref: urls"; |
| 578 else if (pref.type == SessionStartupPref::DEFAULT) | 647 else if (pref.type == SessionStartupPref::DEFAULT) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 641 !HasPendingUncleanExit(profile_)) { | 710 !HasPendingUncleanExit(profile_)) { |
| 642 content::BrowserContext::GetDefaultStoragePartition(profile_)-> | 711 content::BrowserContext::GetDefaultStoragePartition(profile_)-> |
| 643 GetDOMStorageContext()->StartScavengingUnusedSessionStorage(); | 712 GetDOMStorageContext()->StartScavengingUnusedSessionStorage(); |
| 644 } | 713 } |
| 645 | 714 |
| 646 return true; | 715 return true; |
| 647 } | 716 } |
| 648 | 717 |
| 649 Browser* StartupBrowserCreatorImpl::ProcessSpecifiedURLs( | 718 Browser* StartupBrowserCreatorImpl::ProcessSpecifiedURLs( |
| 650 const std::vector<GURL>& urls_to_open) { | 719 const std::vector<GURL>& urls_to_open) { |
| 720 // TODO(tmartino): Deprecated, remove this once UseConsolidatedFirstRun is | |
| 721 // enabled. | |
| 722 | |
| 651 SessionStartupPref pref = | 723 SessionStartupPref pref = |
| 652 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_); | 724 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_); |
| 653 StartupTabs tabs; | 725 StartupTabs tabs; |
| 654 // Pinned tabs should not be displayed when chrome is launched in incognito | 726 // Pinned tabs should not be displayed when chrome is launched in incognito |
| 655 // mode. Also, no pages should be opened automatically if the session | 727 // mode. Also, no pages should be opened automatically if the session |
| 656 // crashed. Otherwise it might trigger another crash, locking the user out of | 728 // crashed. Otherwise it might trigger another crash, locking the user out of |
| 657 // chrome. The crash infobar is shown in this case. | 729 // chrome. The crash infobar is shown in this case. |
| 658 if (!IncognitoModePrefs::ShouldLaunchIncognito(command_line_, | 730 if (!IncognitoModePrefs::ShouldLaunchIncognito(command_line_, |
| 659 profile_->GetPrefs()) && | 731 profile_->GetPrefs()) && |
| 660 !HasPendingUncleanExit(profile_)) { | 732 !HasPendingUncleanExit(profile_)) { |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 819 browser_creator_->is_default_browser_dialog_suppressed())) { | 891 browser_creator_->is_default_browser_dialog_suppressed())) { |
| 820 chrome::ShowDefaultBrowserPrompt(profile_); | 892 chrome::ShowDefaultBrowserPrompt(profile_); |
| 821 } | 893 } |
| 822 } | 894 } |
| 823 #endif | 895 #endif |
| 824 } | 896 } |
| 825 } | 897 } |
| 826 | 898 |
| 827 void StartupBrowserCreatorImpl::AddStartupURLs( | 899 void StartupBrowserCreatorImpl::AddStartupURLs( |
| 828 std::vector<GURL>* startup_urls) const { | 900 std::vector<GURL>* startup_urls) const { |
| 829 // TODO(atwilson): Simplify the logic that decides which tabs to open on | 901 // TODO(tmartino): Deprecated, remove this once UseConsolidatedFirstRun is |
| 830 // start-up and make it more consistent. http://crbug.com/248883 | 902 // enabled. |
| 831 | 903 |
| 832 // If we have urls specified by the first run master preferences use them | 904 // If we have urls specified by the first run master preferences use them |
| 833 // and nothing else. | 905 // and nothing else. |
| 834 if (browser_creator_ && startup_urls->empty()) { | 906 if (browser_creator_ && startup_urls->empty()) { |
| 835 if (!browser_creator_->first_run_tabs_.empty()) { | 907 if (!browser_creator_->first_run_tabs_.empty()) { |
| 836 std::vector<GURL>::iterator it = | 908 std::vector<GURL>::iterator it = |
| 837 browser_creator_->first_run_tabs_.begin(); | 909 browser_creator_->first_run_tabs_.begin(); |
| 838 while (it != browser_creator_->first_run_tabs_.end()) { | 910 while (it != browser_creator_->first_run_tabs_.end()) { |
| 839 // Replace magic names for the actual urls. | 911 // Replace magic names for the actual urls. |
| 840 if (it->host() == "new_tab_page") { | 912 if (it->host() == "new_tab_page") { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 886 startup_urls->at(0) == GURL(chrome::kChromeUINewTabURL)) | 958 startup_urls->at(0) == GURL(chrome::kChromeUINewTabURL)) |
| 887 startup_urls->at(0) = sync_promo_url; | 959 startup_urls->at(0) = sync_promo_url; |
| 888 else | 960 else |
| 889 startup_urls->insert(startup_urls->begin(), sync_promo_url); | 961 startup_urls->insert(startup_urls->begin(), sync_promo_url); |
| 890 } | 962 } |
| 891 } | 963 } |
| 892 } | 964 } |
| 893 | 965 |
| 894 void StartupBrowserCreatorImpl::AddSpecialURLs( | 966 void StartupBrowserCreatorImpl::AddSpecialURLs( |
| 895 std::vector<GURL>* url_list) const { | 967 std::vector<GURL>* url_list) const { |
| 968 // TODO(tmartino): Deprecated, remove this once UseConsolidatedFirstRun is | |
| 969 // enabled. | |
| 970 | |
| 896 // Optionally include the welcome page. | 971 // Optionally include the welcome page. |
| 897 if (welcome_run_type_ == WelcomeRunType::FIRST_TAB) | 972 if (welcome_run_type_ == WelcomeRunType::FIRST_TAB) |
| 898 url_list->insert(url_list->begin(), internals::GetWelcomePageURL()); | 973 url_list->insert(url_list->begin(), internals::GetWelcomePageURL()); |
| 899 | 974 |
| 900 // If this Profile is marked for a reset prompt, ensure the reset | 975 // If this Profile is marked for a reset prompt, ensure the reset |
| 901 // settings dialog appears. | 976 // settings dialog appears. |
| 902 if (ProfileHasResetTrigger()) { | 977 if (ProfileHasResetTrigger()) { |
| 903 url_list->insert(url_list->begin(), | 978 url_list->insert(url_list->begin(), |
| 904 internals::GetTriggeredResetSettingsURL()); | 979 internals::GetTriggeredResetSettingsURL()); |
| 905 } | 980 } |
| 906 } | 981 } |
| 907 | 982 |
| 908 // For first-run, the type will be FIRST_RUN_LAST for all systems except for | 983 // For first-run, the type will be FIRST_RUN_LAST for all systems except for |
| 909 // Windows 10+, where it will be FIRST_RUN_FIRST. For non-first run, the type | 984 // Windows 10+, where it will be FIRST_RUN_FIRST. For non-first run, the type |
| 910 // will be NONE for all systems except for Windows 10+, where it will be | 985 // will be NONE for all systems except for Windows 10+, where it will be |
| 911 // ANY_RUN_FIRST if this is the first somewhat normal launch since an OS | 986 // ANY_RUN_FIRST if this is the first somewhat normal launch since an OS |
| 912 // upgrade. | 987 // upgrade. |
| 988 | |
| 989 // TODO(tmartino): Deprecated, remove this once UseConsolidatedFirstRun is | |
| 990 // enabled. | |
| 913 void StartupBrowserCreatorImpl::InitializeWelcomeRunType( | 991 void StartupBrowserCreatorImpl::InitializeWelcomeRunType( |
| 914 const std::vector<GURL>& urls_to_open) { | 992 const std::vector<GURL>& urls_to_open) { |
| 915 DCHECK_EQ(static_cast<int>(WelcomeRunType::NONE), | 993 DCHECK_EQ(static_cast<int>(WelcomeRunType::NONE), |
| 916 static_cast<int>(welcome_run_type_)); | 994 static_cast<int>(welcome_run_type_)); |
| 917 #if defined(OS_WIN) | 995 #if defined(OS_WIN) |
| 918 // Do not welcome if there are any URLs to open. | 996 // Do not welcome if there are any URLs to open. |
| 919 if (!urls_to_open.empty()) | 997 if (!urls_to_open.empty()) |
| 920 return; | 998 return; |
| 921 | 999 |
| 922 base::win::OSInfo* const os_info = base::win::OSInfo::GetInstance(); | 1000 base::win::OSInfo* const os_info = base::win::OSInfo::GetInstance(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 989 #if defined(OS_WIN) | 1067 #if defined(OS_WIN) |
| 990 TriggeredProfileResetter* triggered_profile_resetter = | 1068 TriggeredProfileResetter* triggered_profile_resetter = |
| 991 TriggeredProfileResetterFactory::GetForBrowserContext(profile_); | 1069 TriggeredProfileResetterFactory::GetForBrowserContext(profile_); |
| 992 // TriggeredProfileResetter instance will be nullptr for incognito profiles. | 1070 // TriggeredProfileResetter instance will be nullptr for incognito profiles. |
| 993 if (triggered_profile_resetter) { | 1071 if (triggered_profile_resetter) { |
| 994 has_reset_trigger = triggered_profile_resetter->HasResetTrigger(); | 1072 has_reset_trigger = triggered_profile_resetter->HasResetTrigger(); |
| 995 } | 1073 } |
| 996 #endif // defined(OS_WIN) | 1074 #endif // defined(OS_WIN) |
| 997 return has_reset_trigger; | 1075 return has_reset_trigger; |
| 998 } | 1076 } |
| OLD | NEW |