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 !first_run::IsWin10()) { | |
|
grt (UTC plus 2)
2016/07/29 06:56:15
i don't think "IsWin10" should be a public method
| |
| 506 ProcessLaunchURLsUsingConsolidatedFlow(process_startup, urls_to_open); | |
| 507 return; | |
| 508 } | |
| 509 | |
| 502 // Don't open any browser windows if we're starting up in "background mode". | 510 // Don't open any browser windows if we're starting up in "background mode". |
| 503 if (process_startup && command_line_.HasSwitch(switches::kNoStartupWindow)) | 511 if (process_startup && command_line_.HasSwitch(switches::kNoStartupWindow)) |
| 504 return; | 512 return; |
| 505 | 513 |
| 506 // Determine whether or not this launch must include the welcome page. | 514 // Determine whether or not this launch must include the welcome page. |
| 507 InitializeWelcomeRunType(urls_to_open); | 515 InitializeWelcomeRunType(urls_to_open); |
| 508 | 516 |
| 509 // TODO(tapted): Move this to startup_browser_creator_win.cc after refactor. | 517 // TODO(tapted): Move this to startup_browser_creator_win.cc after refactor. |
| 510 #if defined(OS_WIN) | 518 #if defined(OS_WIN) |
| 511 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { | 519 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
| (...skipping 47 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. | 567 // Always open a list of urls in a window on the native desktop. |
| 560 browser = chrome::FindTabbedBrowser(profile_, false); | 568 browser = chrome::FindTabbedBrowser(profile_, false); |
| 561 } | 569 } |
| 562 // This will launch a browser; prevent session restore. | 570 // This will launch a browser; prevent session restore. |
| 563 StartupBrowserCreator::in_synchronous_profile_launch_ = true; | 571 StartupBrowserCreator::in_synchronous_profile_launch_ = true; |
| 564 browser = OpenURLsInBrowser(browser, process_startup, adjusted_urls); | 572 browser = OpenURLsInBrowser(browser, process_startup, adjusted_urls); |
| 565 StartupBrowserCreator::in_synchronous_profile_launch_ = false; | 573 StartupBrowserCreator::in_synchronous_profile_launch_ = false; |
| 566 AddInfoBarsIfNecessary(browser, is_process_startup); | 574 AddInfoBarsIfNecessary(browser, is_process_startup); |
| 567 } | 575 } |
| 568 | 576 |
| 577 void StartupBrowserCreatorImpl::ProcessLaunchURLsUsingConsolidatedFlow( | |
| 578 bool process_startup, | |
| 579 const std::vector<GURL>& urls_to_open) { | |
| 580 std::vector<GURL> adjusted_urls(urls_to_open); | |
| 581 | |
| 582 // Don't open any browser windows if we're starting up in "background mode". | |
| 583 if (process_startup && command_line_.HasSwitch(switches::kNoStartupWindow)) | |
| 584 return; | |
| 585 | |
| 586 // TODO(tapted): Move this to startup_browser_creator_win.cc after refactor. | |
| 587 #if defined(OS_WIN) | |
| 588 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { | |
| 589 // See if there are apps for this profile that should be launched on startup | |
| 590 // due to a switch from Metro mode. | |
| 591 app_metro_launch::HandleAppLaunchForMetroRestart(profile_); | |
|
grt (UTC plus 2)
2016/07/29 06:56:15
metro mode is gone. i don't think this dead code n
| |
| 592 } | |
| 593 #endif | |
| 594 | |
| 595 // If Master Prefs contains any first run tabs, use only those. | |
| 596 std::vector<GURL> tabs_to_insert; | |
| 597 if (browser_creator_) { | |
| 598 tabs_to_insert = | |
| 599 first_run::ProcessMasterPrefsTabs(browser_creator_->first_run_tabs_); | |
| 600 browser_creator_->first_run_tabs_.clear(); | |
| 601 } | |
| 602 // Otherwise, use the standard Onboarding logic to determine which, if any, | |
| 603 // tabs need to be surfaced. | |
| 604 if (tabs_to_insert.empty()) { | |
| 605 tabs_to_insert = first_run::GetOnboardingTabs(); | |
| 606 } | |
| 607 | |
| 608 // If this profile is marked for a reset prompt, put this before all other | |
| 609 // tabs. | |
| 610 if (ProfileHasResetTrigger()) { | |
| 611 tabs_to_insert.insert(tabs_to_insert.begin(), | |
| 612 internals::GetTriggeredResetSettingsURL()); | |
| 613 } | |
| 614 | |
| 615 // TODO(tmartino): Function for processing pinned tabs. | |
| 616 | |
| 617 // Prepend the resulting list of tabs to those passed in. | |
| 618 if (!tabs_to_insert.empty()) { | |
| 619 adjusted_urls.insert(adjusted_urls.begin(), tabs_to_insert.begin(), | |
| 620 tabs_to_insert.end()); | |
| 621 } | |
| 622 | |
| 623 // TODO(tmartino): If this is not process startup, we need to restore | |
| 624 // asynchronously and return here. | |
| 625 | |
| 626 // See if we can or should restore an old session synchronously. | |
| 627 Browser* browser = MaybeRestoreSession(adjusted_urls, process_startup); | |
|
grt (UTC plus 2)
2016/07/29 06:56:15
this is mixing policy with functionality. can you
| |
| 628 | |
| 629 // Otherwise, open. | |
| 630 if (!browser) { | |
| 631 browser = OpenURLsInBrowser(browser, process_startup, adjusted_urls); | |
| 632 } | |
| 633 | |
| 634 // Finally, add info bars. | |
| 635 chrome::startup::IsProcessStartup is_process_startup = | |
| 636 process_startup ? chrome::startup::IS_PROCESS_STARTUP | |
| 637 : chrome::startup::IS_NOT_PROCESS_STARTUP; | |
| 638 AddInfoBarsIfNecessary(browser, is_process_startup); | |
| 639 } | |
| 640 | |
| 641 Browser* StartupBrowserCreatorImpl::MaybeRestoreSession( | |
| 642 const std::vector<GURL>& urls, | |
| 643 bool is_process_startup) { | |
| 644 // TODO(tmartino): Move session restore logic into this function. | |
| 645 return NULL; | |
| 646 } | |
| 647 | |
| 569 bool StartupBrowserCreatorImpl::ProcessStartupURLs( | 648 bool StartupBrowserCreatorImpl::ProcessStartupURLs( |
| 570 const std::vector<GURL>& urls_to_open) { | 649 const std::vector<GURL>& urls_to_open) { |
| 571 VLOG(1) << "StartupBrowserCreatorImpl::ProcessStartupURLs"; | 650 VLOG(1) << "StartupBrowserCreatorImpl::ProcessStartupURLs"; |
| 572 SessionStartupPref pref = | 651 SessionStartupPref pref = |
| 573 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_); | 652 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_); |
| 574 if (pref.type == SessionStartupPref::LAST) | 653 if (pref.type == SessionStartupPref::LAST) |
| 575 VLOG(1) << "Pref: last"; | 654 VLOG(1) << "Pref: last"; |
| 576 else if (pref.type == SessionStartupPref::URLS) | 655 else if (pref.type == SessionStartupPref::URLS) |
| 577 VLOG(1) << "Pref: urls"; | 656 VLOG(1) << "Pref: urls"; |
| 578 else if (pref.type == SessionStartupPref::DEFAULT) | 657 else if (pref.type == SessionStartupPref::DEFAULT) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 641 !HasPendingUncleanExit(profile_)) { | 720 !HasPendingUncleanExit(profile_)) { |
| 642 content::BrowserContext::GetDefaultStoragePartition(profile_)-> | 721 content::BrowserContext::GetDefaultStoragePartition(profile_)-> |
| 643 GetDOMStorageContext()->StartScavengingUnusedSessionStorage(); | 722 GetDOMStorageContext()->StartScavengingUnusedSessionStorage(); |
| 644 } | 723 } |
| 645 | 724 |
| 646 return true; | 725 return true; |
| 647 } | 726 } |
| 648 | 727 |
| 649 Browser* StartupBrowserCreatorImpl::ProcessSpecifiedURLs( | 728 Browser* StartupBrowserCreatorImpl::ProcessSpecifiedURLs( |
| 650 const std::vector<GURL>& urls_to_open) { | 729 const std::vector<GURL>& urls_to_open) { |
| 730 // TODO(tmartino): Deprecated, remove this once UseConsolidatedFirstRun is | |
| 731 // enabled. | |
| 732 | |
| 651 SessionStartupPref pref = | 733 SessionStartupPref pref = |
| 652 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_); | 734 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_); |
| 653 StartupTabs tabs; | 735 StartupTabs tabs; |
| 654 // Pinned tabs should not be displayed when chrome is launched in incognito | 736 // Pinned tabs should not be displayed when chrome is launched in incognito |
| 655 // mode. Also, no pages should be opened automatically if the session | 737 // mode. Also, no pages should be opened automatically if the session |
| 656 // crashed. Otherwise it might trigger another crash, locking the user out of | 738 // crashed. Otherwise it might trigger another crash, locking the user out of |
| 657 // chrome. The crash infobar is shown in this case. | 739 // chrome. The crash infobar is shown in this case. |
| 658 if (!IncognitoModePrefs::ShouldLaunchIncognito(command_line_, | 740 if (!IncognitoModePrefs::ShouldLaunchIncognito(command_line_, |
| 659 profile_->GetPrefs()) && | 741 profile_->GetPrefs()) && |
| 660 !HasPendingUncleanExit(profile_)) { | 742 !HasPendingUncleanExit(profile_)) { |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 819 browser_creator_->is_default_browser_dialog_suppressed())) { | 901 browser_creator_->is_default_browser_dialog_suppressed())) { |
| 820 chrome::ShowDefaultBrowserPrompt(profile_); | 902 chrome::ShowDefaultBrowserPrompt(profile_); |
| 821 } | 903 } |
| 822 } | 904 } |
| 823 #endif | 905 #endif |
| 824 } | 906 } |
| 825 } | 907 } |
| 826 | 908 |
| 827 void StartupBrowserCreatorImpl::AddStartupURLs( | 909 void StartupBrowserCreatorImpl::AddStartupURLs( |
| 828 std::vector<GURL>* startup_urls) const { | 910 std::vector<GURL>* startup_urls) const { |
| 829 // TODO(atwilson): Simplify the logic that decides which tabs to open on | 911 // TODO(tmartino): Deprecated, remove this once UseConsolidatedFirstRun is |
| 830 // start-up and make it more consistent. http://crbug.com/248883 | 912 // enabled. |
| 831 | 913 |
| 832 // If we have urls specified by the first run master preferences use them | 914 // If we have urls specified by the first run master preferences use them |
| 833 // and nothing else. | 915 // and nothing else. |
| 834 if (browser_creator_ && startup_urls->empty()) { | 916 if (browser_creator_ && startup_urls->empty()) { |
| 835 if (!browser_creator_->first_run_tabs_.empty()) { | 917 if (!browser_creator_->first_run_tabs_.empty()) { |
| 836 std::vector<GURL>::iterator it = | 918 std::vector<GURL>::iterator it = |
| 837 browser_creator_->first_run_tabs_.begin(); | 919 browser_creator_->first_run_tabs_.begin(); |
| 838 while (it != browser_creator_->first_run_tabs_.end()) { | 920 while (it != browser_creator_->first_run_tabs_.end()) { |
| 839 // Replace magic names for the actual urls. | 921 // Replace magic names for the actual urls. |
| 840 if (it->host() == "new_tab_page") { | 922 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)) | 968 startup_urls->at(0) == GURL(chrome::kChromeUINewTabURL)) |
| 887 startup_urls->at(0) = sync_promo_url; | 969 startup_urls->at(0) = sync_promo_url; |
| 888 else | 970 else |
| 889 startup_urls->insert(startup_urls->begin(), sync_promo_url); | 971 startup_urls->insert(startup_urls->begin(), sync_promo_url); |
| 890 } | 972 } |
| 891 } | 973 } |
| 892 } | 974 } |
| 893 | 975 |
| 894 void StartupBrowserCreatorImpl::AddSpecialURLs( | 976 void StartupBrowserCreatorImpl::AddSpecialURLs( |
| 895 std::vector<GURL>* url_list) const { | 977 std::vector<GURL>* url_list) const { |
| 978 // TODO(tmartino): Deprecated, remove this once UseConsolidatedFirstRun is | |
| 979 // enabled. | |
| 980 | |
| 896 // Optionally include the welcome page. | 981 // Optionally include the welcome page. |
| 897 if (welcome_run_type_ == WelcomeRunType::FIRST_TAB) | 982 if (welcome_run_type_ == WelcomeRunType::FIRST_TAB) |
| 898 url_list->insert(url_list->begin(), internals::GetWelcomePageURL()); | 983 url_list->insert(url_list->begin(), internals::GetWelcomePageURL()); |
| 899 | 984 |
| 900 // If this Profile is marked for a reset prompt, ensure the reset | 985 // If this Profile is marked for a reset prompt, ensure the reset |
| 901 // settings dialog appears. | 986 // settings dialog appears. |
| 902 if (ProfileHasResetTrigger()) { | 987 if (ProfileHasResetTrigger()) { |
| 903 url_list->insert(url_list->begin(), | 988 url_list->insert(url_list->begin(), |
| 904 internals::GetTriggeredResetSettingsURL()); | 989 internals::GetTriggeredResetSettingsURL()); |
| 905 } | 990 } |
| 906 } | 991 } |
| 907 | 992 |
| 908 // For first-run, the type will be FIRST_RUN_LAST for all systems except for | 993 // 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 | 994 // 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 | 995 // 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 | 996 // ANY_RUN_FIRST if this is the first somewhat normal launch since an OS |
| 912 // upgrade. | 997 // upgrade. |
| 998 | |
| 999 // TODO(tmartino): Deprecated, remove this once UseConsolidatedFirstRun is | |
| 1000 // enabled. | |
| 913 void StartupBrowserCreatorImpl::InitializeWelcomeRunType( | 1001 void StartupBrowserCreatorImpl::InitializeWelcomeRunType( |
| 914 const std::vector<GURL>& urls_to_open) { | 1002 const std::vector<GURL>& urls_to_open) { |
| 915 DCHECK_EQ(static_cast<int>(WelcomeRunType::NONE), | 1003 DCHECK_EQ(static_cast<int>(WelcomeRunType::NONE), |
| 916 static_cast<int>(welcome_run_type_)); | 1004 static_cast<int>(welcome_run_type_)); |
| 917 #if defined(OS_WIN) | 1005 #if defined(OS_WIN) |
| 918 // Do not welcome if there are any URLs to open. | 1006 // Do not welcome if there are any URLs to open. |
| 919 if (!urls_to_open.empty()) | 1007 if (!urls_to_open.empty()) |
| 920 return; | 1008 return; |
| 921 | 1009 |
| 922 base::win::OSInfo* const os_info = base::win::OSInfo::GetInstance(); | 1010 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) | 1077 #if defined(OS_WIN) |
| 990 TriggeredProfileResetter* triggered_profile_resetter = | 1078 TriggeredProfileResetter* triggered_profile_resetter = |
| 991 TriggeredProfileResetterFactory::GetForBrowserContext(profile_); | 1079 TriggeredProfileResetterFactory::GetForBrowserContext(profile_); |
| 992 // TriggeredProfileResetter instance will be nullptr for incognito profiles. | 1080 // TriggeredProfileResetter instance will be nullptr for incognito profiles. |
| 993 if (triggered_profile_resetter) { | 1081 if (triggered_profile_resetter) { |
| 994 has_reset_trigger = triggered_profile_resetter->HasResetTrigger(); | 1082 has_reset_trigger = triggered_profile_resetter->HasResetTrigger(); |
| 995 } | 1083 } |
| 996 #endif // defined(OS_WIN) | 1084 #endif // defined(OS_WIN) |
| 997 return has_reset_trigger; | 1085 return has_reset_trigger; |
| 998 } | 1086 } |
| OLD | NEW |