blob: 92c54555bf1e56b0e563676fdc4c7ba79243dfaa [file] [log] [blame]
tmartinoe3f9c38e2016-09-13 14:05:321// 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 Chen532ec2c2018-09-26 21:50:055#include "chrome/browser/ui/webui/welcome/welcome_ui.h"
tmartinoe3f9c38e2016-09-13 14:05:326
Jinho Bang7ab7a4e2018-01-15 14:36:077#include <memory>
Hector Carmona8f2c3cb2018-07-12 21:07:588#include <string>
Jinho Bang7ab7a4e2018-01-15 14:36:079
Scott Chenf68c9b22018-10-12 02:15:2510#include "base/metrics/histogram_macros.h"
Hector Carmonac98557a992018-06-27 17:51:4311#include "build/build_config.h"
David Rogerf53a0752018-06-18 14:46:4812#include "chrome/browser/signin/account_consistency_mode_manager.h"
Hector Carmona207744f2018-10-25 23:49:5413#include "chrome/browser/ui/webui/welcome/nux/bookmark_handler.h"
Scott Chenf68c9b22018-10-12 02:15:2514#include "chrome/browser/ui/webui/welcome/nux/constants.h"
15#include "chrome/browser/ui/webui/welcome/nux/email_handler.h"
16#include "chrome/browser/ui/webui/welcome/nux/google_apps_handler.h"
17#include "chrome/browser/ui/webui/welcome/nux/set_as_default_handler.h"
Scott Chenc74ed762018-09-21 00:23:1618#include "chrome/browser/ui/webui/welcome/nux_helper.h"
Scott Chen532ec2c2018-09-26 21:50:0519#include "chrome/browser/ui/webui/welcome/welcome_handler.h"
tmartino6254f472016-11-21 01:22:5620#include "chrome/common/pref_names.h"
tmartinoe3f9c38e2016-09-13 14:05:3221#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"
dpapadb1f8e9a2018-10-18 21:36:0825#include "chrome/grit/onboarding_welcome_resources.h"
26#include "chrome/grit/onboarding_welcome_resources_map.h"
tmartino6254f472016-11-21 01:22:5627#include "components/prefs/pref_service.h"
Scott Chen395516b2018-10-23 00:05:4828#include "components/strings/grit/components_strings.h"
Scott Chenf68c9b22018-10-12 02:15:2529#include "content/public/browser/web_contents.h"
tmartinoe3f9c38e2016-09-13 14:05:3230#include "content/public/browser/web_ui_data_source.h"
tmartino7f0818b2016-09-27 23:39:0731#include "net/base/url_util.h"
tmartinoe3f9c38e2016-09-13 14:05:3232#include "ui/base/l10n/l10n_util.h"
tmartinoe3f9c38e2016-09-13 14:05:3233
Scott Chene8414882018-10-30 03:14:3534#if defined(OS_WIN)
35#include "base/win/windows_version.h"
36#endif
37
Scott Chenc6706672017-11-17 17:40:2738namespace {
Scott Chen532ec2c2018-09-26 21:50:0539const bool kIsBranded =
Scott Chenc6706672017-11-17 17:40:2740#if defined(GOOGLE_CHROME_BUILD)
Scott Chen532ec2c2018-09-26 21:50:0541 true;
Scott Chenc6706672017-11-17 17:40:2742#else
Scott Chen532ec2c2018-09-26 21:50:0543 false;
Scott Chenc6706672017-11-17 17:40:2744#endif
Scott Chen532ec2c2018-09-26 21:50:0545} // namespace
Scott Chenc6706672017-11-17 17:40:2746
Scott Chen395516b2018-10-23 00:05:4847// TODO(scottchen): reuse instead of copy from
48// md_settings_localized_strings_provider.cc.
49struct LocalizedString {
50 const char* name;
51 int id;
52};
53
54void AddOnboardingStrings(content::WebUIDataSource* html_source) {
55 static constexpr LocalizedString kLocalizedStrings[] = {
56 // Shared strings.
Scott Chen395516b2018-10-23 00:05:4857 {"acceptText", IDS_WELCOME_ACCEPT_BUTTON},
Scott Chen395516b2018-10-23 00:05:4858 {"bookmarkAdded", IDS_ONBOARDING_WELCOME_BOOKMARK_ADDED},
Hector Carmona6d779282018-10-30 23:48:4059 {"bookmarksAdded", IDS_ONBOARDING_WELCOME_BOOKMARKS_ADDED},
Scott Chen395516b2018-10-23 00:05:4860 {"bookmarkRemoved", IDS_ONBOARDING_WELCOME_BOOKMARK_REMOVED},
Hector Carmona6d779282018-10-30 23:48:4061 {"bookmarksRemoved", IDS_ONBOARDING_WELCOME_BOOKMARKS_REMOVED},
Scott Chen395516b2018-10-23 00:05:4862 {"bookmarkReplaced", IDS_ONBOARDING_WELCOME_BOOKMARK_REPLACED},
Scott Chenebfdce732018-10-26 02:34:2663 {"getStarted", IDS_ONBOARDING_WELCOME_GET_STARTED},
64 {"headerText", IDS_WELCOME_HEADER},
65 {"next", IDS_ONBOARDING_WELCOME_NEXT},
66 {"noThanks", IDS_NO_THANKS},
67 {"skip", IDS_ONBOARDING_WELCOME_SKIP},
Scott Chen395516b2018-10-23 00:05:4868
69 // Sign-in view strings.
70 {"signInHeader", IDS_ONBOARDING_WELCOME_SIGNIN_VIEW_HEADER},
71 {"signInSubHeader", IDS_ONBOARDING_WELCOME_SIGNIN_VIEW_SUB_HEADER},
72 {"signIn", IDS_ONBOARDING_WELCOME_SIGNIN_VIEW_SIGNIN},
73
74 // Email provider module strings.
Scott Chenebfdce732018-10-26 02:34:2675 {"emailProviderTitle", IDS_ONBOARDING_WELCOME_NUX_EMAIL_TITLE},
Scott Chen395516b2018-10-23 00:05:4876
77 // Google apps module strings.
78 {"googleAppsDescription",
79 IDS_ONBOARDING_WELCOME_NUX_GOOGLE_APPS_DESCRIPTION},
80
81 // Set as default module strings.
82 {"setDefaultHeader", IDS_ONBOARDING_WELCOME_NUX_SET_AS_DEFAULT_HEADER},
83 {"setDefaultSubHeader",
84 IDS_ONBOARDING_WELCOME_NUX_SET_AS_DEFAULT_SUB_HEADER},
85 {"setDefaultSkip", IDS_ONBOARDING_WELCOME_NUX_SET_AS_DEFAULT_SKIP},
86 {"setDefaultConfirm",
87 IDS_ONBOARDING_WELCOME_NUX_SET_AS_DEFAULT_SET_AS_DEFAULT},
Scott Chen618035d2018-10-24 00:48:1588
89 // Landing view strings.
90 {"landingTitle", IDS_ONBOARDING_WELCOME_LANDING_TITLE},
91 {"landingDescription", IDS_ONBOARDING_WELCOME_LANDING_DESCRIPTION},
92 {"landingNewUser", IDS_ONBOARDING_WELCOME_LANDING_NEW_USER},
93 {"landingExistingUser", IDS_ONBOARDING_WELCOME_LANDING_EXISTING_USER},
94
95 // Email interstitial strings.
96 {"emailInterstitialTitle",
97 IDS_ONBOARDING_WELCOME_EMAIL_INTERSTITIAL_TITLE},
98 {"emailInterstitialContinue",
99 IDS_ONBOARDING_WELCOME_EMAIL_INTERSTITIAL_CONTINUE},
Scott Chen395516b2018-10-23 00:05:48100 };
101
102 // TODO(scottchen): reuse instead of copy from
103 // md_settings_localized_strings_provider.cc.
104 for (size_t i = 0; i < base::size(kLocalizedStrings); i++) {
105 html_source->AddLocalizedString(kLocalizedStrings[i].name,
106 kLocalizedStrings[i].id);
107 }
108}
109
tmartinoe3f9c38e2016-09-13 14:05:32110WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url)
111 : content::WebUIController(web_ui) {
tmartino7f0818b2016-09-27 23:39:07112 Profile* profile = Profile::FromWebUI(web_ui);
113
114 // This page is not shown to incognito or guest profiles. If one should end up
115 // here, we return, causing a 404-like page.
116 if (!profile ||
117 profile->GetProfileType() != Profile::ProfileType::REGULAR_PROFILE) {
118 return;
119 }
120
Scott Chenf68c9b22018-10-12 02:15:25121 StorePageSeen(profile);
tmartino6254f472016-11-21 01:22:56122
Jinho Bang7ab7a4e2018-01-15 14:36:07123 web_ui->AddMessageHandler(std::make_unique<WelcomeHandler>(web_ui));
tmartinoe3f9c38e2016-09-13 14:05:32124
125 content::WebUIDataSource* html_source =
126 content::WebUIDataSource::Create(url.host());
127
David Rogerf53a0752018-06-18 14:46:48128 bool is_dice =
129 AccountConsistencyModeManager::IsDiceEnabledForProfile(profile);
tmartinoe3f9c38e2016-09-13 14:05:32130
Scott Chenc6706672017-11-17 17:40:27131 // There are multiple possible configurations that affects the layout, but
132 // first add resources that are shared across all layouts.
tmartinoe3f9c38e2016-09-13 14:05:32133 html_source->AddResourcePath("logo.png", IDR_PRODUCT_LOGO_128);
134 html_source->AddResourcePath("logo2x.png", IDR_PRODUCT_LOGO_256);
Scott Chena1264452017-11-14 13:32:08135
Scott Chenf68c9b22018-10-12 02:15:25136 if (nux::IsNuxOnboardingEnabled(profile)) {
Scott Chenc74ed762018-09-21 00:23:16137 // Add Onboarding welcome strings.
Scott Chen395516b2018-10-23 00:05:48138 AddOnboardingStrings(html_source);
Scott Chenc74ed762018-09-21 00:23:16139
dpapadb1f8e9a2018-10-18 21:36:08140 // Add all Onboarding resources.
141 for (size_t i = 0; i < kOnboardingWelcomeResourcesSize; ++i) {
142 html_source->AddResourcePath(kOnboardingWelcomeResources[i].name,
143 kOnboardingWelcomeResources[i].value);
144 }
Scott Chenaac2e182018-10-23 01:49:44145
146 // chrome://welcome
Scott Chenc74ed762018-09-21 00:23:16147 html_source->SetDefaultResource(
148 IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_HTML);
Scott Chenf68c9b22018-10-12 02:15:25149
Scott Chenaac2e182018-10-23 01:49:44150 // chrome://welcome/email-interstitial
151 html_source->AddResourcePath(
152 "email-interstitial",
153 IDR_WELCOME_ONBOARDING_WELCOME_EMAIL_INTERSTITIAL_HTML);
154
Scott Chend92e6ff2018-10-16 23:54:39155 html_source->AddResourcePath(
156 "images/background_svgs/blue_circle.svg",
157 IDR_WELCOME_ONBOARDING_WELCOME_IMAGES_BACKGROUND_SVGS_BLUE_CIRCLE_SVG);
158 html_source->AddResourcePath(
159 "images/background_svgs/green_rectangle.svg",
160 IDR_WELCOME_ONBOARDING_WELCOME_IMAGES_BACKGROUND_SVGS_GREEN_RECTANGLE_SVG);
161 html_source->AddResourcePath(
162 "images/background_svgs/grey_oval.svg",
163 IDR_WELCOME_ONBOARDING_WELCOME_IMAGES_BACKGROUND_SVGS_GREY_OVAL_SVG);
164 html_source->AddResourcePath(
165 "images/background_svgs/grey_rounded_rectangle.svg",
166 IDR_WELCOME_ONBOARDING_WELCOME_IMAGES_BACKGROUND_SVGS_GREY_ROUNDED_RECTANGLE_SVG);
167 html_source->AddResourcePath(
168 "images/background_svgs/red_triangle.svg",
169 IDR_WELCOME_ONBOARDING_WELCOME_IMAGES_BACKGROUND_SVGS_RED_TRIANGLE_SVG);
170 html_source->AddResourcePath(
171 "images/background_svgs/yellow_dots.svg",
172 IDR_WELCOME_ONBOARDING_WELCOME_IMAGES_BACKGROUND_SVGS_YELLOW_DOTS_SVG);
173 html_source->AddResourcePath(
174 "images/background_svgs/yellow_semicircle.svg",
175 IDR_WELCOME_ONBOARDING_WELCOME_IMAGES_BACKGROUND_SVGS_YELLOW_SEMICIRCLE_SVG);
Scott Chenf68c9b22018-10-12 02:15:25176
Scott Chenebfdce732018-10-26 02:34:26177 html_source->AddResourcePath("images/email_provider_1x.png",
178 IDR_NUX_EMAIL_PROVIDER_LOGO_1X);
179 html_source->AddResourcePath("images/email_provider_2x.png",
180 IDR_NUX_EMAIL_PROVIDER_LOGO_2X);
181 html_source->AddResourcePath("images/set_as_default_1x.png",
182 IDR_NUX_SET_AS_DEFAULT_LOGO_1X);
183 html_source->AddResourcePath("images/set_as_default_2x.png",
184 IDR_NUX_SET_AS_DEFAULT_LOGO_2X);
185 html_source->AddResourcePath("images/set_as_default_illustration_1x.png",
186 IDR_NUX_SET_AS_DEFAULT_ILLUSTRATION_1X);
187 html_source->AddResourcePath("images/set_as_default_illustration_2x.png",
188 IDR_NUX_SET_AS_DEFAULT_ILLUSTRATION_2X);
189
Scott Chene8414882018-10-30 03:14:35190#if defined(OS_WIN)
191 html_source->AddBoolean(
192 "is_win10", base::win::GetVersion() >= base::win::VERSION_WIN10);
193#endif
194
Hector Carmona207744f2018-10-25 23:49:54195 // Add the shared bookmark handler for onboarding modules.
196 web_ui->AddMessageHandler(
197 std::make_unique<nux::BookmarkHandler>(profile->GetPrefs()));
Hector Carmona207744f2018-10-25 23:49:54198
Scott Chenf68c9b22018-10-12 02:15:25199 // Add email provider bookmarking onboarding module.
Scott Chen3bb4c578362018-10-31 00:23:31200 web_ui->AddMessageHandler(std::make_unique<nux::EmailHandler>());
Hector Carmona207744f2018-10-25 23:49:54201 nux::EmailHandler::AddSources(html_source);
Scott Chenf68c9b22018-10-12 02:15:25202
203 // Add google apps bookmarking onboarding module.
Scott Chen3bb4c578362018-10-31 00:23:31204 web_ui->AddMessageHandler(std::make_unique<nux::GoogleAppsHandler>());
Hector Carmona207744f2018-10-25 23:49:54205 nux::GoogleAppsHandler::AddSources(html_source);
Scott Chenf68c9b22018-10-12 02:15:25206
207 // Add set-as-default onboarding module.
208 web_ui->AddMessageHandler(std::make_unique<nux::SetAsDefaultHandler>());
Scott Chen00858242018-11-01 23:40:47209
210 html_source->AddString(
211 "new_user_modules",
212 nux::GetNuxOnboardingModules(profile).FindKey("new-user")->GetString());
213 html_source->AddString("returning_user_modules",
214 nux::GetNuxOnboardingModules(profile)
215 .FindKey("returning-user")
216 ->GetString());
Scott Chenc74ed762018-09-21 00:23:16217 } else if (kIsBranded && is_dice) {
218 // Use special layout if the application is branded and DICE is enabled.
Scott Chenc6706672017-11-17 17:40:27219 html_source->AddLocalizedString("headerText", IDS_WELCOME_HEADER);
Thomas Tangl441b06782018-09-27 19:37:07220 html_source->AddLocalizedString("acceptText",
221 IDS_PROFILES_DICE_SIGNIN_BUTTON);
Scott Chenc6706672017-11-17 17:40:27222 html_source->AddLocalizedString("secondHeaderText",
223 IDS_DICE_WELCOME_SECOND_HEADER);
224 html_source->AddLocalizedString("descriptionText",
225 IDS_DICE_WELCOME_DESCRIPTION);
226 html_source->AddLocalizedString("declineText",
227 IDS_DICE_WELCOME_DECLINE_BUTTON);
Mihai Sardarescu631f3b472018-05-04 15:08:15228 html_source->AddResourcePath("welcome_browser_proxy.html",
229 IDR_DICE_WELCOME_BROWSER_PROXY_HTML);
230 html_source->AddResourcePath("welcome_browser_proxy.js",
231 IDR_DICE_WELCOME_BROWSER_PROXY_JS);
Scott Chenc6706672017-11-17 17:40:27232 html_source->AddResourcePath("welcome_app.html", IDR_DICE_WELCOME_APP_HTML);
233 html_source->AddResourcePath("welcome_app.js", IDR_DICE_WELCOME_APP_JS);
Scott Chena1264452017-11-14 13:32:08234 html_source->AddResourcePath("welcome.css", IDR_DICE_WELCOME_CSS);
235 html_source->SetDefaultResource(IDR_DICE_WELCOME_HTML);
236 } else {
Mihai Sardarescu631f3b472018-05-04 15:08:15237 // Use default layout for non-DICE or unbranded build.
238 std::string value;
239 bool is_everywhere_variant =
240 (net::GetValueForKeyInQuery(url, "variant", &value) &&
241 value == "everywhere");
242
Scott Chenc6706672017-11-17 17:40:27243 if (kIsBranded) {
244 base::string16 subheader =
245 is_everywhere_variant
246 ? base::string16()
247 : l10n_util::GetStringUTF16(IDS_WELCOME_SUBHEADER);
248 html_source->AddString("subheaderText", subheader);
249 }
250
251 int header_id = is_everywhere_variant ? IDS_WELCOME_HEADER_AFTER_FIRST_RUN
252 : IDS_WELCOME_HEADER;
253 html_source->AddString("headerText", l10n_util::GetStringUTF16(header_id));
Thomas Tangl441b06782018-09-27 19:37:07254 html_source->AddLocalizedString("acceptText", IDS_WELCOME_ACCEPT_BUTTON);
Scott Chenc6706672017-11-17 17:40:27255 html_source->AddLocalizedString("descriptionText", IDS_WELCOME_DESCRIPTION);
256 html_source->AddLocalizedString("declineText", IDS_WELCOME_DECLINE_BUTTON);
Scott Chena1264452017-11-14 13:32:08257 html_source->AddResourcePath("welcome.js", IDR_WELCOME_JS);
258 html_source->AddResourcePath("welcome.css", IDR_WELCOME_CSS);
259 html_source->SetDefaultResource(IDR_WELCOME_HTML);
260 }
tmartinoe3f9c38e2016-09-13 14:05:32261
tmartinoe3f9c38e2016-09-13 14:05:32262 content::WebUIDataSource::Add(profile, html_source);
263}
264
265WelcomeUI::~WelcomeUI() {}
Hector Carmona8f2c3cb2018-07-12 21:07:58266
Scott Chenf68c9b22018-10-12 02:15:25267void WelcomeUI::StorePageSeen(Profile* profile) {
Hector Carmona8f2c3cb2018-07-12 21:07:58268 // Store that this profile has been shown the Welcome page.
269 profile->GetPrefs()->SetBoolean(prefs::kHasSeenWelcomePage, true);
270}