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