Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_tab_provider.h" | 5 #include "chrome/browser/ui/startup/startup_tab_provider.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "chrome/browser/first_run/first_run.h" | 8 #include "chrome/browser/first_run/first_run.h" |
| 9 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h" | 9 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h" |
| 10 #include "chrome/browser/profile_resetter/triggered_profile_resetter_factory.h" | 10 #include "chrome/browser/profile_resetter/triggered_profile_resetter_factory.h" |
| 11 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 11 #include "chrome/browser/ui/chrome_pages.h" | 12 #include "chrome/browser/ui/chrome_pages.h" |
| 12 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" | 13 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" |
| 14 #include "chrome/common/pref_names.h" | |
| 13 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 14 #include "chrome/grit/locale_settings.h" | 16 #include "chrome/grit/locale_settings.h" |
| 17 #include "components/prefs/pref_service.h" | |
| 18 #include "components/signin/core/browser/signin_manager.h" | |
| 15 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 16 | 20 |
| 17 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
| 18 #include "base/win/windows_version.h" | 22 #include "base/win/windows_version.h" |
| 19 #endif | 23 #endif |
| 20 | 24 |
| 21 StartupTabs StartupTabProviderImpl::GetOnboardingTabs() const { | 25 namespace { |
| 26 constexpr char kVersionWelcomeIntroduced[] = "55.0.0.0"; | |
|
Peter Kasting
2016/11/10 05:26:43
I'm not a big fan of a version-number-based check
tmartino
2016/11/15 00:16:30
Agreed on the structural changes, but I've looked
Peter Kasting
2016/11/15 00:32:06
Sorry, I think you parsed the phrase differently t
| |
| 27 } // namespace | |
| 28 | |
| 29 StartupTabs StartupTabProviderImpl::GetOnboardingTabs(Profile* profile) const { | |
| 22 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
| 23 // Windows 10 has unique onboarding policies and content. | 31 // Windows 10 has unique onboarding policies and content. |
| 24 if (base::win::GetVersion() >= base::win::VERSION_WIN10) { | 32 if (base::win::GetVersion() >= base::win::VERSION_WIN10) { |
| 25 // TODO(tmartino): * Add a function, GetWin10SystemState, which gathers | 33 // TODO(tmartino): * Add a function, GetWin10SystemState, which gathers |
| 26 // system state relevant to Win10 Onboarding and returns | 34 // system state relevant to Win10 Onboarding and returns |
| 27 // a struct. | 35 // a struct. |
| 28 // * Add a function, CheckWin10OnboardingTabPolicy, which | 36 // * Add a function, CheckWin10OnboardingTabPolicy, which |
| 29 // takes such a struct as input and returns StartupTabs. | 37 // takes such a struct as input and returns StartupTabs. |
| 30 return StartupTabs(); | 38 return StartupTabs(); |
| 31 } | 39 } |
| 32 #endif | 40 #endif |
| 33 | 41 |
| 34 return CheckStandardOnboardingTabPolicy(first_run::IsChromeFirstRun()); | 42 if (!profile) |
| 43 return StartupTabs(); | |
| 44 | |
| 45 PrefService* prefs = profile->GetPrefs(); | |
| 46 bool has_seen_welcome = prefs && prefs->GetBoolean(prefs::kHasSeenWelcomeUI); | |
| 47 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile); | |
| 48 bool is_signed_in = signin_manager && signin_manager->IsAuthenticated(); | |
| 49 bool created_after_welcome_ui = | |
| 50 profile->WasCreatedByVersionOrLater(kVersionWelcomeIntroduced); | |
| 51 | |
| 52 return CheckStandardOnboardingTabPolicy(first_run::IsChromeFirstRun(), | |
| 53 has_seen_welcome, is_signed_in, | |
| 54 created_after_welcome_ui); | |
| 35 } | 55 } |
| 36 | 56 |
| 37 StartupTabs StartupTabProviderImpl::GetDistributionFirstRunTabs( | 57 StartupTabs StartupTabProviderImpl::GetDistributionFirstRunTabs( |
| 38 StartupBrowserCreator* browser_creator) const { | 58 StartupBrowserCreator* browser_creator) const { |
| 39 if (!browser_creator) | 59 if (!browser_creator) |
| 40 return StartupTabs(); | 60 return StartupTabs(); |
| 41 StartupTabs tabs = CheckMasterPrefsTabPolicy( | 61 StartupTabs tabs = CheckMasterPrefsTabPolicy( |
| 42 first_run::IsChromeFirstRun(), browser_creator->first_run_tabs_); | 62 first_run::IsChromeFirstRun(), browser_creator->first_run_tabs_); |
| 43 browser_creator->first_run_tabs_.clear(); | 63 browser_creator->first_run_tabs_.clear(); |
| 44 return tabs; | 64 return tabs; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 70 | 90 |
| 71 StartupTabs StartupTabProviderImpl::GetNewTabPageTabs( | 91 StartupTabs StartupTabProviderImpl::GetNewTabPageTabs( |
| 72 const base::CommandLine& command_line, | 92 const base::CommandLine& command_line, |
| 73 Profile* profile) const { | 93 Profile* profile) const { |
| 74 return CheckNewTabPageTabPolicy( | 94 return CheckNewTabPageTabPolicy( |
| 75 StartupBrowserCreator::GetSessionStartupPref(command_line, profile)); | 95 StartupBrowserCreator::GetSessionStartupPref(command_line, profile)); |
| 76 } | 96 } |
| 77 | 97 |
| 78 // static | 98 // static |
| 79 StartupTabs StartupTabProviderImpl::CheckStandardOnboardingTabPolicy( | 99 StartupTabs StartupTabProviderImpl::CheckStandardOnboardingTabPolicy( |
| 80 bool is_first_run) { | 100 bool is_first_run, |
| 101 bool has_seen_welcome, | |
| 102 bool is_signed_in, | |
| 103 bool created_after_welcome_ui) { | |
| 81 StartupTabs tabs; | 104 StartupTabs tabs; |
| 82 if (is_first_run) | 105 if (!has_seen_welcome && created_after_welcome_ui && !is_signed_in) |
| 83 tabs.emplace_back(GetWelcomePageUrl(), false); | 106 tabs.emplace_back(GetWelcomePageUrl(!is_first_run), false); |
| 84 return tabs; | 107 return tabs; |
| 85 } | 108 } |
| 86 | 109 |
| 87 // static | 110 // static |
| 88 StartupTabs StartupTabProviderImpl::CheckMasterPrefsTabPolicy( | 111 StartupTabs StartupTabProviderImpl::CheckMasterPrefsTabPolicy( |
| 89 bool is_first_run, | 112 bool is_first_run, |
| 90 const std::vector<GURL>& first_run_tabs) { | 113 const std::vector<GURL>& first_run_tabs) { |
| 91 // Constants: Magic words used by Master Preferences files in place of a URL | 114 // Constants: Magic words used by Master Preferences files in place of a URL |
| 92 // host to indicate that internal pages should appear on first run. | 115 // host to indicate that internal pages should appear on first run. |
| 93 static constexpr char kNewTabUrlHost[] = "new_tab_page"; | 116 static constexpr char kNewTabUrlHost[] = "new_tab_page"; |
| 94 static constexpr char kWelcomePageUrlHost[] = "welcome_page"; | 117 static constexpr char kWelcomePageUrlHost[] = "welcome_page"; |
| 95 | 118 |
| 96 StartupTabs tabs; | 119 StartupTabs tabs; |
| 97 if (is_first_run) { | 120 if (is_first_run) { |
| 98 tabs.reserve(first_run_tabs.size()); | 121 tabs.reserve(first_run_tabs.size()); |
| 99 for (GURL url : first_run_tabs) { | 122 for (GURL url : first_run_tabs) { |
| 100 if (url.host() == kNewTabUrlHost) | 123 if (url.host() == kNewTabUrlHost) |
| 101 url = GURL(chrome::kChromeUINewTabURL); | 124 url = GURL(chrome::kChromeUINewTabURL); |
| 102 else if (url.host() == kWelcomePageUrlHost) | 125 else if (url.host() == kWelcomePageUrlHost) |
| 103 url = GetWelcomePageUrl(); | 126 url = GetWelcomePageUrl(false); |
| 104 tabs.emplace_back(url, false); | 127 tabs.emplace_back(url, false); |
| 105 } | 128 } |
| 106 } | 129 } |
| 107 return tabs; | 130 return tabs; |
| 108 } | 131 } |
| 109 | 132 |
| 110 // static | 133 // static |
| 111 StartupTabs StartupTabProviderImpl::CheckResetTriggerTabPolicy( | 134 StartupTabs StartupTabProviderImpl::CheckResetTriggerTabPolicy( |
| 112 bool profile_has_trigger) { | 135 bool profile_has_trigger) { |
| 113 StartupTabs tabs; | 136 StartupTabs tabs; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 138 // static | 161 // static |
| 139 StartupTabs StartupTabProviderImpl::CheckNewTabPageTabPolicy( | 162 StartupTabs StartupTabProviderImpl::CheckNewTabPageTabPolicy( |
| 140 const SessionStartupPref& pref) { | 163 const SessionStartupPref& pref) { |
| 141 StartupTabs tabs; | 164 StartupTabs tabs; |
| 142 if (pref.type != SessionStartupPref::Type::LAST) | 165 if (pref.type != SessionStartupPref::Type::LAST) |
| 143 tabs.emplace_back(GURL(chrome::kChromeUINewTabURL), false); | 166 tabs.emplace_back(GURL(chrome::kChromeUINewTabURL), false); |
| 144 return tabs; | 167 return tabs; |
| 145 } | 168 } |
| 146 | 169 |
| 147 // static | 170 // static |
| 148 GURL StartupTabProviderImpl::GetWelcomePageUrl() { | 171 GURL StartupTabProviderImpl::GetWelcomePageUrl(bool use_later_run_variant) { |
| 149 return GURL(chrome::kChromeUIWelcomeURL); | 172 std::string url(chrome::kChromeUIWelcomeURL); |
| 173 if (use_later_run_variant) | |
| 174 url.append("?variant=everywhere"); | |
|
Peter Kasting
2016/11/10 05:26:43
Nit: Safer in case someone changes the welcome URL
tmartino
2016/11/15 00:16:30
Done
| |
| 175 return GURL(url); | |
| 150 } | 176 } |
| 151 | 177 |
| 152 // static | 178 // static |
| 153 GURL StartupTabProviderImpl::GetTriggeredResetSettingsUrl() { | 179 GURL StartupTabProviderImpl::GetTriggeredResetSettingsUrl() { |
| 154 return GURL( | 180 return GURL( |
| 155 chrome::GetSettingsUrl(chrome::kTriggeredResetProfileSettingsSubPage)); | 181 chrome::GetSettingsUrl(chrome::kTriggeredResetProfileSettingsSubPage)); |
| 156 } | 182 } |
| OLD | NEW |