OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/startup/startup_tab_provider.h" | |
6 | |
7 #include "build/build_config.h" | |
8 #include "chrome/browser/first_run/first_run.h" | |
9 #include "chrome/browser/ui/chrome_pages.h" | |
10 #include "chrome/common/url_constants.h" | |
11 #include "chrome/grit/locale_settings.h" | |
12 #include "ui/base/l10n/l10n_util.h" | |
13 | |
14 #if defined(OS_WIN) | |
15 #include "base/win/windows_version.h" | |
16 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h" | |
17 #include "chrome/browser/profile_resetter/triggered_profile_resetter_factory.h" | |
18 #endif | |
19 | |
20 namespace { | |
21 // Constants: Magic words used by Master Preferences files in place of a URL | |
22 // host to indicate that internal pages should appear on first run. | |
23 constexpr char kNewTabUrlHost[] = "new_tab_page"; | |
24 constexpr char kWelcomePageUrlHost[] = "welcome_page"; | |
25 } // namespace | |
26 | |
27 bool StartupTabProviderImpl::AddOnboardingTabs(StartupTabs* output) const { | |
28 #if defined(OS_WIN) | |
29 // Windows 10 has unique onboarding policies and content. | |
30 if (base::win::GetVersion() >= base::win::VERSION_WIN10) { | |
31 // TODO(tmartino): * Add a function, GetWin10SystemState, which gathers | |
32 // system state relevant to Win10 Onboarding and returns | |
33 // a struct. | |
34 // * Add a function, CheckWin10OnboardingTabPolicy, which | |
35 // takes such a struct as input and returns StartupTabs. | |
36 return false; | |
37 } | |
38 #endif | |
39 | |
40 return CheckStandardOnboardingTabPolicy(first_run::IsChromeFirstRun(), | |
41 output); | |
42 } | |
43 | |
44 bool StartupTabProviderImpl::AddDistributionFirstRunTabs( | |
45 StartupBrowserCreator* browser_creator, | |
46 StartupTabs* output) const { | |
47 if (!browser_creator) | |
48 return false; | |
49 bool added_tabs = CheckMasterPrefsTabPolicy( | |
50 first_run::IsChromeFirstRun(), browser_creator->first_run_tabs_, output); | |
51 browser_creator->first_run_tabs_.clear(); | |
52 return added_tabs; | |
53 } | |
54 | |
55 bool StartupTabProviderImpl::AddResetTriggerTabs(Profile* profile, | |
56 StartupTabs* output) const { | |
57 bool has_reset_trigger = false; | |
58 #if defined(OS_WIN) | |
59 TriggeredProfileResetter* triggered_profile_resetter = | |
60 TriggeredProfileResetterFactory::GetForBrowserContext(profile_); | |
61 if (triggered_profile_resetter) | |
62 has_reset_trigger = triggered_profile_resetter->HasResetTrigger(); | |
63 #endif // defined(OS_WIN) | |
64 return CheckResetTriggerTabPolicy(has_reset_trigger, output); | |
65 } | |
66 | |
67 bool StartupTabProviderImpl::AddPinnedTabs(StartupTabs* output) const { | |
68 // TODO(tmartino): Copy/clean up logic from | |
69 // StartupBrowserCreatorImpl::ProcessSpecifiedUrls. | |
70 return false; | |
71 } | |
72 | |
73 bool StartupTabProviderImpl::AddPreferencesTabs(StartupTabs* output) const { | |
74 // TODO(tmartino): Copy/clean up logic from | |
75 // StartupBrowserCreatorImpl::ProcessStartupUrls. | |
76 return false; | |
77 } | |
78 | |
79 // static | |
80 bool StartupTabProviderImpl::CheckStandardOnboardingTabPolicy( | |
81 bool is_first_run, | |
82 StartupTabs* output) { | |
83 if (is_first_run) { | |
84 output->push_back(StartupTab(GetWelcomePageUrl(), false)); | |
85 return true; | |
86 } | |
87 return false; | |
88 } | |
89 | |
90 // static | |
91 bool StartupTabProviderImpl::CheckMasterPrefsTabPolicy( | |
92 bool is_first_run, | |
93 const std::vector<GURL>& first_run_tabs, | |
94 StartupTabs* output) { | |
95 size_t initial_size = output->size(); | |
96 if (is_first_run) { | |
97 output->reserve(initial_size + first_run_tabs.size()); | |
98 for (const GURL& url : first_run_tabs) { | |
99 if (url.host() == kNewTabUrlHost) { | |
100 output->push_back(StartupTab(GURL(chrome::kChromeUINewTabURL), false)); | |
101 } else if (url.host() == kWelcomePageUrlHost) { | |
102 output->push_back(StartupTab(GetWelcomePageUrl(), false)); | |
103 } else { | |
104 output->push_back(StartupTab(url, false)); | |
105 } | |
106 } | |
107 } | |
108 return output->size() > initial_size; | |
109 } | |
110 | |
111 // static | |
112 bool StartupTabProviderImpl::CheckResetTriggerTabPolicy( | |
113 bool profile_has_trigger, | |
114 StartupTabs* output) { | |
115 if (profile_has_trigger) { | |
grt (UTC plus 2)
2016/09/14 11:21:22
nit: reverse the logic to get rid of the braces:
| |
116 output->push_back(StartupTab(GetTriggeredResetSettingsUrl(), false)); | |
117 return true; | |
118 } | |
119 return false; | |
120 } | |
121 | |
122 GURL GetWelcomePageUrl() { | |
123 return GURL(l10n_util::GetStringUTF8(IDS_WELCOME_PAGE_URL)); | |
124 } | |
125 | |
126 GURL GetTriggeredResetSettingsUrl() { | |
127 return GURL( | |
128 chrome::GetSettingsUrl(chrome::kTriggeredResetProfileSettingsSubPage)); | |
129 } | |
OLD | NEW |