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/signin/signin_manager_factory.h" |
12 #include "chrome/browser/ui/browser.h" | |
13 #include "chrome/browser/ui/browser_list.h" | |
14 #include "chrome/browser/ui/chrome_pages.h" | 12 #include "chrome/browser/ui/chrome_pages.h" |
15 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" | 13 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
17 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
18 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
19 #include "chrome/grit/locale_settings.h" | 16 #include "chrome/grit/locale_settings.h" |
20 #include "components/prefs/pref_service.h" | 17 #include "components/prefs/pref_service.h" |
21 #include "components/signin/core/browser/signin_manager.h" | 18 #include "components/signin/core/browser/signin_manager.h" |
22 #include "net/base/url_util.h" | 19 #include "net/base/url_util.h" |
23 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
24 | 21 |
25 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
26 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
27 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
28 #include "chrome/browser/shell_integration.h" | 25 #include "chrome/browser/shell_integration.h" |
29 #endif | 26 #endif |
30 | 27 |
31 StartupTabs StartupTabProviderImpl::GetOnboardingTabs(Profile* profile) const { | 28 StartupTabs StartupTabProviderImpl::GetOnboardingTabs(Profile* profile) const { |
32 // Onboarding content has not been launched on Chrome OS. | |
33 #if defined(OS_CHROMEOS) | |
34 return StartupTabs(); | |
35 #else | |
36 if (!profile) | 29 if (!profile) |
37 return StartupTabs(); | 30 return StartupTabs(); |
38 | 31 |
39 bool is_first_run = first_run::IsChromeFirstRun(); | 32 bool is_first_run = first_run::IsChromeFirstRun(); |
40 PrefService* prefs = profile->GetPrefs(); | 33 PrefService* prefs = profile->GetPrefs(); |
41 bool has_seen_welcome_page = | 34 bool has_seen_welcome_page = |
42 prefs && prefs->GetBoolean(prefs::kHasSeenWelcomePage); | 35 prefs && prefs->GetBoolean(prefs::kHasSeenWelcomePage); |
43 SigninManagerBase* signin_manager = | 36 SigninManagerBase* signin_manager = |
44 SigninManagerFactory::GetForProfile(profile); | 37 SigninManagerFactory::GetForProfile(profile); |
45 bool is_signed_in = signin_manager && signin_manager->IsAuthenticated(); | 38 bool is_signed_in = signin_manager && signin_manager->IsAuthenticated(); |
46 | 39 |
47 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
48 // Windows 10 has unique onboarding policies and content. | 41 // Windows 10 has unique onboarding policies and content. |
49 if (base::win::GetVersion() >= base::win::VERSION_WIN10) { | 42 if (base::win::GetVersion() >= base::win::VERSION_WIN10) { |
50 PrefService* local_state = g_browser_process->local_state(); | 43 PrefService* local_state = g_browser_process->local_state(); |
51 bool has_seen_win10_promo = | 44 bool has_seen_win10_promo = |
52 local_state && local_state->GetBoolean(prefs::kHasSeenWin10PromoPage); | 45 local_state && local_state->GetBoolean(prefs::kHasSeenWin10PromoPage); |
53 bool is_default_browser = | 46 bool is_default_browser = |
54 g_browser_process->CachedDefaultWebClientState() == | 47 g_browser_process->CachedDefaultWebClientState() == |
55 shell_integration::IS_DEFAULT; | 48 shell_integration::IS_DEFAULT; |
56 return CheckWin10OnboardingTabPolicy(is_first_run, has_seen_welcome_page, | 49 return CheckWin10OnboardingTabPolicy(is_first_run, has_seen_welcome_page, |
57 has_seen_win10_promo, is_signed_in, | 50 has_seen_win10_promo, is_signed_in, |
58 is_default_browser); | 51 is_default_browser); |
59 } | 52 } |
60 #endif // defined(OS_WIN) | 53 #endif |
61 | 54 |
62 return CheckStandardOnboardingTabPolicy(is_first_run, has_seen_welcome_page, | 55 return CheckStandardOnboardingTabPolicy(is_first_run, has_seen_welcome_page, |
63 is_signed_in); | 56 is_signed_in); |
64 #endif // defined(OS_CHROMEOS) | |
65 } | 57 } |
66 | 58 |
67 StartupTabs StartupTabProviderImpl::GetDistributionFirstRunTabs( | 59 StartupTabs StartupTabProviderImpl::GetDistributionFirstRunTabs( |
68 StartupBrowserCreator* browser_creator) const { | 60 StartupBrowserCreator* browser_creator) const { |
69 if (!browser_creator) | 61 if (!browser_creator) |
70 return StartupTabs(); | 62 return StartupTabs(); |
71 StartupTabs tabs = CheckMasterPrefsTabPolicy( | 63 StartupTabs tabs = CheckMasterPrefsTabPolicy( |
72 first_run::IsChromeFirstRun(), browser_creator->first_run_tabs_); | 64 first_run::IsChromeFirstRun(), browser_creator->first_run_tabs_); |
73 browser_creator->first_run_tabs_.clear(); | 65 browser_creator->first_run_tabs_.clear(); |
74 return tabs; | 66 return tabs; |
(...skipping 12 matching lines...) Expand all Loading... |
87 const base::CommandLine& command_line, | 79 const base::CommandLine& command_line, |
88 Profile* profile) const { | 80 Profile* profile) const { |
89 return CheckPinnedTabPolicy( | 81 return CheckPinnedTabPolicy( |
90 StartupBrowserCreator::GetSessionStartupPref(command_line, profile), | 82 StartupBrowserCreator::GetSessionStartupPref(command_line, profile), |
91 PinnedTabCodec::ReadPinnedTabs(profile)); | 83 PinnedTabCodec::ReadPinnedTabs(profile)); |
92 } | 84 } |
93 | 85 |
94 StartupTabs StartupTabProviderImpl::GetPreferencesTabs( | 86 StartupTabs StartupTabProviderImpl::GetPreferencesTabs( |
95 const base::CommandLine& command_line, | 87 const base::CommandLine& command_line, |
96 Profile* profile) const { | 88 Profile* profile) const { |
97 // Attempt to find an existing, non-empty tabbed browser for this profile. If | |
98 // one exists, preferences tabs are not used. | |
99 BrowserList* browser_list = BrowserList::GetInstance(); | |
100 auto other_tabbed_browser = std::find_if( | |
101 browser_list->begin(), browser_list->end(), [profile](Browser* browser) { | |
102 return browser->profile() == profile && browser->is_type_tabbed() && | |
103 !browser->tab_strip_model()->empty(); | |
104 }); | |
105 bool profile_has_other_tabbed_browser = | |
106 other_tabbed_browser != browser_list->end(); | |
107 | |
108 return CheckPreferencesTabPolicy( | 89 return CheckPreferencesTabPolicy( |
109 StartupBrowserCreator::GetSessionStartupPref(command_line, profile), | 90 StartupBrowserCreator::GetSessionStartupPref(command_line, profile)); |
110 profile_has_other_tabbed_browser); | |
111 } | 91 } |
112 | 92 |
113 StartupTabs StartupTabProviderImpl::GetNewTabPageTabs( | 93 StartupTabs StartupTabProviderImpl::GetNewTabPageTabs( |
114 const base::CommandLine& command_line, | 94 const base::CommandLine& command_line, |
115 Profile* profile) const { | 95 Profile* profile) const { |
116 return CheckNewTabPageTabPolicy( | 96 return CheckNewTabPageTabPolicy( |
117 StartupBrowserCreator::GetSessionStartupPref(command_line, profile)); | 97 StartupBrowserCreator::GetSessionStartupPref(command_line, profile)); |
118 } | 98 } |
119 | 99 |
120 // static | 100 // static |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 // static | 160 // static |
181 StartupTabs StartupTabProviderImpl::CheckPinnedTabPolicy( | 161 StartupTabs StartupTabProviderImpl::CheckPinnedTabPolicy( |
182 const SessionStartupPref& pref, | 162 const SessionStartupPref& pref, |
183 const StartupTabs& pinned_tabs) { | 163 const StartupTabs& pinned_tabs) { |
184 return (pref.type == SessionStartupPref::Type::LAST) ? StartupTabs() | 164 return (pref.type == SessionStartupPref::Type::LAST) ? StartupTabs() |
185 : pinned_tabs; | 165 : pinned_tabs; |
186 } | 166 } |
187 | 167 |
188 // static | 168 // static |
189 StartupTabs StartupTabProviderImpl::CheckPreferencesTabPolicy( | 169 StartupTabs StartupTabProviderImpl::CheckPreferencesTabPolicy( |
190 const SessionStartupPref& pref, | 170 const SessionStartupPref& pref) { |
191 bool profile_has_other_tabbed_browser) { | |
192 StartupTabs tabs; | 171 StartupTabs tabs; |
193 if (pref.type == SessionStartupPref::Type::URLS && !pref.urls.empty() && | 172 if (pref.type == SessionStartupPref::Type::URLS && !pref.urls.empty()) { |
194 !profile_has_other_tabbed_browser) { | |
195 for (const auto& url : pref.urls) | 173 for (const auto& url : pref.urls) |
196 tabs.push_back(StartupTab(url, false)); | 174 tabs.push_back(StartupTab(url, false)); |
197 } | 175 } |
198 return tabs; | 176 return tabs; |
199 } | 177 } |
200 | 178 |
201 // static | 179 // static |
202 StartupTabs StartupTabProviderImpl::CheckNewTabPageTabPolicy( | 180 StartupTabs StartupTabProviderImpl::CheckNewTabPageTabPolicy( |
203 const SessionStartupPref& pref) { | 181 const SessionStartupPref& pref) { |
204 StartupTabs tabs; | 182 StartupTabs tabs; |
(...skipping 19 matching lines...) Expand all Loading... |
224 ? net::AppendQueryParameter(url, "text", "faster") | 202 ? net::AppendQueryParameter(url, "text", "faster") |
225 : url; | 203 : url; |
226 } | 204 } |
227 #endif | 205 #endif |
228 | 206 |
229 // static | 207 // static |
230 GURL StartupTabProviderImpl::GetTriggeredResetSettingsUrl() { | 208 GURL StartupTabProviderImpl::GetTriggeredResetSettingsUrl() { |
231 return GURL( | 209 return GURL( |
232 chrome::GetSettingsUrl(chrome::kTriggeredResetProfileSettingsSubPage)); | 210 chrome::GetSettingsUrl(chrome::kTriggeredResetProfileSettingsSubPage)); |
233 } | 211 } |
OLD | NEW |