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" |
11 #include "apps/app_restore_service_factory.h" | 11 #include "apps/app_restore_service_factory.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/environment.h" | 16 #include "base/environment.h" |
17 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
20 #include "base/metrics/statistics_recorder.h" | 20 #include "base/metrics/statistics_recorder.h" |
21 #include "base/prefs/pref_service.h" | 21 #include "base/prefs/pref_service.h" |
22 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
23 #include "base/strings/string_split.h" | 23 #include "base/strings/string_split.h" |
24 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
25 #include "base/strings/stringprintf.h" | |
25 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
26 #include "base/threading/thread_restrictions.h" | 27 #include "base/threading/thread_restrictions.h" |
27 #include "chrome/browser/apps/install_chrome_app.h" | 28 #include "chrome/browser/apps/install_chrome_app.h" |
28 #include "chrome/browser/auto_launch_trial.h" | 29 #include "chrome/browser/auto_launch_trial.h" |
29 #include "chrome/browser/browser_process.h" | 30 #include "chrome/browser/browser_process.h" |
30 #include "chrome/browser/chrome_notification_types.h" | 31 #include "chrome/browser/chrome_notification_types.h" |
31 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 32 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
32 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | 33 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
33 #include "chrome/browser/defaults.h" | 34 #include "chrome/browser/defaults.h" |
34 #include "chrome/browser/extensions/extension_creator.h" | 35 #include "chrome/browser/extensions/extension_creator.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 70 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
70 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" | 71 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" |
71 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 72 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
72 #include "chrome/common/chrome_constants.h" | 73 #include "chrome/common/chrome_constants.h" |
73 #include "chrome/common/chrome_paths.h" | 74 #include "chrome/common/chrome_paths.h" |
74 #include "chrome/common/chrome_result_codes.h" | 75 #include "chrome/common/chrome_result_codes.h" |
75 #include "chrome/common/chrome_switches.h" | 76 #include "chrome/common/chrome_switches.h" |
76 #include "chrome/common/chrome_version_info.h" | 77 #include "chrome/common/chrome_version_info.h" |
77 #include "chrome/common/extensions/extension_constants.h" | 78 #include "chrome/common/extensions/extension_constants.h" |
78 #include "chrome/common/extensions/extension_metrics.h" | 79 #include "chrome/common/extensions/extension_metrics.h" |
80 #include "chrome/common/pref_names.h" | |
79 #include "chrome/common/url_constants.h" | 81 #include "chrome/common/url_constants.h" |
80 #include "chrome/grit/locale_settings.h" | 82 #include "chrome/grit/locale_settings.h" |
81 #include "chrome/installer/util/browser_distribution.h" | 83 #include "chrome/installer/util/browser_distribution.h" |
82 #include "components/google/core/browser/google_util.h" | 84 #include "components/google/core/browser/google_util.h" |
83 #include "content/public/browser/child_process_security_policy.h" | 85 #include "content/public/browser/child_process_security_policy.h" |
84 #include "content/public/browser/dom_storage_context.h" | 86 #include "content/public/browser/dom_storage_context.h" |
85 #include "content/public/browser/notification_observer.h" | 87 #include "content/public/browser/notification_observer.h" |
86 #include "content/public/browser/notification_registrar.h" | 88 #include "content/public/browser/notification_registrar.h" |
87 #include "content/public/browser/storage_partition.h" | 89 #include "content/public/browser/storage_partition.h" |
88 #include "content/public/browser/web_contents.h" | 90 #include "content/public/browser/web_contents.h" |
89 #include "extensions/browser/extension_prefs.h" | 91 #include "extensions/browser/extension_prefs.h" |
90 #include "extensions/browser/extension_registry.h" | 92 #include "extensions/browser/extension_registry.h" |
91 #include "extensions/common/constants.h" | 93 #include "extensions/common/constants.h" |
92 #include "extensions/common/extension.h" | 94 #include "extensions/common/extension.h" |
93 #include "extensions/common/extension_set.h" | 95 #include "extensions/common/extension_set.h" |
96 #include "net/base/network_change_notifier.h" | |
94 #include "ui/base/l10n/l10n_util.h" | 97 #include "ui/base/l10n/l10n_util.h" |
95 | 98 |
96 #if defined(OS_MACOSX) | 99 #if defined(OS_MACOSX) |
97 #include "base/mac/mac_util.h" | 100 #include "base/mac/mac_util.h" |
98 #include "chrome/browser/ui/cocoa/keystone_infobar_delegate.h" | 101 #include "chrome/browser/ui/cocoa/keystone_infobar_delegate.h" |
99 #endif | 102 #endif |
100 | 103 |
101 #if defined(OS_WIN) | 104 #if defined(OS_WIN) |
102 #include "base/win/windows_version.h" | 105 #include "base/win/windows_version.h" |
103 #include "chrome/browser/apps/app_launch_for_metro_restart_win.h" | 106 #include "chrome/browser/apps/app_launch_for_metro_restart_win.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 | 283 |
281 } // namespace | 284 } // namespace |
282 | 285 |
283 namespace internals { | 286 namespace internals { |
284 | 287 |
285 GURL GetWelcomePageURL() { | 288 GURL GetWelcomePageURL() { |
286 std::string welcome_url = l10n_util::GetStringUTF8(IDS_WELCOME_PAGE_URL); | 289 std::string welcome_url = l10n_util::GetStringUTF8(IDS_WELCOME_PAGE_URL); |
287 return GURL(welcome_url); | 290 return GURL(welcome_url); |
288 } | 291 } |
289 | 292 |
293 bool ShowWelcomePageAfterFirstRun() { | |
294 #if defined(OS_WIN) | |
295 return base::win::GetVersion() >= base::win::VERSION_WIN10; | |
296 #else | |
297 return false; | |
298 #endif | |
299 } | |
300 | |
290 } // namespace internals | 301 } // namespace internals |
291 | 302 |
292 StartupBrowserCreatorImpl::StartupBrowserCreatorImpl( | 303 StartupBrowserCreatorImpl::StartupBrowserCreatorImpl( |
293 const base::FilePath& cur_dir, | 304 const base::FilePath& cur_dir, |
294 const base::CommandLine& command_line, | 305 const base::CommandLine& command_line, |
295 chrome::startup::IsFirstRun is_first_run) | 306 chrome::startup::IsFirstRun is_first_run) |
296 : cur_dir_(cur_dir), | 307 : cur_dir_(cur_dir), |
297 command_line_(command_line), | 308 command_line_(command_line), |
298 profile_(NULL), | 309 profile_(NULL), |
299 browser_creator_(NULL), | 310 browser_creator_(NULL), |
300 is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN) { | 311 is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN), |
312 welcome_run_type_(WelcomeRunType::NONE) { | |
301 } | 313 } |
302 | 314 |
303 StartupBrowserCreatorImpl::StartupBrowserCreatorImpl( | 315 StartupBrowserCreatorImpl::StartupBrowserCreatorImpl( |
304 const base::FilePath& cur_dir, | 316 const base::FilePath& cur_dir, |
305 const base::CommandLine& command_line, | 317 const base::CommandLine& command_line, |
306 StartupBrowserCreator* browser_creator, | 318 StartupBrowserCreator* browser_creator, |
307 chrome::startup::IsFirstRun is_first_run) | 319 chrome::startup::IsFirstRun is_first_run) |
308 : cur_dir_(cur_dir), | 320 : cur_dir_(cur_dir), |
309 command_line_(command_line), | 321 command_line_(command_line), |
310 profile_(NULL), | 322 profile_(NULL), |
311 browser_creator_(browser_creator), | 323 browser_creator_(browser_creator), |
312 is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN) { | 324 is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN), |
325 welcome_run_type_(WelcomeRunType::NONE) { | |
313 } | 326 } |
314 | 327 |
315 StartupBrowserCreatorImpl::~StartupBrowserCreatorImpl() { | 328 StartupBrowserCreatorImpl::~StartupBrowserCreatorImpl() { |
316 } | 329 } |
317 | 330 |
318 bool StartupBrowserCreatorImpl::Launch(Profile* profile, | 331 bool StartupBrowserCreatorImpl::Launch(Profile* profile, |
319 const std::vector<GURL>& urls_to_open, | 332 const std::vector<GURL>& urls_to_open, |
320 bool process_startup, | 333 bool process_startup, |
321 chrome::HostDesktopType desktop_type) { | 334 chrome::HostDesktopType desktop_type) { |
322 DCHECK(profile); | 335 DCHECK(profile); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
528 chrome::HostDesktopType desktop_type) { | 541 chrome::HostDesktopType desktop_type) { |
529 // If we're starting up in "background mode" (no open browser window) then | 542 // If we're starting up in "background mode" (no open browser window) then |
530 // don't open any browser windows, unless kAutoLaunchAtStartup is also | 543 // don't open any browser windows, unless kAutoLaunchAtStartup is also |
531 // specified. | 544 // specified. |
532 if (process_startup && | 545 if (process_startup && |
533 command_line_.HasSwitch(switches::kNoStartupWindow) && | 546 command_line_.HasSwitch(switches::kNoStartupWindow) && |
534 !command_line_.HasSwitch(switches::kAutoLaunchAtStartup)) { | 547 !command_line_.HasSwitch(switches::kAutoLaunchAtStartup)) { |
535 return; | 548 return; |
536 } | 549 } |
537 | 550 |
551 // Determine whether or not this launch must include the welcome page. | |
552 InitializeWelcomeRunType(urls_to_open); | |
553 | |
538 // TODO(tapted): Move this to startup_browser_creator_win.cc after refactor. | 554 // TODO(tapted): Move this to startup_browser_creator_win.cc after refactor. |
539 #if defined(OS_WIN) | 555 #if defined(OS_WIN) |
540 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { | 556 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
541 // See if there are apps for this profile that should be launched on startup | 557 // See if there are apps for this profile that should be launched on startup |
542 // due to a switch from Metro mode. | 558 // due to a switch from Metro mode. |
543 app_metro_launch::HandleAppLaunchForMetroRestart(profile_); | 559 app_metro_launch::HandleAppLaunchForMetroRestart(profile_); |
544 } | 560 } |
545 #endif | 561 #endif |
546 | 562 |
547 if (process_startup && ProcessStartupURLs(urls_to_open, desktop_type)) { | 563 if (process_startup && ProcessStartupURLs(urls_to_open, desktop_type)) { |
548 // ProcessStartupURLs processed the urls, nothing else to do. | 564 // ProcessStartupURLs processed the urls, nothing else to do. |
549 return; | 565 return; |
550 } | 566 } |
551 | 567 |
552 chrome::startup::IsProcessStartup is_process_startup = process_startup ? | 568 chrome::startup::IsProcessStartup is_process_startup = process_startup ? |
553 chrome::startup::IS_PROCESS_STARTUP : | 569 chrome::startup::IS_PROCESS_STARTUP : |
554 chrome::startup::IS_NOT_PROCESS_STARTUP; | 570 chrome::startup::IS_NOT_PROCESS_STARTUP; |
555 if (!process_startup) { | 571 if (!process_startup) { |
556 // Even if we're not starting a new process, this may conceptually be | 572 // Even if we're not starting a new process, this may conceptually be |
557 // "startup" for the user and so should be handled in a similar way. Eg., | 573 // "startup" for the user and so should be handled in a similar way. Eg., |
558 // Chrome may have been running in the background due to an app with a | 574 // Chrome may have been running in the background due to an app with a |
559 // background page being installed, or running with only an app window | 575 // background page being installed, or running with only an app window |
560 // displayed. | 576 // displayed. |
561 SessionService* service = | 577 SessionService* service = |
562 SessionServiceFactory::GetForProfileForSessionRestore(profile_); | 578 SessionServiceFactory::GetForProfileForSessionRestore(profile_); |
563 if (service && service->ShouldNewWindowStartSession()) { | 579 if (service && service->ShouldNewWindowStartSession()) { |
564 // Restore the last session if any. | 580 // Restore the last session if any, optionally including the welcome page |
565 if (!HasPendingUncleanExit(profile_) && | 581 // if desired. |
566 service->RestoreIfNecessary(urls_to_open)) { | 582 if (!HasPendingUncleanExit(profile_)) { |
567 return; | 583 std::vector<GURL> adjust_urls(urls_to_open); |
584 if (welcome_run_type_ != WelcomeRunType::NONE) | |
585 adjust_urls.push_back(internals::GetWelcomePageURL()); | |
586 if (service->RestoreIfNecessary(adjust_urls)) { | |
587 RecordWelcomeRunComplete(); | |
588 return; | |
589 } | |
568 } | 590 } |
591 | |
569 // Open user-specified URLs like pinned tabs and startup tabs. | 592 // Open user-specified URLs like pinned tabs and startup tabs. |
570 Browser* browser = ProcessSpecifiedURLs(urls_to_open, desktop_type); | 593 Browser* browser = ProcessSpecifiedURLs(urls_to_open, desktop_type); |
571 if (browser) { | 594 if (browser) { |
572 AddInfoBarsIfNecessary(browser, is_process_startup); | 595 AddInfoBarsIfNecessary(browser, is_process_startup); |
573 return; | 596 return; |
574 } | 597 } |
575 } | 598 } |
576 } | 599 } |
577 | 600 |
578 // Session startup didn't occur, open the urls. | 601 // Session startup didn't occur, open the urls. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
635 #if defined(OS_MACOSX) | 658 #if defined(OS_MACOSX) |
636 // On Mac, when restoring a session with no windows, suppress the creation | 659 // On Mac, when restoring a session with no windows, suppress the creation |
637 // of a new window in the case where the system is launching Chrome via a | 660 // of a new window in the case where the system is launching Chrome via a |
638 // login item or Lion's resume feature. | 661 // login item or Lion's resume feature. |
639 if (base::mac::WasLaunchedAsLoginOrResumeItem()) { | 662 if (base::mac::WasLaunchedAsLoginOrResumeItem()) { |
640 restore_behavior = restore_behavior & | 663 restore_behavior = restore_behavior & |
641 ~SessionRestore::ALWAYS_CREATE_TABBED_BROWSER; | 664 ~SessionRestore::ALWAYS_CREATE_TABBED_BROWSER; |
642 } | 665 } |
643 #endif | 666 #endif |
644 | 667 |
668 // Optionally include the welcome page. | |
669 std::vector<GURL> adjust_urls(urls_to_open); | |
670 if (welcome_run_type_ != WelcomeRunType::NONE) | |
671 adjust_urls.push_back(internals::GetWelcomePageURL()); | |
672 | |
645 // The startup code only executes for browsers launched in desktop mode. | 673 // The startup code only executes for browsers launched in desktop mode. |
646 // i.e. HOST_DESKTOP_TYPE_NATIVE. Ash should never get here. | 674 // i.e. HOST_DESKTOP_TYPE_NATIVE. Ash should never get here. |
647 Browser* browser = SessionRestore::RestoreSession( | 675 Browser* browser = SessionRestore::RestoreSession( |
648 profile_, NULL, desktop_type, restore_behavior, | 676 profile_, NULL, desktop_type, restore_behavior, adjust_urls); |
649 urls_to_open); | 677 |
678 RecordWelcomeRunComplete(); | |
650 | 679 |
651 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP); | 680 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP); |
652 return true; | 681 return true; |
653 } | 682 } |
654 | 683 |
655 Browser* browser = ProcessSpecifiedURLs(urls_to_open, desktop_type); | 684 Browser* browser = ProcessSpecifiedURLs(urls_to_open, desktop_type); |
656 if (!browser) | 685 if (!browser) |
657 return false; | 686 return false; |
658 | 687 |
659 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP); | 688 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
692 // If urls were specified on the command line, use them. | 721 // If urls were specified on the command line, use them. |
693 UrlsToTabs(urls_to_open, &tabs); | 722 UrlsToTabs(urls_to_open, &tabs); |
694 } else if (pref.type == SessionStartupPref::DEFAULT || | 723 } else if (pref.type == SessionStartupPref::DEFAULT || |
695 (is_first_run_ && | 724 (is_first_run_ && |
696 browser_creator_ && !browser_creator_->first_run_tabs_.empty())) { | 725 browser_creator_ && !browser_creator_->first_run_tabs_.empty())) { |
697 std::vector<GURL> urls; | 726 std::vector<GURL> urls; |
698 AddStartupURLs(&urls); | 727 AddStartupURLs(&urls); |
699 UrlsToTabs(urls, &tabs); | 728 UrlsToTabs(urls, &tabs); |
700 } else if (pref.type == SessionStartupPref::URLS && !pref.urls.empty() && | 729 } else if (pref.type == SessionStartupPref::URLS && !pref.urls.empty() && |
701 !HasPendingUncleanExit(profile_)) { | 730 !HasPendingUncleanExit(profile_)) { |
731 // Optionally include the welcome page first. | |
732 if (welcome_run_type_ == WelcomeRunType::ANY_RUN_FIRST) | |
733 UrlsToTabs(std::vector<GURL>(1, internals::GetWelcomePageURL()), &tabs); | |
702 // Only use the set of urls specified in preferences if nothing was | 734 // Only use the set of urls specified in preferences if nothing was |
703 // specified on the command line. Filter out any urls that are to be | 735 // specified on the command line. Filter out any urls that are to be |
704 // restored by virtue of having been previously pinned. | 736 // restored by virtue of having been previously pinned. |
705 AddUniqueURLs(pref.urls, &tabs); | 737 AddUniqueURLs(pref.urls, &tabs); |
706 } else if (pref.type == SessionStartupPref::HOMEPAGE) { | 738 } else if (pref.type == SessionStartupPref::HOMEPAGE) { |
707 // If 'homepage' selected, either by the user or by a policy, we should | 739 // If 'homepage' selected, either by the user or by a policy, we should |
708 // have migrated them to another value. | 740 // have migrated them to another value. |
709 NOTREACHED() << "SessionStartupPref has deprecated type HOMEPAGE"; | 741 NOTREACHED() << "SessionStartupPref has deprecated type HOMEPAGE"; |
710 } | 742 } |
711 | 743 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
756 // If we don't yet have a profile, try to use the one we're given from | 788 // If we don't yet have a profile, try to use the one we're given from |
757 // |browser|. While we may not end up actually using |browser| (since it | 789 // |browser|. While we may not end up actually using |browser| (since it |
758 // could be a popup window), we can at least use the profile. | 790 // could be a popup window), we can at least use the profile. |
759 if (!profile_ && browser) | 791 if (!profile_ && browser) |
760 profile_ = browser->profile(); | 792 profile_ = browser->profile(); |
761 | 793 |
762 if (!browser || !browser->is_type_tabbed()) | 794 if (!browser || !browser->is_type_tabbed()) |
763 browser = new Browser(Browser::CreateParams(profile_, desktop_type)); | 795 browser = new Browser(Browser::CreateParams(profile_, desktop_type)); |
764 | 796 |
765 bool first_tab = true; | 797 bool first_tab = true; |
798 const GURL welcome_url(internals::GetWelcomePageURL()); | |
766 ProtocolHandlerRegistry* registry = profile_ ? | 799 ProtocolHandlerRegistry* registry = profile_ ? |
767 ProtocolHandlerRegistryFactory::GetForBrowserContext(profile_) : NULL; | 800 ProtocolHandlerRegistryFactory::GetForBrowserContext(profile_) : NULL; |
768 for (size_t i = 0; i < tabs.size(); ++i) { | 801 for (size_t i = 0; i < tabs.size(); ++i) { |
769 // We skip URLs that we'd have to launch an external protocol handler for. | 802 // We skip URLs that we'd have to launch an external protocol handler for. |
770 // This avoids us getting into an infinite loop asking ourselves to open | 803 // This avoids us getting into an infinite loop asking ourselves to open |
771 // a URL, should the handler be (incorrectly) configured to be us. Anyone | 804 // a URL, should the handler be (incorrectly) configured to be us. Anyone |
772 // asking us to open such a URL should really ask the handler directly. | 805 // asking us to open such a URL should really ask the handler directly. |
773 bool handled_by_chrome = ProfileIOData::IsHandledURL(tabs[i].url) || | 806 bool handled_by_chrome = ProfileIOData::IsHandledURL(tabs[i].url) || |
774 (registry && registry->IsHandledProtocol(tabs[i].url.scheme())); | 807 (registry && registry->IsHandledProtocol(tabs[i].url.scheme())); |
775 if (!process_startup && !handled_by_chrome) | 808 if (!process_startup && !handled_by_chrome) |
(...skipping 10 matching lines...) Expand all Loading... | |
786 params.disposition = first_tab ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; | 819 params.disposition = first_tab ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; |
787 params.tabstrip_add_types = add_types; | 820 params.tabstrip_add_types = add_types; |
788 | 821 |
789 #if defined(ENABLE_RLZ) && !defined(OS_IOS) | 822 #if defined(ENABLE_RLZ) && !defined(OS_IOS) |
790 if (process_startup && google_util::IsGoogleHomePageUrl(tabs[i].url)) { | 823 if (process_startup && google_util::IsGoogleHomePageUrl(tabs[i].url)) { |
791 params.extra_headers = RLZTracker::GetAccessPointHttpHeader( | 824 params.extra_headers = RLZTracker::GetAccessPointHttpHeader( |
792 RLZTracker::ChromeHomePage()); | 825 RLZTracker::ChromeHomePage()); |
793 } | 826 } |
794 #endif // defined(ENABLE_RLZ) && !defined(OS_IOS) | 827 #endif // defined(ENABLE_RLZ) && !defined(OS_IOS) |
795 | 828 |
829 if (welcome_run_type_ != WelcomeRunType::NONE && tabs[i].url == welcome_url) | |
830 RecordWelcomeRunComplete(); | |
831 | |
796 chrome::Navigate(¶ms); | 832 chrome::Navigate(¶ms); |
797 | 833 |
798 first_tab = false; | 834 first_tab = false; |
799 } | 835 } |
800 if (!browser->tab_strip_model()->GetActiveWebContents()) { | 836 if (!browser->tab_strip_model()->GetActiveWebContents()) { |
801 // TODO: this is a work around for 110909. Figure out why it's needed. | 837 // TODO: this is a work around for 110909. Figure out why it's needed. |
802 if (!browser->tab_strip_model()->count()) | 838 if (!browser->tab_strip_model()->count()) |
803 chrome::AddTabAt(browser, GURL(), -1, true); | 839 chrome::AddTabAt(browser, GURL(), -1, true); |
804 else | 840 else |
805 browser->tab_strip_model()->ActivateTabAt(0, false); | 841 browser->tab_strip_model()->ActivateTabAt(0, false); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
873 startup_urls->push_back(internals::GetWelcomePageURL()); | 909 startup_urls->push_back(internals::GetWelcomePageURL()); |
874 } else { | 910 } else { |
875 startup_urls->push_back(*it); | 911 startup_urls->push_back(*it); |
876 } | 912 } |
877 ++it; | 913 ++it; |
878 } | 914 } |
879 browser_creator_->first_run_tabs_.clear(); | 915 browser_creator_->first_run_tabs_.clear(); |
880 } | 916 } |
881 } | 917 } |
882 | 918 |
883 // Otherwise open at least the new tab page (and the welcome page, if this | 919 // Otherwise open at least the new tab page (and the welcome page if this is |
884 // is the first time the browser is being started), or the set of URLs | 920 // the first time the browser is being started or the first time following an |
885 // specified on the command line. | 921 // upgrade past Windows 10), or the set of URLs specified on the command line. |
886 if (startup_urls->empty()) { | 922 if (startup_urls->empty()) { |
923 // Put the welcome page before the new tab page on Windows 10. | |
924 if (welcome_run_type_ == WelcomeRunType::FIRST_RUN_FIRST || | |
925 welcome_run_type_ == WelcomeRunType::ANY_RUN_FIRST) { | |
926 startup_urls->push_back(internals::GetWelcomePageURL()); | |
927 } | |
887 startup_urls->push_back(GURL(chrome::kChromeUINewTabURL)); | 928 startup_urls->push_back(GURL(chrome::kChromeUINewTabURL)); |
888 if (first_run::ShouldShowWelcomePage()) | 929 // Put the welcome page after the new tab page elsewhere. |
930 if (welcome_run_type_ == WelcomeRunType::FIRST_RUN_LAST) | |
889 startup_urls->push_back(internals::GetWelcomePageURL()); | 931 startup_urls->push_back(internals::GetWelcomePageURL()); |
890 } | 932 } |
891 | 933 |
892 if (signin::ShouldShowPromoAtStartup(profile_, is_first_run_)) { | 934 if (signin::ShouldShowPromoAtStartup(profile_, is_first_run_)) { |
893 signin::DidShowPromoAtStartup(profile_); | 935 signin::DidShowPromoAtStartup(profile_); |
894 | 936 |
895 const GURL sync_promo_url = signin::GetPromoURL( | 937 const GURL sync_promo_url = signin::GetPromoURL( |
896 signin_metrics::SOURCE_START_PAGE, false); | 938 signin_metrics::SOURCE_START_PAGE, false); |
897 | 939 |
898 // No need to add if the sync promo is already in the startup list. | 940 // No need to add if the sync promo is already in the startup list. |
(...skipping 11 matching lines...) Expand all Loading... | |
910 // behavior is desired because completing or skipping the sync promo | 952 // behavior is desired because completing or skipping the sync promo |
911 // causes a redirect to the NTP. | 953 // causes a redirect to the NTP. |
912 if (!startup_urls->empty() && | 954 if (!startup_urls->empty() && |
913 startup_urls->at(0) == GURL(chrome::kChromeUINewTabURL)) | 955 startup_urls->at(0) == GURL(chrome::kChromeUINewTabURL)) |
914 startup_urls->at(0) = sync_promo_url; | 956 startup_urls->at(0) = sync_promo_url; |
915 else | 957 else |
916 startup_urls->insert(startup_urls->begin(), sync_promo_url); | 958 startup_urls->insert(startup_urls->begin(), sync_promo_url); |
917 } | 959 } |
918 } | 960 } |
919 } | 961 } |
962 | |
963 // For first-run, the type will be FIRST_RUN_LAST for all systems except for | |
964 // Windows 10+, where it will be FIRST_RUN_FIRST. For non-first run, the type | |
965 // will be NONE for all systems except for Windows 10+, where it will be | |
966 // ANY_RUN_FIRST if this is the first somewhat normal launch since an OS | |
967 // upgrade. | |
968 void StartupBrowserCreatorImpl::InitializeWelcomeRunType( | |
969 const std::vector<GURL>& urls_to_open) { | |
970 DCHECK_EQ(static_cast<int>(WelcomeRunType::NONE), | |
971 static_cast<int>(welcome_run_type_)); | |
972 #if defined(OS_WIN) | |
973 // Do not welcome if there are any URLs to open. | |
974 if (!urls_to_open.empty()) | |
975 return; | |
976 | |
977 base::win::OSInfo* os_info = base::win::OSInfo::GetInstance(); | |
978 | |
979 // Always welcome on first run. | |
980 if (first_run::ShouldShowWelcomePage()) { | |
981 // First tab for Win10+, last tab otherwise. | |
982 welcome_run_type_ = os_info->version() >= base::win::VERSION_WIN10 | |
983 ? WelcomeRunType::FIRST_RUN_FIRST | |
984 : WelcomeRunType::FIRST_RUN_LAST; | |
985 return; | |
986 } | |
987 | |
988 // Otherwise, do not welcome pre-Win10. | |
989 if (!internals::ShowWelcomePageAfterFirstRun()) | |
990 return; | |
991 | |
992 // Do not welcome if launching into incognito. | |
993 if (IncognitoModePrefs::ShouldLaunchIncognito(command_line_, | |
994 profile_->GetPrefs())) { | |
995 return; | |
996 } | |
997 | |
998 // Do not welcome if there is no local state (tests). | |
999 PrefService* local_state = g_browser_process->local_state(); | |
1000 if (!local_state) | |
1001 return; | |
1002 | |
1003 // Do not welcome if disabled by policy or master_preferences. | |
1004 if (!local_state->GetBoolean(prefs::kWelcomePageOnOSUpgradeEnabled)) | |
1005 return; | |
1006 | |
1007 base::win::OSInfo::VersionNumber v(os_info->version_number()); | |
1008 std::string this_os_version(base::StringPrintf("%d.%d", v.major, v.minor)); | |
1009 | |
1010 // Do not welcome if already shown for this OS version. | |
1011 if (local_state->GetString(prefs::kLastWelcomedOSVersion) == this_os_version) | |
1012 return; | |
1013 | |
1014 // Do not welcome if offline. | |
1015 if (net::NetworkChangeNotifier::IsOffline()) | |
1016 return; | |
1017 | |
1018 // Do not welcome if Chrome is the default browser. | |
1019 { | |
1020 // Checking for default browser will touch the filesystem. This phase of | |
1021 // launch is synchronous, so there is no choice to bounce to another thread | |
1022 // now. Since this is the last condition checked before adding the welcome | |
1023 // page, it will be hit only once per user. | |
1024 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
jochen (gone - plz use gerrit)
2015/07/10 09:03:31
is it possible to move this check to before the io
grt (UTC plus 2)
2015/07/10 12:05:31
For an ordinary Chrome launch, this does indeed ta
jochen (gone - plz use gerrit)
2015/07/10 12:12:51
that means that we potentially show the page twice
grt (UTC plus 2)
2015/07/10 12:17:31
No. In fact, we'll never his this line if the page
| |
1025 if (ShellIntegration::GetDefaultBrowser() == ShellIntegration::IS_DEFAULT) | |
1026 return; | |
1027 } | |
1028 | |
1029 // Show the welcome page in the first tab. | |
1030 welcome_run_type_ = WelcomeRunType::ANY_RUN_FIRST; | |
1031 #else // OS_WIN | |
1032 // Show the welcome page as the last tab only on first-run. | |
1033 if (first_run::ShouldShowWelcomePage()) | |
1034 welcome_run_type_ = WelcomeRunType::FIRST_RUN_LAST; | |
1035 #endif // !OS_WIN | |
1036 } | |
1037 | |
1038 void StartupBrowserCreatorImpl::RecordWelcomeRunComplete() const { | |
1039 #if defined(OS_WIN) | |
1040 if (welcome_run_type_ == WelcomeRunType::NONE) | |
1041 return; | |
1042 | |
1043 // Remember that the welcome page was shown for this OS version. | |
1044 using base::win::OSInfo; | |
1045 OSInfo::VersionNumber v(OSInfo::GetInstance()->version_number()); | |
1046 g_browser_process->local_state()->SetString( | |
1047 prefs::kLastWelcomedOSVersion, | |
1048 base::StringPrintf("%d.%d", v.major, v.minor)); | |
1049 welcome_run_type_ = WelcomeRunType::NONE; | |
1050 #endif | |
1051 } | |
OLD | NEW |