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 | |
301 void RecordWelcomeRunComplete() { | |
302 #if defined(OS_WIN) | |
303 using base::win::OSInfo; | |
304 OSInfo::VersionNumber v(OSInfo::GetInstance()->version_number()); | |
gab
2015/07/09 18:05:12
const
| |
305 std::string os_version(base::StringPrintf("%d.%d", v.major, v.minor)); | |
gab
2015/07/09 18:05:13
const
| |
306 g_browser_process->local_state()->SetString(prefs::kLastWelcomedOSVersion, | |
307 os_version); | |
308 #endif | |
309 } | |
310 | |
290 } // namespace internals | 311 } // namespace internals |
291 | 312 |
292 StartupBrowserCreatorImpl::StartupBrowserCreatorImpl( | 313 StartupBrowserCreatorImpl::StartupBrowserCreatorImpl( |
293 const base::FilePath& cur_dir, | 314 const base::FilePath& cur_dir, |
294 const base::CommandLine& command_line, | 315 const base::CommandLine& command_line, |
295 chrome::startup::IsFirstRun is_first_run) | 316 chrome::startup::IsFirstRun is_first_run) |
296 : cur_dir_(cur_dir), | 317 : cur_dir_(cur_dir), |
297 command_line_(command_line), | 318 command_line_(command_line), |
298 profile_(NULL), | 319 profile_(NULL), |
299 browser_creator_(NULL), | 320 browser_creator_(NULL), |
300 is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN) { | 321 is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN), |
322 welcome_run_type_(WelcomeRunType::NONE) { | |
301 } | 323 } |
302 | 324 |
303 StartupBrowserCreatorImpl::StartupBrowserCreatorImpl( | 325 StartupBrowserCreatorImpl::StartupBrowserCreatorImpl( |
304 const base::FilePath& cur_dir, | 326 const base::FilePath& cur_dir, |
305 const base::CommandLine& command_line, | 327 const base::CommandLine& command_line, |
306 StartupBrowserCreator* browser_creator, | 328 StartupBrowserCreator* browser_creator, |
307 chrome::startup::IsFirstRun is_first_run) | 329 chrome::startup::IsFirstRun is_first_run) |
308 : cur_dir_(cur_dir), | 330 : cur_dir_(cur_dir), |
309 command_line_(command_line), | 331 command_line_(command_line), |
310 profile_(NULL), | 332 profile_(NULL), |
311 browser_creator_(browser_creator), | 333 browser_creator_(browser_creator), |
312 is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN) { | 334 is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN), |
335 welcome_run_type_(WelcomeRunType::NONE) { | |
313 } | 336 } |
314 | 337 |
315 StartupBrowserCreatorImpl::~StartupBrowserCreatorImpl() { | 338 StartupBrowserCreatorImpl::~StartupBrowserCreatorImpl() { |
316 } | 339 } |
317 | 340 |
318 bool StartupBrowserCreatorImpl::Launch(Profile* profile, | 341 bool StartupBrowserCreatorImpl::Launch(Profile* profile, |
319 const std::vector<GURL>& urls_to_open, | 342 const std::vector<GURL>& urls_to_open, |
320 bool process_startup, | 343 bool process_startup, |
321 chrome::HostDesktopType desktop_type) { | 344 chrome::HostDesktopType desktop_type) { |
322 DCHECK(profile); | 345 DCHECK(profile); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
528 chrome::HostDesktopType desktop_type) { | 551 chrome::HostDesktopType desktop_type) { |
529 // If we're starting up in "background mode" (no open browser window) then | 552 // If we're starting up in "background mode" (no open browser window) then |
530 // don't open any browser windows, unless kAutoLaunchAtStartup is also | 553 // don't open any browser windows, unless kAutoLaunchAtStartup is also |
531 // specified. | 554 // specified. |
532 if (process_startup && | 555 if (process_startup && |
533 command_line_.HasSwitch(switches::kNoStartupWindow) && | 556 command_line_.HasSwitch(switches::kNoStartupWindow) && |
534 !command_line_.HasSwitch(switches::kAutoLaunchAtStartup)) { | 557 !command_line_.HasSwitch(switches::kAutoLaunchAtStartup)) { |
535 return; | 558 return; |
536 } | 559 } |
537 | 560 |
561 // Determine whether or not this launch must include the welcome page. | |
562 InitializeWelcomeRunType(urls_to_open); | |
msw
2015/07/09 17:51:31
I feel like there's a lot of unnecessary complexit
grt (UTC plus 2)
2015/07/10 15:43:24
I originally had it as you describe, but found tha
msw
2015/07/10 19:40:45
But if RestoreIfNecessary returns false, the code
grt (UTC plus 2)
2015/07/10 20:35:12
Ah, yes, I think I can get rid of RecordWelcomeRun
| |
563 | |
538 // TODO(tapted): Move this to startup_browser_creator_win.cc after refactor. | 564 // TODO(tapted): Move this to startup_browser_creator_win.cc after refactor. |
539 #if defined(OS_WIN) | 565 #if defined(OS_WIN) |
540 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { | 566 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
541 // See if there are apps for this profile that should be launched on startup | 567 // See if there are apps for this profile that should be launched on startup |
542 // due to a switch from Metro mode. | 568 // due to a switch from Metro mode. |
543 app_metro_launch::HandleAppLaunchForMetroRestart(profile_); | 569 app_metro_launch::HandleAppLaunchForMetroRestart(profile_); |
544 } | 570 } |
545 #endif | 571 #endif |
546 | 572 |
547 if (process_startup && ProcessStartupURLs(urls_to_open, desktop_type)) { | 573 if (process_startup && ProcessStartupURLs(urls_to_open, desktop_type)) { |
548 // ProcessStartupURLs processed the urls, nothing else to do. | 574 // ProcessStartupURLs processed the urls, nothing else to do. |
549 return; | 575 return; |
550 } | 576 } |
551 | 577 |
552 chrome::startup::IsProcessStartup is_process_startup = process_startup ? | 578 chrome::startup::IsProcessStartup is_process_startup = process_startup ? |
553 chrome::startup::IS_PROCESS_STARTUP : | 579 chrome::startup::IS_PROCESS_STARTUP : |
554 chrome::startup::IS_NOT_PROCESS_STARTUP; | 580 chrome::startup::IS_NOT_PROCESS_STARTUP; |
555 if (!process_startup) { | 581 if (!process_startup) { |
556 // Even if we're not starting a new process, this may conceptually be | 582 // 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., | 583 // "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 | 584 // 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 | 585 // background page being installed, or running with only an app window |
560 // displayed. | 586 // displayed. |
561 SessionService* service = | 587 SessionService* service = |
562 SessionServiceFactory::GetForProfileForSessionRestore(profile_); | 588 SessionServiceFactory::GetForProfileForSessionRestore(profile_); |
563 if (service && service->ShouldNewWindowStartSession()) { | 589 if (service && service->ShouldNewWindowStartSession()) { |
564 // Restore the last session if any. | 590 // Restore the last session if any, optionally including the welcome page |
565 if (!HasPendingUncleanExit(profile_) && | 591 // if desired. |
566 service->RestoreIfNecessary(urls_to_open)) { | 592 if (!HasPendingUncleanExit(profile_)) { |
567 return; | 593 std::vector<GURL> adjust_urls(urls_to_open); |
gab
2015/07/09 18:05:12
s/adjust_urls/adjusted_urls/
grt (UTC plus 2)
2015/07/10 15:43:25
Done.
| |
594 if (welcome_run_type_ != WelcomeRunType::NONE) | |
595 adjust_urls.push_back(internals::GetWelcomePageURL()); | |
gab
2015/07/09 18:05:12
Doesn't this unconditionally put it last?
grt (UTC plus 2)
2015/07/10 15:43:25
adjust_urls will be empty, so it'll do the right t
| |
596 if (service->RestoreIfNecessary(adjust_urls)) { | |
597 RecordWelcomeRunComplete(); | |
598 return; | |
599 } | |
568 } | 600 } |
601 | |
569 // Open user-specified URLs like pinned tabs and startup tabs. | 602 // Open user-specified URLs like pinned tabs and startup tabs. |
570 Browser* browser = ProcessSpecifiedURLs(urls_to_open, desktop_type); | 603 Browser* browser = ProcessSpecifiedURLs(urls_to_open, desktop_type); |
571 if (browser) { | 604 if (browser) { |
572 AddInfoBarsIfNecessary(browser, is_process_startup); | 605 AddInfoBarsIfNecessary(browser, is_process_startup); |
573 return; | 606 return; |
574 } | 607 } |
575 } | 608 } |
576 } | 609 } |
577 | 610 |
578 // Session startup didn't occur, open the urls. | 611 // 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) | 668 #if defined(OS_MACOSX) |
636 // On Mac, when restoring a session with no windows, suppress the creation | 669 // 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 | 670 // of a new window in the case where the system is launching Chrome via a |
638 // login item or Lion's resume feature. | 671 // login item or Lion's resume feature. |
639 if (base::mac::WasLaunchedAsLoginOrResumeItem()) { | 672 if (base::mac::WasLaunchedAsLoginOrResumeItem()) { |
640 restore_behavior = restore_behavior & | 673 restore_behavior = restore_behavior & |
641 ~SessionRestore::ALWAYS_CREATE_TABBED_BROWSER; | 674 ~SessionRestore::ALWAYS_CREATE_TABBED_BROWSER; |
642 } | 675 } |
643 #endif | 676 #endif |
644 | 677 |
678 // Optionally include the welcome page. | |
679 std::vector<GURL> adjust_urls(urls_to_open); | |
gab
2015/07/09 18:05:13
s/adjust_urls/adjusted_urls/
grt (UTC plus 2)
2015/07/10 15:43:25
Done.
| |
680 if (welcome_run_type_ != WelcomeRunType::NONE) | |
681 adjust_urls.push_back(internals::GetWelcomePageURL()); | |
gab
2015/07/09 18:05:12
Again, why is unconditionally pushing to the back
grt (UTC plus 2)
2015/07/10 15:43:25
Done.
| |
682 | |
645 // The startup code only executes for browsers launched in desktop mode. | 683 // The startup code only executes for browsers launched in desktop mode. |
646 // i.e. HOST_DESKTOP_TYPE_NATIVE. Ash should never get here. | 684 // i.e. HOST_DESKTOP_TYPE_NATIVE. Ash should never get here. |
647 Browser* browser = SessionRestore::RestoreSession( | 685 Browser* browser = SessionRestore::RestoreSession( |
648 profile_, NULL, desktop_type, restore_behavior, | 686 profile_, NULL, desktop_type, restore_behavior, adjust_urls); |
649 urls_to_open); | 687 |
688 RecordWelcomeRunComplete(); | |
650 | 689 |
651 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP); | 690 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP); |
652 return true; | 691 return true; |
653 } | 692 } |
654 | 693 |
655 Browser* browser = ProcessSpecifiedURLs(urls_to_open, desktop_type); | 694 Browser* browser = ProcessSpecifiedURLs(urls_to_open, desktop_type); |
656 if (!browser) | 695 if (!browser) |
657 return false; | 696 return false; |
658 | 697 |
659 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP); | 698 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. | 731 // If urls were specified on the command line, use them. |
693 UrlsToTabs(urls_to_open, &tabs); | 732 UrlsToTabs(urls_to_open, &tabs); |
694 } else if (pref.type == SessionStartupPref::DEFAULT || | 733 } else if (pref.type == SessionStartupPref::DEFAULT || |
695 (is_first_run_ && | 734 (is_first_run_ && |
696 browser_creator_ && !browser_creator_->first_run_tabs_.empty())) { | 735 browser_creator_ && !browser_creator_->first_run_tabs_.empty())) { |
697 std::vector<GURL> urls; | 736 std::vector<GURL> urls; |
698 AddStartupURLs(&urls); | 737 AddStartupURLs(&urls); |
699 UrlsToTabs(urls, &tabs); | 738 UrlsToTabs(urls, &tabs); |
700 } else if (pref.type == SessionStartupPref::URLS && !pref.urls.empty() && | 739 } else if (pref.type == SessionStartupPref::URLS && !pref.urls.empty() && |
701 !HasPendingUncleanExit(profile_)) { | 740 !HasPendingUncleanExit(profile_)) { |
741 // Optionally include the welcome page first. | |
742 if (welcome_run_type_ == WelcomeRunType::ANY_RUN_FIRST) | |
gab
2015/07/09 18:05:12
Why not also FIRST_RUN_FIRST? I guess I don't unde
grt (UTC plus 2)
2015/07/10 15:43:24
Here's the explanation I gave to msw:
I didn't di
| |
743 UrlsToTabs(std::vector<GURL>(1, internals::GetWelcomePageURL()), &tabs); | |
gab
2015/07/09 18:05:12
UrlsToTabs()'s name is misleading :-( -- it's real
grt (UTC plus 2)
2015/07/10 15:43:24
Acknowledged.
| |
702 // Only use the set of urls specified in preferences if nothing was | 744 // 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 | 745 // specified on the command line. Filter out any urls that are to be |
704 // restored by virtue of having been previously pinned. | 746 // restored by virtue of having been previously pinned. |
705 AddUniqueURLs(pref.urls, &tabs); | 747 AddUniqueURLs(pref.urls, &tabs); |
706 } else if (pref.type == SessionStartupPref::HOMEPAGE) { | 748 } else if (pref.type == SessionStartupPref::HOMEPAGE) { |
707 // If 'homepage' selected, either by the user or by a policy, we should | 749 // If 'homepage' selected, either by the user or by a policy, we should |
708 // have migrated them to another value. | 750 // have migrated them to another value. |
709 NOTREACHED() << "SessionStartupPref has deprecated type HOMEPAGE"; | 751 NOTREACHED() << "SessionStartupPref has deprecated type HOMEPAGE"; |
710 } | 752 } |
711 | 753 |
(...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 | 798 // 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 | 799 // |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. | 800 // could be a popup window), we can at least use the profile. |
759 if (!profile_ && browser) | 801 if (!profile_ && browser) |
760 profile_ = browser->profile(); | 802 profile_ = browser->profile(); |
761 | 803 |
762 if (!browser || !browser->is_type_tabbed()) | 804 if (!browser || !browser->is_type_tabbed()) |
763 browser = new Browser(Browser::CreateParams(profile_, desktop_type)); | 805 browser = new Browser(Browser::CreateParams(profile_, desktop_type)); |
764 | 806 |
765 bool first_tab = true; | 807 bool first_tab = true; |
808 const GURL welcome_url(internals::GetWelcomePageURL()); | |
766 ProtocolHandlerRegistry* registry = profile_ ? | 809 ProtocolHandlerRegistry* registry = profile_ ? |
767 ProtocolHandlerRegistryFactory::GetForBrowserContext(profile_) : NULL; | 810 ProtocolHandlerRegistryFactory::GetForBrowserContext(profile_) : NULL; |
768 for (size_t i = 0; i < tabs.size(); ++i) { | 811 for (size_t i = 0; i < tabs.size(); ++i) { |
769 // We skip URLs that we'd have to launch an external protocol handler for. | 812 // 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 | 813 // 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 | 814 // 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. | 815 // asking us to open such a URL should really ask the handler directly. |
773 bool handled_by_chrome = ProfileIOData::IsHandledURL(tabs[i].url) || | 816 bool handled_by_chrome = ProfileIOData::IsHandledURL(tabs[i].url) || |
774 (registry && registry->IsHandledProtocol(tabs[i].url.scheme())); | 817 (registry && registry->IsHandledProtocol(tabs[i].url.scheme())); |
775 if (!process_startup && !handled_by_chrome) | 818 if (!process_startup && !handled_by_chrome) |
(...skipping 10 matching lines...) Expand all Loading... | |
786 params.disposition = first_tab ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; | 829 params.disposition = first_tab ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; |
787 params.tabstrip_add_types = add_types; | 830 params.tabstrip_add_types = add_types; |
788 | 831 |
789 #if defined(ENABLE_RLZ) && !defined(OS_IOS) | 832 #if defined(ENABLE_RLZ) && !defined(OS_IOS) |
790 if (process_startup && google_util::IsGoogleHomePageUrl(tabs[i].url)) { | 833 if (process_startup && google_util::IsGoogleHomePageUrl(tabs[i].url)) { |
791 params.extra_headers = RLZTracker::GetAccessPointHttpHeader( | 834 params.extra_headers = RLZTracker::GetAccessPointHttpHeader( |
792 RLZTracker::ChromeHomePage()); | 835 RLZTracker::ChromeHomePage()); |
793 } | 836 } |
794 #endif // defined(ENABLE_RLZ) && !defined(OS_IOS) | 837 #endif // defined(ENABLE_RLZ) && !defined(OS_IOS) |
795 | 838 |
839 if (welcome_run_type_ != WelcomeRunType::NONE && tabs[i].url == welcome_url) | |
840 RecordWelcomeRunComplete(); | |
841 | |
796 chrome::Navigate(¶ms); | 842 chrome::Navigate(¶ms); |
797 | 843 |
798 first_tab = false; | 844 first_tab = false; |
799 } | 845 } |
800 if (!browser->tab_strip_model()->GetActiveWebContents()) { | 846 if (!browser->tab_strip_model()->GetActiveWebContents()) { |
801 // TODO: this is a work around for 110909. Figure out why it's needed. | 847 // TODO: this is a work around for 110909. Figure out why it's needed. |
802 if (!browser->tab_strip_model()->count()) | 848 if (!browser->tab_strip_model()->count()) |
803 chrome::AddTabAt(browser, GURL(), -1, true); | 849 chrome::AddTabAt(browser, GURL(), -1, true); |
804 else | 850 else |
805 browser->tab_strip_model()->ActivateTabAt(0, false); | 851 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()); | 919 startup_urls->push_back(internals::GetWelcomePageURL()); |
874 } else { | 920 } else { |
875 startup_urls->push_back(*it); | 921 startup_urls->push_back(*it); |
876 } | 922 } |
877 ++it; | 923 ++it; |
878 } | 924 } |
879 browser_creator_->first_run_tabs_.clear(); | 925 browser_creator_->first_run_tabs_.clear(); |
880 } | 926 } |
881 } | 927 } |
882 | 928 |
883 // Otherwise open at least the new tab page (and the welcome page, if this | 929 // 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 | 930 // the first time the browser is being started or the first time following an |
885 // specified on the command line. | 931 // upgrade past Windows 10), or the set of URLs specified on the command line. |
886 if (startup_urls->empty()) { | 932 if (startup_urls->empty()) { |
933 // Put the welcome page before the new tab page on Windows 10. | |
msw
2015/07/09 17:51:31
nit: remove the comment about win10. This code her
grt (UTC plus 2)
2015/07/10 15:43:24
Done.
| |
934 if (welcome_run_type_ == WelcomeRunType::FIRST_RUN_FIRST || | |
935 welcome_run_type_ == WelcomeRunType::ANY_RUN_FIRST) { | |
936 startup_urls->push_back(internals::GetWelcomePageURL()); | |
937 } | |
887 startup_urls->push_back(GURL(chrome::kChromeUINewTabURL)); | 938 startup_urls->push_back(GURL(chrome::kChromeUINewTabURL)); |
888 if (first_run::ShouldShowWelcomePage()) | 939 // Put the welcome page after the new tab page elsewhere. |
940 if (welcome_run_type_ == WelcomeRunType::FIRST_RUN_LAST) | |
889 startup_urls->push_back(internals::GetWelcomePageURL()); | 941 startup_urls->push_back(internals::GetWelcomePageURL()); |
890 } | 942 } |
891 | 943 |
892 if (signin::ShouldShowPromoAtStartup(profile_, is_first_run_)) { | 944 if (signin::ShouldShowPromoAtStartup(profile_, is_first_run_)) { |
893 signin::DidShowPromoAtStartup(profile_); | 945 signin::DidShowPromoAtStartup(profile_); |
894 | 946 |
895 const GURL sync_promo_url = signin::GetPromoURL( | 947 const GURL sync_promo_url = signin::GetPromoURL( |
896 signin_metrics::SOURCE_START_PAGE, false); | 948 signin_metrics::SOURCE_START_PAGE, false); |
897 | 949 |
898 // No need to add if the sync promo is already in the startup list. | 950 // 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 | 962 // behavior is desired because completing or skipping the sync promo |
911 // causes a redirect to the NTP. | 963 // causes a redirect to the NTP. |
912 if (!startup_urls->empty() && | 964 if (!startup_urls->empty() && |
913 startup_urls->at(0) == GURL(chrome::kChromeUINewTabURL)) | 965 startup_urls->at(0) == GURL(chrome::kChromeUINewTabURL)) |
914 startup_urls->at(0) = sync_promo_url; | 966 startup_urls->at(0) = sync_promo_url; |
915 else | 967 else |
916 startup_urls->insert(startup_urls->begin(), sync_promo_url); | 968 startup_urls->insert(startup_urls->begin(), sync_promo_url); |
917 } | 969 } |
918 } | 970 } |
919 } | 971 } |
972 | |
973 void StartupBrowserCreatorImpl::InitializeWelcomeRunType( | |
974 const std::vector<GURL>& urls_to_open) { | |
975 DCHECK_EQ(static_cast<int>(WelcomeRunType::NONE), | |
976 static_cast<int>(welcome_run_type_)); | |
977 #if defined(OS_WIN) | |
978 // Do not welcome if there are any URLs to open. | |
979 if (!urls_to_open.empty()) | |
980 return; | |
981 | |
982 base::win::OSInfo* os_info = base::win::OSInfo::GetInstance(); | |
gab
2015/07/09 18:05:12
const
grt (UTC plus 2)
2015/07/09 18:59:37
which thing, the pointer or the thing being pointe
| |
983 | |
984 // Always welcome on first run. | |
985 if (first_run::ShouldShowWelcomePage()) { | |
986 // First tab for Win10+, last tab otherwise. | |
987 welcome_run_type_ = os_info->version() >= base::win::VERSION_WIN10 | |
988 ? WelcomeRunType::FIRST_RUN_FIRST | |
989 : WelcomeRunType::FIRST_RUN_LAST; | |
990 return; | |
991 } | |
992 | |
993 // Otherwise, do not welcome pre-Win10. | |
994 if (!internals::ShowWelcomePageAfterFirstRun()) | |
995 return; | |
996 | |
997 // Do not welcome if launching into incognito. | |
998 if (IncognitoModePrefs::ShouldLaunchIncognito(command_line_, | |
999 profile_->GetPrefs())) { | |
1000 return; | |
1001 } | |
1002 | |
1003 // Do not welcome if there is no local state (tests). | |
1004 PrefService* local_state = g_browser_process->local_state(); | |
gab
2015/07/09 18:05:12
const
| |
1005 if (!local_state) | |
1006 return; | |
1007 | |
1008 // Do not welcome if disabled by policy or master_preferences. | |
1009 if (!local_state->GetBoolean(prefs::kWelcomePageOnOSUpgradeEnabled)) | |
1010 return; | |
1011 | |
1012 base::win::OSInfo::VersionNumber v(os_info->version_number()); | |
gab
2015/07/09 18:05:12
const
grt (UTC plus 2)
2015/07/09 18:59:37
i find that consting all variables that don't happ
| |
1013 std::string this_os_version(base::StringPrintf("%d.%d", v.major, v.minor)); | |
gab
2015/07/09 18:05:12
const
| |
1014 | |
1015 // Do not welcome if already shown for this OS version. | |
1016 if (local_state->GetString(prefs::kLastWelcomedOSVersion) == this_os_version) | |
1017 return; | |
1018 | |
1019 // Do not welcome if offline. | |
1020 if (net::NetworkChangeNotifier::IsOffline()) | |
1021 return; | |
1022 | |
1023 // Do not welcome if Chrome is the default browser. | |
1024 { | |
1025 // Checking for default browser will touch the filesystem. This phase of | |
1026 // launch is synchronous, so there is no choice to bounce to another thread | |
1027 // now. Since this is the last condition checked before adding the welcome | |
1028 // page, it will be hit only once per user. | |
1029 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
1030 if (ShellIntegration::GetDefaultBrowser() == ShellIntegration::IS_DEFAULT) | |
1031 return; | |
1032 } | |
1033 | |
1034 // Show the welcome page in the first tab. | |
1035 welcome_run_type_ = WelcomeRunType::ANY_RUN_FIRST; | |
1036 #else // OS_WIN | |
1037 // Show the welcome page as the last tab only on first-run. | |
1038 if (first_run::ShouldShowWelcomePage()) | |
1039 welcome_run_type_ = WelcomeRunType::FIRST_RUN_LAST; | |
1040 #endif // !OS_WIN | |
1041 } | |
1042 | |
1043 void StartupBrowserCreatorImpl::RecordWelcomeRunComplete() const { | |
1044 #if defined(OS_WIN) | |
1045 if (welcome_run_type_ == WelcomeRunType::NONE) | |
1046 return; | |
1047 // Remember that the welcome page was added for this OS version. | |
msw
2015/07/09 17:51:31
nit: s/added/shown/
grt (UTC plus 2)
2015/07/09 18:59:38
nice catch. done.
| |
1048 internals::RecordWelcomeRunComplete(); | |
gab
2015/07/09 18:05:12
Should we also reset |welcome_run_type_ = WelcomeR
grt (UTC plus 2)
2015/07/09 18:59:37
Good point. Done.
| |
1049 #endif | |
1050 } | |
OLD | NEW |