tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 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 | |
Scott Chen | 532ec2c | 2018-09-26 21:50:05 | [diff] [blame] | 5 | #include "chrome/browser/ui/webui/welcome/welcome_ui.h" |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 6 | |
Dan Beam | e3e7947 | 2019-03-15 01:23:33 | [diff] [blame] | 7 | #include "base/bind.h" |
Scott Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 8 | #include "base/metrics/histogram_macros.h" |
Dan Beam | e3e7947 | 2019-03-15 01:23:33 | [diff] [blame] | 9 | #include "base/stl_util.h" |
Hector Carmona | c98557a99 | 2018-06-27 17:51:43 | [diff] [blame] | 10 | #include "build/build_config.h" |
David Roger | f53a075 | 2018-06-18 14:46:48 | [diff] [blame] | 11 | #include "chrome/browser/signin/account_consistency_mode_manager.h" |
Lei Zhang | 0a1c1c7 | 2018-12-13 20:41:33 | [diff] [blame] | 12 | #include "chrome/browser/ui/webui/localized_string.h" |
Hector Carmona | 207744f | 2018-10-25 23:49:54 | [diff] [blame] | 13 | #include "chrome/browser/ui/webui/welcome/nux/bookmark_handler.h" |
Scott Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 14 | #include "chrome/browser/ui/webui/welcome/nux/constants.h" |
Scott Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 15 | #include "chrome/browser/ui/webui/welcome/nux/google_apps_handler.h" |
John Lee | eba5909 | 2019-02-05 23:44:58 | [diff] [blame] | 16 | #include "chrome/browser/ui/webui/welcome/nux/ntp_background_handler.h" |
Scott Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 17 | #include "chrome/browser/ui/webui/welcome/nux/set_as_default_handler.h" |
Scott Chen | c74ed76 | 2018-09-21 00:23:16 | [diff] [blame] | 18 | #include "chrome/browser/ui/webui/welcome/nux_helper.h" |
Scott Chen | 532ec2c | 2018-09-26 21:50:05 | [diff] [blame] | 19 | #include "chrome/browser/ui/webui/welcome/welcome_handler.h" |
tmartino | 6254f47 | 2016-11-21 01:22:56 | [diff] [blame] | 20 | #include "chrome/common/pref_names.h" |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 21 | #include "chrome/grit/browser_resources.h" |
| 22 | #include "chrome/grit/chrome_unscaled_resources.h" |
| 23 | #include "chrome/grit/chromium_strings.h" |
| 24 | #include "chrome/grit/generated_resources.h" |
dpapad | b1f8e9a | 2018-10-18 21:36:08 | [diff] [blame] | 25 | #include "chrome/grit/onboarding_welcome_resources.h" |
| 26 | #include "chrome/grit/onboarding_welcome_resources_map.h" |
tmartino | 6254f47 | 2016-11-21 01:22:56 | [diff] [blame] | 27 | #include "components/prefs/pref_service.h" |
Colin Blundell | 3517170e | 2019-07-11 08:16:34 | [diff] [blame^] | 28 | #include "components/signin/public/base/signin_pref_names.h" |
Scott Chen | 395516b | 2018-10-23 00:05:48 | [diff] [blame] | 29 | #include "components/strings/grit/components_strings.h" |
Scott Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 30 | #include "content/public/browser/web_contents.h" |
tmartino | 7f0818b | 2016-09-27 23:39:07 | [diff] [blame] | 31 | #include "net/base/url_util.h" |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 32 | #include "ui/base/l10n/l10n_util.h" |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 33 | |
Scott Chen | e841488 | 2018-10-30 03:14:35 | [diff] [blame] | 34 | #if defined(OS_WIN) |
| 35 | #include "base/win/windows_version.h" |
| 36 | #endif |
| 37 | |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 38 | namespace { |
Dan Beam | a896f66 | 2019-03-19 18:26:39 | [diff] [blame] | 39 | |
Scott Chen | 532ec2c | 2018-09-26 21:50:05 | [diff] [blame] | 40 | const bool kIsBranded = |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 41 | #if defined(GOOGLE_CHROME_BUILD) |
Scott Chen | 532ec2c | 2018-09-26 21:50:05 | [diff] [blame] | 42 | true; |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 43 | #else |
Scott Chen | 532ec2c | 2018-09-26 21:50:05 | [diff] [blame] | 44 | false; |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 45 | #endif |
Dan Beam | a896f66 | 2019-03-19 18:26:39 | [diff] [blame] | 46 | |
| 47 | const char kPreviewBackgroundPath[] = "preview-background.jpg"; |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 48 | |
dpapad | 28dccc44 | 2019-04-09 22:06:40 | [diff] [blame] | 49 | bool ShouldHandleRequestCallback(base::WeakPtr<WelcomeUI> weak_ptr, |
| 50 | const std::string& path) { |
Dan Beam | a896f66 | 2019-03-19 18:26:39 | [diff] [blame] | 51 | if (!base::StartsWith(path, kPreviewBackgroundPath, |
John Lee | 6eb43ae | 2019-02-28 21:25:26 | [diff] [blame] | 52 | base::CompareCase::SENSITIVE)) { |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | std::string index_param = path.substr(path.find_first_of("?") + 1); |
| 57 | int background_index = -1; |
| 58 | if (!base::StringToInt(index_param, &background_index) || |
| 59 | background_index < 0) { |
| 60 | return false; |
| 61 | } |
| 62 | |
dpapad | 28dccc44 | 2019-04-09 22:06:40 | [diff] [blame] | 63 | return !weak_ptr ? false : true; |
| 64 | } |
John Lee | 6eb43ae | 2019-02-28 21:25:26 | [diff] [blame] | 65 | |
dpapad | 28dccc44 | 2019-04-09 22:06:40 | [diff] [blame] | 66 | void HandleRequestCallback( |
| 67 | base::WeakPtr<WelcomeUI> weak_ptr, |
| 68 | const std::string& path, |
| 69 | const content::WebUIDataSource::GotDataCallback& callback) { |
| 70 | DCHECK(ShouldHandleRequestCallback(weak_ptr, path)); |
| 71 | |
| 72 | std::string index_param = path.substr(path.find_first_of("?") + 1); |
| 73 | int background_index = -1; |
| 74 | CHECK(base::StringToInt(index_param, &background_index) || |
| 75 | background_index < 0); |
| 76 | |
| 77 | DCHECK(weak_ptr); |
| 78 | weak_ptr->CreateBackgroundFetcher(background_index, callback); |
John Lee | 6eb43ae | 2019-02-28 21:25:26 | [diff] [blame] | 79 | } |
| 80 | |
Scott Chen | 395516b | 2018-10-23 00:05:48 | [diff] [blame] | 81 | void AddOnboardingStrings(content::WebUIDataSource* html_source) { |
| 82 | static constexpr LocalizedString kLocalizedStrings[] = { |
| 83 | // Shared strings. |
Scott Chen | 395516b | 2018-10-23 00:05:48 | [diff] [blame] | 84 | {"acceptText", IDS_WELCOME_ACCEPT_BUTTON}, |
Scott Chen | 395516b | 2018-10-23 00:05:48 | [diff] [blame] | 85 | {"bookmarkAdded", IDS_ONBOARDING_WELCOME_BOOKMARK_ADDED}, |
Hector Carmona | 6d77928 | 2018-10-30 23:48:40 | [diff] [blame] | 86 | {"bookmarksAdded", IDS_ONBOARDING_WELCOME_BOOKMARKS_ADDED}, |
Scott Chen | 395516b | 2018-10-23 00:05:48 | [diff] [blame] | 87 | {"bookmarkRemoved", IDS_ONBOARDING_WELCOME_BOOKMARK_REMOVED}, |
Hector Carmona | 6d77928 | 2018-10-30 23:48:40 | [diff] [blame] | 88 | {"bookmarksRemoved", IDS_ONBOARDING_WELCOME_BOOKMARKS_REMOVED}, |
Scott Chen | 5524784e | 2019-04-02 02:54:58 | [diff] [blame] | 89 | {"defaultBrowserChanged", IDS_ONBOARDING_DEFAULT_BROWSER_CHANGED}, |
Scott Chen | ebfdce73 | 2018-10-26 02:34:26 | [diff] [blame] | 90 | {"getStarted", IDS_ONBOARDING_WELCOME_GET_STARTED}, |
| 91 | {"headerText", IDS_WELCOME_HEADER}, |
| 92 | {"next", IDS_ONBOARDING_WELCOME_NEXT}, |
| 93 | {"noThanks", IDS_NO_THANKS}, |
| 94 | {"skip", IDS_ONBOARDING_WELCOME_SKIP}, |
Scott Chen | 395516b | 2018-10-23 00:05:48 | [diff] [blame] | 95 | |
| 96 | // Sign-in view strings. |
| 97 | {"signInHeader", IDS_ONBOARDING_WELCOME_SIGNIN_VIEW_HEADER}, |
| 98 | {"signInSubHeader", IDS_ONBOARDING_WELCOME_SIGNIN_VIEW_SUB_HEADER}, |
| 99 | {"signIn", IDS_ONBOARDING_WELCOME_SIGNIN_VIEW_SIGNIN}, |
| 100 | |
Scott Chen | 395516b | 2018-10-23 00:05:48 | [diff] [blame] | 101 | // Google apps module strings. |
| 102 | {"googleAppsDescription", |
| 103 | IDS_ONBOARDING_WELCOME_NUX_GOOGLE_APPS_DESCRIPTION}, |
| 104 | |
John Lee | 0c3ede53 | 2019-01-30 02:58:50 | [diff] [blame] | 105 | // New Tab Page background module strings. |
| 106 | {"ntpBackgroundDescription", |
| 107 | IDS_ONBOARDING_WELCOME_NTP_BACKGROUND_DESCRIPTION}, |
John Lee | cea68d4 | 2019-02-12 20:02:57 | [diff] [blame] | 108 | {"ntpBackgroundDefault", |
| 109 | IDS_ONBOARDING_WELCOME_NTP_BACKGROUND_DEFAULT_TITLE}, |
John Lee | 10f1987 | 2019-03-11 21:28:50 | [diff] [blame] | 110 | {"ntpBackgroundPreviewUpdated", |
| 111 | IDS_ONBOARDING_WELCOME_NTP_BACKGROUND_PREVIEW_UPDATED}, |
John Lee | b5d871e | 2019-03-12 03:30:18 | [diff] [blame] | 112 | {"ntpBackgroundReset", IDS_ONBOARDING_WELCOME_NTP_BACKGROUND_RESET}, |
John Lee | 0c3ede53 | 2019-01-30 02:58:50 | [diff] [blame] | 113 | |
Scott Chen | 395516b | 2018-10-23 00:05:48 | [diff] [blame] | 114 | // Set as default module strings. |
| 115 | {"setDefaultHeader", IDS_ONBOARDING_WELCOME_NUX_SET_AS_DEFAULT_HEADER}, |
| 116 | {"setDefaultSubHeader", |
| 117 | IDS_ONBOARDING_WELCOME_NUX_SET_AS_DEFAULT_SUB_HEADER}, |
| 118 | {"setDefaultSkip", IDS_ONBOARDING_WELCOME_NUX_SET_AS_DEFAULT_SKIP}, |
| 119 | {"setDefaultConfirm", |
| 120 | IDS_ONBOARDING_WELCOME_NUX_SET_AS_DEFAULT_SET_AS_DEFAULT}, |
Scott Chen | 618035d | 2018-10-24 00:48:15 | [diff] [blame] | 121 | |
| 122 | // Landing view strings. |
| 123 | {"landingTitle", IDS_ONBOARDING_WELCOME_LANDING_TITLE}, |
| 124 | {"landingDescription", IDS_ONBOARDING_WELCOME_LANDING_DESCRIPTION}, |
| 125 | {"landingNewUser", IDS_ONBOARDING_WELCOME_LANDING_NEW_USER}, |
| 126 | {"landingExistingUser", IDS_ONBOARDING_WELCOME_LANDING_EXISTING_USER}, |
Scott Chen | 395516b | 2018-10-23 00:05:48 | [diff] [blame] | 127 | }; |
Lei Zhang | 0a1c1c7 | 2018-12-13 20:41:33 | [diff] [blame] | 128 | AddLocalizedStringsBulk(html_source, kLocalizedStrings, |
| 129 | base::size(kLocalizedStrings)); |
Scott Chen | 395516b | 2018-10-23 00:05:48 | [diff] [blame] | 130 | } |
| 131 | |
Dan Beam | a896f66 | 2019-03-19 18:26:39 | [diff] [blame] | 132 | } // namespace |
| 133 | |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 134 | WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url) |
John Lee | 6eb43ae | 2019-02-28 21:25:26 | [diff] [blame] | 135 | : content::WebUIController(web_ui), weak_ptr_factory_(this) { |
tmartino | 7f0818b | 2016-09-27 23:39:07 | [diff] [blame] | 136 | Profile* profile = Profile::FromWebUI(web_ui); |
| 137 | |
| 138 | // This page is not shown to incognito or guest profiles. If one should end up |
| 139 | // here, we return, causing a 404-like page. |
Ramin Halavati | 85ce927 | 2019-05-14 10:29:30 | [diff] [blame] | 140 | if (!profile || !profile->IsRegularProfile()) { |
tmartino | 7f0818b | 2016-09-27 23:39:07 | [diff] [blame] | 141 | return; |
| 142 | } |
| 143 | |
Scott Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 144 | StorePageSeen(profile); |
tmartino | 6254f47 | 2016-11-21 01:22:56 | [diff] [blame] | 145 | |
Jinho Bang | 7ab7a4e | 2018-01-15 14:36:07 | [diff] [blame] | 146 | web_ui->AddMessageHandler(std::make_unique<WelcomeHandler>(web_ui)); |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 147 | |
| 148 | content::WebUIDataSource* html_source = |
| 149 | content::WebUIDataSource::Create(url.host()); |
| 150 | |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 151 | // There are multiple possible configurations that affects the layout, but |
| 152 | // first add resources that are shared across all layouts. |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 153 | html_source->AddResourcePath("logo.png", IDR_PRODUCT_LOGO_128); |
| 154 | html_source->AddResourcePath("logo2x.png", IDR_PRODUCT_LOGO_256); |
Scott Chen | a126445 | 2017-11-14 13:32:08 | [diff] [blame] | 155 | |
Dan Beam | a896f66 | 2019-03-19 18:26:39 | [diff] [blame] | 156 | if (nux::IsNuxOnboardingEnabled(profile)) { |
Scott Chen | c74ed76 | 2018-09-21 00:23:16 | [diff] [blame] | 157 | // Add Onboarding welcome strings. |
Scott Chen | 395516b | 2018-10-23 00:05:48 | [diff] [blame] | 158 | AddOnboardingStrings(html_source); |
Scott Chen | c74ed76 | 2018-09-21 00:23:16 | [diff] [blame] | 159 | |
dpapad | b1f8e9a | 2018-10-18 21:36:08 | [diff] [blame] | 160 | // Add all Onboarding resources. |
| 161 | for (size_t i = 0; i < kOnboardingWelcomeResourcesSize; ++i) { |
| 162 | html_source->AddResourcePath(kOnboardingWelcomeResources[i].name, |
| 163 | kOnboardingWelcomeResources[i].value); |
| 164 | } |
Scott Chen | aac2e18 | 2018-10-23 01:49:44 | [diff] [blame] | 165 | |
Hector Carmona | 1c97020b76 | 2019-06-11 16:39:29 | [diff] [blame] | 166 | #if defined(GOOGLE_CHROME_BUILD) |
| 167 | // Load unscaled images. |
| 168 | html_source->AddResourcePath("images/module_icons/google_dark.svg", |
| 169 | IDR_WELCOME_MODULE_ICONS_GOOGLE_DARK); |
| 170 | html_source->AddResourcePath("images/module_icons/google_light.svg", |
| 171 | IDR_WELCOME_MODULE_ICONS_GOOGLE_LIGHT); |
| 172 | html_source->AddResourcePath("images/module_icons/set_default_dark.svg", |
| 173 | IDR_WELCOME_MODULE_ICONS_SET_DEFAULT_DARK); |
| 174 | html_source->AddResourcePath("images/module_icons/set_default_light.svg", |
| 175 | IDR_WELCOME_MODULE_ICONS_SET_DEFAULT_LIGHT); |
| 176 | html_source->AddResourcePath("images/module_icons/wallpaper_dark.svg", |
| 177 | IDR_WELCOME_MODULE_ICONS_WALLPAPER_DARK); |
| 178 | html_source->AddResourcePath("images/module_icons/wallpaper_light.svg", |
| 179 | IDR_WELCOME_MODULE_ICONS_WALLPAPER_LIGHT); |
| 180 | html_source->AddResourcePath("images/ntp_thumbnails/art.jpg", |
| 181 | IDR_WELCOME_NTP_THUMBNAILS_ART); |
| 182 | html_source->AddResourcePath("images/ntp_thumbnails/cityscape.jpg", |
| 183 | IDR_WELCOME_NTP_THUMBNAILS_CITYSCAPE); |
| 184 | html_source->AddResourcePath("images/ntp_thumbnails/earth.jpg", |
| 185 | IDR_WELCOME_NTP_THUMBNAILS_EARTH); |
| 186 | html_source->AddResourcePath("images/ntp_thumbnails/geometric_shapes.jpg", |
| 187 | IDR_WELCOME_NTP_THUMBNAILS_GEOMETRIC_SHAPES); |
| 188 | html_source->AddResourcePath("images/ntp_thumbnails/landscape.jpg", |
| 189 | IDR_WELCOME_NTP_THUMBNAILS_LANDSCAPE); |
| 190 | html_source->AddResourcePath("images/set_default_dark.svg", |
| 191 | IDR_WELCOME_SET_DEFAULT_DARK); |
| 192 | html_source->AddResourcePath("images/set_default_light.svg", |
| 193 | IDR_WELCOME_SET_DEFAULT_LIGHT); |
| 194 | #endif // defined(GOOGLE_CHROME_BUILD) |
| 195 | |
Scott Chen | aac2e18 | 2018-10-23 01:49:44 | [diff] [blame] | 196 | // chrome://welcome |
Scott Chen | c74ed76 | 2018-09-21 00:23:16 | [diff] [blame] | 197 | html_source->SetDefaultResource( |
| 198 | IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_HTML); |
Scott Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 199 | |
Scott Chen | e841488 | 2018-10-30 03:14:35 | [diff] [blame] | 200 | #if defined(OS_WIN) |
| 201 | html_source->AddBoolean( |
Bruce Dawson | aed9bea | 2019-04-20 02:30:09 | [diff] [blame] | 202 | "is_win10", base::win::GetVersion() >= base::win::Version::WIN10); |
Scott Chen | e841488 | 2018-10-30 03:14:35 | [diff] [blame] | 203 | #endif |
| 204 | |
Hector Carmona | 207744f | 2018-10-25 23:49:54 | [diff] [blame] | 205 | // Add the shared bookmark handler for onboarding modules. |
| 206 | web_ui->AddMessageHandler( |
| 207 | std::make_unique<nux::BookmarkHandler>(profile->GetPrefs())); |
Hector Carmona | 207744f | 2018-10-25 23:49:54 | [diff] [blame] | 208 | |
Scott Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 209 | // Add google apps bookmarking onboarding module. |
Scott Chen | 3bb4c57836 | 2018-10-31 00:23:31 | [diff] [blame] | 210 | web_ui->AddMessageHandler(std::make_unique<nux::GoogleAppsHandler>()); |
Scott Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 211 | |
John Lee | eba5909 | 2019-02-05 23:44:58 | [diff] [blame] | 212 | // Add NTP custom background onboarding module. |
| 213 | web_ui->AddMessageHandler(std::make_unique<nux::NtpBackgroundHandler>()); |
| 214 | |
Scott Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 215 | // Add set-as-default onboarding module. |
| 216 | web_ui->AddMessageHandler(std::make_unique<nux::SetAsDefaultHandler>()); |
Scott Chen | 0085824 | 2018-11-01 23:40:47 | [diff] [blame] | 217 | |
| 218 | html_source->AddString( |
Scott Chen | 7243c1a | 2018-11-06 01:33:41 | [diff] [blame] | 219 | "newUserModules", |
Scott Chen | 0085824 | 2018-11-01 23:40:47 | [diff] [blame] | 220 | nux::GetNuxOnboardingModules(profile).FindKey("new-user")->GetString()); |
Scott Chen | 7243c1a | 2018-11-06 01:33:41 | [diff] [blame] | 221 | html_source->AddString("returningUserModules", |
Scott Chen | 0085824 | 2018-11-01 23:40:47 | [diff] [blame] | 222 | nux::GetNuxOnboardingModules(profile) |
| 223 | .FindKey("returning-user") |
| 224 | ->GetString()); |
Hector Carmona | 7f52fab | 2019-04-18 23:31:22 | [diff] [blame] | 225 | html_source->AddBoolean("signinAllowed", profile->GetPrefs()->GetBoolean( |
| 226 | prefs::kSigninAllowed)); |
dpapad | 28dccc44 | 2019-04-09 22:06:40 | [diff] [blame] | 227 | html_source->SetRequestFilter( |
| 228 | base::BindRepeating(&ShouldHandleRequestCallback, |
| 229 | weak_ptr_factory_.GetWeakPtr()), |
| 230 | base::BindRepeating(&HandleRequestCallback, |
| 231 | weak_ptr_factory_.GetWeakPtr())); |
Hector Carmona | e3b2605c | 2019-04-11 22:28:35 | [diff] [blame] | 232 | html_source->SetJsonPath("strings.js"); |
Dan Beam | a896f66 | 2019-03-19 18:26:39 | [diff] [blame] | 233 | } else if (kIsBranded && |
| 234 | AccountConsistencyModeManager::IsDiceEnabledForProfile(profile)) { |
Scott Chen | c74ed76 | 2018-09-21 00:23:16 | [diff] [blame] | 235 | // Use special layout if the application is branded and DICE is enabled. |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 236 | html_source->AddLocalizedString("headerText", IDS_WELCOME_HEADER); |
Thomas Tangl | 441b0678 | 2018-09-27 19:37:07 | [diff] [blame] | 237 | html_source->AddLocalizedString("acceptText", |
| 238 | IDS_PROFILES_DICE_SIGNIN_BUTTON); |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 239 | html_source->AddLocalizedString("secondHeaderText", |
| 240 | IDS_DICE_WELCOME_SECOND_HEADER); |
| 241 | html_source->AddLocalizedString("descriptionText", |
| 242 | IDS_DICE_WELCOME_DESCRIPTION); |
| 243 | html_source->AddLocalizedString("declineText", |
| 244 | IDS_DICE_WELCOME_DECLINE_BUTTON); |
Mihai Sardarescu | 631f3b47 | 2018-05-04 15:08:15 | [diff] [blame] | 245 | html_source->AddResourcePath("welcome_browser_proxy.html", |
| 246 | IDR_DICE_WELCOME_BROWSER_PROXY_HTML); |
| 247 | html_source->AddResourcePath("welcome_browser_proxy.js", |
| 248 | IDR_DICE_WELCOME_BROWSER_PROXY_JS); |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 249 | html_source->AddResourcePath("welcome_app.html", IDR_DICE_WELCOME_APP_HTML); |
| 250 | html_source->AddResourcePath("welcome_app.js", IDR_DICE_WELCOME_APP_JS); |
Scott Chen | a126445 | 2017-11-14 13:32:08 | [diff] [blame] | 251 | html_source->AddResourcePath("welcome.css", IDR_DICE_WELCOME_CSS); |
| 252 | html_source->SetDefaultResource(IDR_DICE_WELCOME_HTML); |
| 253 | } else { |
Mihai Sardarescu | 631f3b47 | 2018-05-04 15:08:15 | [diff] [blame] | 254 | // Use default layout for non-DICE or unbranded build. |
| 255 | std::string value; |
| 256 | bool is_everywhere_variant = |
| 257 | (net::GetValueForKeyInQuery(url, "variant", &value) && |
| 258 | value == "everywhere"); |
| 259 | |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 260 | if (kIsBranded) { |
| 261 | base::string16 subheader = |
| 262 | is_everywhere_variant |
| 263 | ? base::string16() |
| 264 | : l10n_util::GetStringUTF16(IDS_WELCOME_SUBHEADER); |
| 265 | html_source->AddString("subheaderText", subheader); |
| 266 | } |
| 267 | |
| 268 | int header_id = is_everywhere_variant ? IDS_WELCOME_HEADER_AFTER_FIRST_RUN |
| 269 | : IDS_WELCOME_HEADER; |
| 270 | html_source->AddString("headerText", l10n_util::GetStringUTF16(header_id)); |
Thomas Tangl | 441b0678 | 2018-09-27 19:37:07 | [diff] [blame] | 271 | html_source->AddLocalizedString("acceptText", IDS_WELCOME_ACCEPT_BUTTON); |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 272 | html_source->AddLocalizedString("descriptionText", IDS_WELCOME_DESCRIPTION); |
| 273 | html_source->AddLocalizedString("declineText", IDS_WELCOME_DECLINE_BUTTON); |
Scott Chen | a126445 | 2017-11-14 13:32:08 | [diff] [blame] | 274 | html_source->AddResourcePath("welcome.js", IDR_WELCOME_JS); |
| 275 | html_source->AddResourcePath("welcome.css", IDR_WELCOME_CSS); |
| 276 | html_source->SetDefaultResource(IDR_WELCOME_HTML); |
| 277 | } |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 278 | |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 279 | content::WebUIDataSource::Add(profile, html_source); |
| 280 | } |
| 281 | |
| 282 | WelcomeUI::~WelcomeUI() {} |
Hector Carmona | 8f2c3cb | 2018-07-12 21:07:58 | [diff] [blame] | 283 | |
John Lee | 6eb43ae | 2019-02-28 21:25:26 | [diff] [blame] | 284 | void WelcomeUI::CreateBackgroundFetcher( |
| 285 | size_t background_index, |
| 286 | const content::WebUIDataSource::GotDataCallback& callback) { |
| 287 | background_fetcher_ = |
| 288 | std::make_unique<nux::NtpBackgroundFetcher>(background_index, callback); |
| 289 | } |
| 290 | |
Scott Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 291 | void WelcomeUI::StorePageSeen(Profile* profile) { |
Hector Carmona | 8f2c3cb | 2018-07-12 21:07:58 | [diff] [blame] | 292 | // Store that this profile has been shown the Welcome page. |
| 293 | profile->GetPrefs()->SetBoolean(prefs::kHasSeenWelcomePage, true); |
| 294 | } |