| 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 "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "chrome/browser/first_run/first_run.h" | 9 #include "chrome/browser/first_run/first_run.h" |
| 10 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h" | 10 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 local_state && | 59 local_state && |
| 60 local_state->IsManagedPreference( | 60 local_state->IsManagedPreference( |
| 61 prefs::kDefaultBrowserSettingEnabled) && | 61 prefs::kDefaultBrowserSettingEnabled) && |
| 62 !local_state->GetBoolean(prefs::kDefaultBrowserSettingEnabled); | 62 !local_state->GetBoolean(prefs::kDefaultBrowserSettingEnabled); |
| 63 bool set_default_browser_allowed = | 63 bool set_default_browser_allowed = |
| 64 !disabled_by_enterprise_policy && | 64 !disabled_by_enterprise_policy && |
| 65 shell_integration::CanSetAsDefaultBrowser(); | 65 shell_integration::CanSetAsDefaultBrowser(); |
| 66 bool is_default_browser = | 66 bool is_default_browser = |
| 67 g_browser_process->CachedDefaultWebClientState() == | 67 g_browser_process->CachedDefaultWebClientState() == |
| 68 shell_integration::IS_DEFAULT; | 68 shell_integration::IS_DEFAULT; |
| 69 return CheckWin10OnboardingTabPolicy( | 69 return GetWin10OnboardingTabsForState( |
| 70 is_first_run, has_seen_welcome_page, has_seen_win10_promo, is_signed_in, | 70 is_first_run, has_seen_welcome_page, has_seen_win10_promo, is_signed_in, |
| 71 set_default_browser_allowed, is_default_browser, is_supervised_user); | 71 set_default_browser_allowed, is_default_browser, is_supervised_user); |
| 72 } | 72 } |
| 73 #endif // defined(OS_WIN) | 73 #endif // defined(OS_WIN) |
| 74 | 74 |
| 75 return CheckStandardOnboardingTabPolicy(is_first_run, has_seen_welcome_page, | 75 return GetStandardOnboardingTabsForState(is_first_run, has_seen_welcome_page, |
| 76 is_signed_in, is_supervised_user); | 76 is_signed_in, is_supervised_user); |
| 77 #endif // defined(OS_CHROMEOS) | 77 #endif // defined(OS_CHROMEOS) |
| 78 } | 78 } |
| 79 | 79 |
| 80 StartupTabs StartupTabProviderImpl::GetDistributionFirstRunTabs( | 80 StartupTabs StartupTabProviderImpl::GetDistributionFirstRunTabs( |
| 81 StartupBrowserCreator* browser_creator) const { | 81 StartupBrowserCreator* browser_creator) const { |
| 82 if (!browser_creator) | 82 if (!browser_creator) |
| 83 return StartupTabs(); | 83 return StartupTabs(); |
| 84 StartupTabs tabs = CheckMasterPrefsTabPolicy( | 84 StartupTabs tabs = GetMasterPrefsTabsForState( |
| 85 first_run::IsChromeFirstRun(), browser_creator->first_run_tabs_); | 85 first_run::IsChromeFirstRun(), browser_creator->first_run_tabs_); |
| 86 browser_creator->first_run_tabs_.clear(); | 86 browser_creator->first_run_tabs_.clear(); |
| 87 return tabs; | 87 return tabs; |
| 88 } | 88 } |
| 89 | 89 |
| 90 StartupTabs StartupTabProviderImpl::GetResetTriggerTabs( | 90 StartupTabs StartupTabProviderImpl::GetResetTriggerTabs( |
| 91 Profile* profile) const { | 91 Profile* profile) const { |
| 92 auto* triggered_profile_resetter = | 92 auto* triggered_profile_resetter = |
| 93 TriggeredProfileResetterFactory::GetForBrowserContext(profile); | 93 TriggeredProfileResetterFactory::GetForBrowserContext(profile); |
| 94 bool has_reset_trigger = triggered_profile_resetter && | 94 bool has_reset_trigger = triggered_profile_resetter && |
| 95 triggered_profile_resetter->HasResetTrigger(); | 95 triggered_profile_resetter->HasResetTrigger(); |
| 96 return CheckResetTriggerTabPolicy(has_reset_trigger); | 96 return GetResetTriggerTabsForState(has_reset_trigger); |
| 97 } | 97 } |
| 98 | 98 |
| 99 StartupTabs StartupTabProviderImpl::GetPinnedTabs( | 99 StartupTabs StartupTabProviderImpl::GetPinnedTabs( |
| 100 const base::CommandLine& command_line, | 100 const base::CommandLine& command_line, |
| 101 Profile* profile) const { | 101 Profile* profile) const { |
| 102 return CheckPinnedTabPolicy( | 102 return GetPinnedTabsForState( |
| 103 StartupBrowserCreator::GetSessionStartupPref(command_line, profile), | 103 StartupBrowserCreator::GetSessionStartupPref(command_line, profile), |
| 104 PinnedTabCodec::ReadPinnedTabs(profile)); | 104 PinnedTabCodec::ReadPinnedTabs(profile)); |
| 105 } | 105 } |
| 106 | 106 |
| 107 StartupTabs StartupTabProviderImpl::GetPreferencesTabs( | 107 StartupTabs StartupTabProviderImpl::GetPreferencesTabs( |
| 108 const base::CommandLine& command_line, | 108 const base::CommandLine& command_line, |
| 109 Profile* profile) const { | 109 Profile* profile) const { |
| 110 // Attempt to find an existing, non-empty tabbed browser for this profile. If | 110 // Attempt to find an existing, non-empty tabbed browser for this profile. If |
| 111 // one exists, preferences tabs are not used. | 111 // one exists, preferences tabs are not used. |
| 112 BrowserList* browser_list = BrowserList::GetInstance(); | 112 BrowserList* browser_list = BrowserList::GetInstance(); |
| 113 auto other_tabbed_browser = std::find_if( | 113 auto other_tabbed_browser = std::find_if( |
| 114 browser_list->begin(), browser_list->end(), [profile](Browser* browser) { | 114 browser_list->begin(), browser_list->end(), [profile](Browser* browser) { |
| 115 return browser->profile() == profile && browser->is_type_tabbed() && | 115 return browser->profile() == profile && browser->is_type_tabbed() && |
| 116 !browser->tab_strip_model()->empty(); | 116 !browser->tab_strip_model()->empty(); |
| 117 }); | 117 }); |
| 118 bool profile_has_other_tabbed_browser = | 118 bool profile_has_other_tabbed_browser = |
| 119 other_tabbed_browser != browser_list->end(); | 119 other_tabbed_browser != browser_list->end(); |
| 120 | 120 |
| 121 return CheckPreferencesTabPolicy( | 121 return GetPreferencesTabsForState( |
| 122 StartupBrowserCreator::GetSessionStartupPref(command_line, profile), | 122 StartupBrowserCreator::GetSessionStartupPref(command_line, profile), |
| 123 profile_has_other_tabbed_browser); | 123 profile_has_other_tabbed_browser); |
| 124 } | 124 } |
| 125 | 125 |
| 126 StartupTabs StartupTabProviderImpl::GetNewTabPageTabs( | 126 StartupTabs StartupTabProviderImpl::GetNewTabPageTabs( |
| 127 const base::CommandLine& command_line, | 127 const base::CommandLine& command_line, |
| 128 Profile* profile) const { | 128 Profile* profile) const { |
| 129 return CheckNewTabPageTabPolicy( | 129 return GetNewTabPageTabsForState( |
| 130 StartupBrowserCreator::GetSessionStartupPref(command_line, profile)); | 130 StartupBrowserCreator::GetSessionStartupPref(command_line, profile)); |
| 131 } | 131 } |
| 132 | 132 |
| 133 // static | 133 // static |
| 134 StartupTabs StartupTabProviderImpl::CheckStandardOnboardingTabPolicy( | 134 StartupTabs StartupTabProviderImpl::GetStandardOnboardingTabsForState( |
| 135 bool is_first_run, | 135 bool is_first_run, |
| 136 bool has_seen_welcome_page, | 136 bool has_seen_welcome_page, |
| 137 bool is_signed_in, | 137 bool is_signed_in, |
| 138 bool is_supervised_user) { | 138 bool is_supervised_user) { |
| 139 StartupTabs tabs; | 139 StartupTabs tabs; |
| 140 if (!has_seen_welcome_page && !is_signed_in && !is_supervised_user) | 140 if (!has_seen_welcome_page && !is_signed_in && !is_supervised_user) |
| 141 tabs.emplace_back(GetWelcomePageUrl(!is_first_run), false); | 141 tabs.emplace_back(GetWelcomePageUrl(!is_first_run), false); |
| 142 return tabs; | 142 return tabs; |
| 143 } | 143 } |
| 144 | 144 |
| 145 #if defined(OS_WIN) | 145 #if defined(OS_WIN) |
| 146 // static | 146 // static |
| 147 StartupTabs StartupTabProviderImpl::CheckWin10OnboardingTabPolicy( | 147 StartupTabs StartupTabProviderImpl::GetWin10OnboardingTabsForState( |
| 148 bool is_first_run, | 148 bool is_first_run, |
| 149 bool has_seen_welcome_page, | 149 bool has_seen_welcome_page, |
| 150 bool has_seen_win10_promo, | 150 bool has_seen_win10_promo, |
| 151 bool is_signed_in, | 151 bool is_signed_in, |
| 152 bool set_default_browser_allowed, | 152 bool set_default_browser_allowed, |
| 153 bool is_default_browser, | 153 bool is_default_browser, |
| 154 bool is_supervised_user) { | 154 bool is_supervised_user) { |
| 155 StartupTabs tabs; | 155 StartupTabs tabs; |
| 156 | 156 |
| 157 if (is_supervised_user) | 157 if (is_supervised_user) |
| 158 return tabs; | 158 return tabs; |
| 159 | 159 |
| 160 if (set_default_browser_allowed && !has_seen_win10_promo && | 160 if (set_default_browser_allowed && !has_seen_win10_promo && |
| 161 !is_default_browser) { | 161 !is_default_browser) { |
| 162 tabs.emplace_back(GetWin10WelcomePageUrl(!is_first_run), false); | 162 tabs.emplace_back(GetWin10WelcomePageUrl(!is_first_run), false); |
| 163 } else if (!has_seen_welcome_page && !is_signed_in) { | 163 } else if (!has_seen_welcome_page && !is_signed_in) { |
| 164 tabs.emplace_back(GetWelcomePageUrl(!is_first_run), false); | 164 tabs.emplace_back(GetWelcomePageUrl(!is_first_run), false); |
| 165 } | 165 } |
| 166 return tabs; | 166 return tabs; |
| 167 } | 167 } |
| 168 #endif | 168 #endif |
| 169 | 169 |
| 170 // static | 170 // static |
| 171 StartupTabs StartupTabProviderImpl::CheckMasterPrefsTabPolicy( | 171 StartupTabs StartupTabProviderImpl::GetMasterPrefsTabsForState( |
| 172 bool is_first_run, | 172 bool is_first_run, |
| 173 const std::vector<GURL>& first_run_tabs) { | 173 const std::vector<GURL>& first_run_tabs) { |
| 174 // Constants: Magic words used by Master Preferences files in place of a URL | 174 // Constants: Magic words used by Master Preferences files in place of a URL |
| 175 // host to indicate that internal pages should appear on first run. | 175 // host to indicate that internal pages should appear on first run. |
| 176 static constexpr char kNewTabUrlHost[] = "new_tab_page"; | 176 static constexpr char kNewTabUrlHost[] = "new_tab_page"; |
| 177 static constexpr char kWelcomePageUrlHost[] = "welcome_page"; | 177 static constexpr char kWelcomePageUrlHost[] = "welcome_page"; |
| 178 | 178 |
| 179 StartupTabs tabs; | 179 StartupTabs tabs; |
| 180 if (is_first_run) { | 180 if (is_first_run) { |
| 181 tabs.reserve(first_run_tabs.size()); | 181 tabs.reserve(first_run_tabs.size()); |
| 182 for (GURL url : first_run_tabs) { | 182 for (GURL url : first_run_tabs) { |
| 183 if (url.host_piece() == kNewTabUrlHost) | 183 if (url.host_piece() == kNewTabUrlHost) |
| 184 url = GURL(chrome::kChromeUINewTabURL); | 184 url = GURL(chrome::kChromeUINewTabURL); |
| 185 else if (url.host_piece() == kWelcomePageUrlHost) | 185 else if (url.host_piece() == kWelcomePageUrlHost) |
| 186 url = GetWelcomePageUrl(false); | 186 url = GetWelcomePageUrl(false); |
| 187 tabs.emplace_back(url, false); | 187 tabs.emplace_back(url, false); |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 return tabs; | 190 return tabs; |
| 191 } | 191 } |
| 192 | 192 |
| 193 // static | 193 // static |
| 194 StartupTabs StartupTabProviderImpl::CheckResetTriggerTabPolicy( | 194 StartupTabs StartupTabProviderImpl::GetResetTriggerTabsForState( |
| 195 bool profile_has_trigger) { | 195 bool profile_has_trigger) { |
| 196 StartupTabs tabs; | 196 StartupTabs tabs; |
| 197 if (profile_has_trigger) | 197 if (profile_has_trigger) |
| 198 tabs.emplace_back(GetTriggeredResetSettingsUrl(), false); | 198 tabs.emplace_back(GetTriggeredResetSettingsUrl(), false); |
| 199 return tabs; | 199 return tabs; |
| 200 } | 200 } |
| 201 | 201 |
| 202 // static | 202 // static |
| 203 StartupTabs StartupTabProviderImpl::CheckPinnedTabPolicy( | 203 StartupTabs StartupTabProviderImpl::GetPinnedTabsForState( |
| 204 const SessionStartupPref& pref, | 204 const SessionStartupPref& pref, |
| 205 const StartupTabs& pinned_tabs) { | 205 const StartupTabs& pinned_tabs) { |
| 206 return (pref.type == SessionStartupPref::Type::LAST) ? StartupTabs() | 206 return (pref.type == SessionStartupPref::Type::LAST) ? StartupTabs() |
| 207 : pinned_tabs; | 207 : pinned_tabs; |
| 208 } | 208 } |
| 209 | 209 |
| 210 // static | 210 // static |
| 211 StartupTabs StartupTabProviderImpl::CheckPreferencesTabPolicy( | 211 StartupTabs StartupTabProviderImpl::GetPreferencesTabsForState( |
| 212 const SessionStartupPref& pref, | 212 const SessionStartupPref& pref, |
| 213 bool profile_has_other_tabbed_browser) { | 213 bool profile_has_other_tabbed_browser) { |
| 214 StartupTabs tabs; | 214 StartupTabs tabs; |
| 215 if (pref.type == SessionStartupPref::Type::URLS && !pref.urls.empty() && | 215 if (pref.type == SessionStartupPref::Type::URLS && !pref.urls.empty() && |
| 216 !profile_has_other_tabbed_browser) { | 216 !profile_has_other_tabbed_browser) { |
| 217 for (const auto& url : pref.urls) | 217 for (const auto& url : pref.urls) |
| 218 tabs.push_back(StartupTab(url, false)); | 218 tabs.push_back(StartupTab(url, false)); |
| 219 } | 219 } |
| 220 return tabs; | 220 return tabs; |
| 221 } | 221 } |
| 222 | 222 |
| 223 // static | 223 // static |
| 224 StartupTabs StartupTabProviderImpl::CheckNewTabPageTabPolicy( | 224 StartupTabs StartupTabProviderImpl::GetNewTabPageTabsForState( |
| 225 const SessionStartupPref& pref) { | 225 const SessionStartupPref& pref) { |
| 226 StartupTabs tabs; | 226 StartupTabs tabs; |
| 227 if (pref.type != SessionStartupPref::Type::LAST) | 227 if (pref.type != SessionStartupPref::Type::LAST) |
| 228 tabs.emplace_back(GURL(chrome::kChromeUINewTabURL), false); | 228 tabs.emplace_back(GURL(chrome::kChromeUINewTabURL), false); |
| 229 return tabs; | 229 return tabs; |
| 230 } | 230 } |
| 231 | 231 |
| 232 // static | 232 // static |
| 233 GURL StartupTabProviderImpl::GetWelcomePageUrl(bool use_later_run_variant) { | 233 GURL StartupTabProviderImpl::GetWelcomePageUrl(bool use_later_run_variant) { |
| 234 // Record that the Welcome page was added to the startup url list. | 234 // Record that the Welcome page was added to the startup url list. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 248 ? net::AppendQueryParameter(url, "text", "faster") | 248 ? net::AppendQueryParameter(url, "text", "faster") |
| 249 : url; | 249 : url; |
| 250 } | 250 } |
| 251 #endif | 251 #endif |
| 252 | 252 |
| 253 // static | 253 // static |
| 254 GURL StartupTabProviderImpl::GetTriggeredResetSettingsUrl() { | 254 GURL StartupTabProviderImpl::GetTriggeredResetSettingsUrl() { |
| 255 return GURL( | 255 return GURL( |
| 256 chrome::GetSettingsUrl(chrome::kTriggeredResetProfileSettingsSubPage)); | 256 chrome::GetSettingsUrl(chrome::kTriggeredResetProfileSettingsSubPage)); |
| 257 } | 257 } |
| OLD | NEW |