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::kUseNewFirstRun) && | |
505 !first_run::IsWin10()) { | |
506 ProcessLaunchURLsUsingNewFlow(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::ProcessLaunchURLsUsingNewFlow( | |
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 #if defined(OS_WIN) | |
Roger Tawa OOO till Jul 10th
2016/07/26 15:00:26
Don't forget to copy TODO from line 517.
tmartino
2016/07/27 18:40:44
Done.
| |
587 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { | |
588 // See if there are apps for this profile that should be launched on startup | |
589 // due to a switch from Metro mode. | |
590 app_metro_launch::HandleAppLaunchForMetroRestart(profile_); | |
591 } | |
592 #endif | |
593 | |
594 // If Master Prefs contains any first run tabs, use only those. | |
595 std::vector<GURL> tabs_to_insert; | |
596 if (browser_creator_) { | |
597 tabs_to_insert = | |
598 first_run::ProcessMasterPrefsTabs(browser_creator_->first_run_tabs_); | |
599 browser_creator_->first_run_tabs_.clear(); | |
600 } | |
601 // Otherwise, use the standard Onboarding logic to determine which, if any, | |
602 // tabs need to be surfaced. | |
603 if (tabs_to_insert.empty()) { | |
604 tabs_to_insert = first_run::GetOnboardingTabs(); | |
605 } | |
606 | |
607 // If this profile is marked for a reset prompt, put this before all other | |
608 // tabs. | |
609 if (ProfileHasResetTrigger()) { | |
610 tabs_to_insert.insert(tabs_to_insert.begin(), | |
611 internals::GetTriggeredResetSettingsURL()); | |
612 } | |
613 | |
614 // TODO(tmartino): Function for processing pinned tabs. | |
615 | |
616 // Prepend the resulting list of tabs to those passed in. | |
617 if (!tabs_to_insert.empty()) { | |
618 adjusted_urls.insert(adjusted_urls.begin(), tabs_to_insert.begin(), | |
619 tabs_to_insert.end()); | |
620 } | |
621 | |
622 // First, we see if we can or should restore an old session. | |
623 Browser* browser = MaybeRestoreSession(adjusted_urls, process_startup); | |
624 | |
625 // Otherwise, open. | |
626 if (!browser) { | |
627 browser = OpenURLsInBrowser(browser, process_startup, adjusted_urls); | |
628 } | |
629 | |
630 // Finally, add info bars. | |
631 chrome::startup::IsProcessStartup is_process_startup = | |
632 process_startup ? chrome::startup::IS_PROCESS_STARTUP | |
633 : chrome::startup::IS_NOT_PROCESS_STARTUP; | |
634 AddInfoBarsIfNecessary(browser, is_process_startup); | |
635 } | |
636 | |
637 Browser* StartupBrowserCreatorImpl::MaybeRestoreSession( | |
638 const std::vector<GURL>& urls, | |
639 bool is_process_startup) { | |
640 // TODO(tmartino): Add session restore logic. | |
641 return NULL; | |
Roger Tawa OOO till Jul 10th
2016/07/26 15:00:26
Is it possible for session restore to restore mult
tmartino
2016/07/27 18:40:43
I've clarified my skeleton. There are two types of
| |
642 } | |
643 | |
569 bool StartupBrowserCreatorImpl::ProcessStartupURLs( | 644 bool StartupBrowserCreatorImpl::ProcessStartupURLs( |
570 const std::vector<GURL>& urls_to_open) { | 645 const std::vector<GURL>& urls_to_open) { |
571 VLOG(1) << "StartupBrowserCreatorImpl::ProcessStartupURLs"; | 646 VLOG(1) << "StartupBrowserCreatorImpl::ProcessStartupURLs"; |
572 SessionStartupPref pref = | 647 SessionStartupPref pref = |
573 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_); | 648 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_); |
574 if (pref.type == SessionStartupPref::LAST) | 649 if (pref.type == SessionStartupPref::LAST) |
575 VLOG(1) << "Pref: last"; | 650 VLOG(1) << "Pref: last"; |
576 else if (pref.type == SessionStartupPref::URLS) | 651 else if (pref.type == SessionStartupPref::URLS) |
577 VLOG(1) << "Pref: urls"; | 652 VLOG(1) << "Pref: urls"; |
578 else if (pref.type == SessionStartupPref::DEFAULT) | 653 else if (pref.type == SessionStartupPref::DEFAULT) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
641 !HasPendingUncleanExit(profile_)) { | 716 !HasPendingUncleanExit(profile_)) { |
642 content::BrowserContext::GetDefaultStoragePartition(profile_)-> | 717 content::BrowserContext::GetDefaultStoragePartition(profile_)-> |
643 GetDOMStorageContext()->StartScavengingUnusedSessionStorage(); | 718 GetDOMStorageContext()->StartScavengingUnusedSessionStorage(); |
644 } | 719 } |
645 | 720 |
646 return true; | 721 return true; |
647 } | 722 } |
648 | 723 |
649 Browser* StartupBrowserCreatorImpl::ProcessSpecifiedURLs( | 724 Browser* StartupBrowserCreatorImpl::ProcessSpecifiedURLs( |
650 const std::vector<GURL>& urls_to_open) { | 725 const std::vector<GURL>& urls_to_open) { |
726 // TODO(tmartino): Deprecated, remove this once UseNewFirstRun is enabled. | |
727 | |
651 SessionStartupPref pref = | 728 SessionStartupPref pref = |
652 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_); | 729 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_); |
653 StartupTabs tabs; | 730 StartupTabs tabs; |
654 // Pinned tabs should not be displayed when chrome is launched in incognito | 731 // Pinned tabs should not be displayed when chrome is launched in incognito |
655 // mode. Also, no pages should be opened automatically if the session | 732 // mode. Also, no pages should be opened automatically if the session |
656 // crashed. Otherwise it might trigger another crash, locking the user out of | 733 // crashed. Otherwise it might trigger another crash, locking the user out of |
657 // chrome. The crash infobar is shown in this case. | 734 // chrome. The crash infobar is shown in this case. |
658 if (!IncognitoModePrefs::ShouldLaunchIncognito(command_line_, | 735 if (!IncognitoModePrefs::ShouldLaunchIncognito(command_line_, |
659 profile_->GetPrefs()) && | 736 profile_->GetPrefs()) && |
660 !HasPendingUncleanExit(profile_)) { | 737 !HasPendingUncleanExit(profile_)) { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
819 browser_creator_->is_default_browser_dialog_suppressed())) { | 896 browser_creator_->is_default_browser_dialog_suppressed())) { |
820 chrome::ShowDefaultBrowserPrompt(profile_); | 897 chrome::ShowDefaultBrowserPrompt(profile_); |
821 } | 898 } |
822 } | 899 } |
823 #endif | 900 #endif |
824 } | 901 } |
825 } | 902 } |
826 | 903 |
827 void StartupBrowserCreatorImpl::AddStartupURLs( | 904 void StartupBrowserCreatorImpl::AddStartupURLs( |
828 std::vector<GURL>* startup_urls) const { | 905 std::vector<GURL>* startup_urls) const { |
829 // TODO(atwilson): Simplify the logic that decides which tabs to open on | 906 // TODO(tmartino): Deprecated, remove this once UseNewFirstRun is enabled. |
830 // start-up and make it more consistent. http://crbug.com/248883 | |
831 | 907 |
832 // If we have urls specified by the first run master preferences use them | 908 // If we have urls specified by the first run master preferences use them |
833 // and nothing else. | 909 // and nothing else. |
834 if (browser_creator_ && startup_urls->empty()) { | 910 if (browser_creator_ && startup_urls->empty()) { |
835 if (!browser_creator_->first_run_tabs_.empty()) { | 911 if (!browser_creator_->first_run_tabs_.empty()) { |
836 std::vector<GURL>::iterator it = | 912 std::vector<GURL>::iterator it = |
837 browser_creator_->first_run_tabs_.begin(); | 913 browser_creator_->first_run_tabs_.begin(); |
838 while (it != browser_creator_->first_run_tabs_.end()) { | 914 while (it != browser_creator_->first_run_tabs_.end()) { |
839 // Replace magic names for the actual urls. | 915 // Replace magic names for the actual urls. |
840 if (it->host() == "new_tab_page") { | 916 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)) | 962 startup_urls->at(0) == GURL(chrome::kChromeUINewTabURL)) |
887 startup_urls->at(0) = sync_promo_url; | 963 startup_urls->at(0) = sync_promo_url; |
888 else | 964 else |
889 startup_urls->insert(startup_urls->begin(), sync_promo_url); | 965 startup_urls->insert(startup_urls->begin(), sync_promo_url); |
890 } | 966 } |
891 } | 967 } |
892 } | 968 } |
893 | 969 |
894 void StartupBrowserCreatorImpl::AddSpecialURLs( | 970 void StartupBrowserCreatorImpl::AddSpecialURLs( |
895 std::vector<GURL>* url_list) const { | 971 std::vector<GURL>* url_list) const { |
972 // TODO(tmartino): Deprecated, remove this once UseNewFirstRun is enabled. | |
973 | |
896 // Optionally include the welcome page. | 974 // Optionally include the welcome page. |
897 if (welcome_run_type_ == WelcomeRunType::FIRST_TAB) | 975 if (welcome_run_type_ == WelcomeRunType::FIRST_TAB) |
898 url_list->insert(url_list->begin(), internals::GetWelcomePageURL()); | 976 url_list->insert(url_list->begin(), internals::GetWelcomePageURL()); |
899 | 977 |
900 // If this Profile is marked for a reset prompt, ensure the reset | 978 // If this Profile is marked for a reset prompt, ensure the reset |
901 // settings dialog appears. | 979 // settings dialog appears. |
902 if (ProfileHasResetTrigger()) { | 980 if (ProfileHasResetTrigger()) { |
903 url_list->insert(url_list->begin(), | 981 url_list->insert(url_list->begin(), |
904 internals::GetTriggeredResetSettingsURL()); | 982 internals::GetTriggeredResetSettingsURL()); |
905 } | 983 } |
(...skipping 83 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 |