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