blob: d1d9b057b209de0bdae95d7b1c5555dd461e6aed [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"
Hector Carmona82ae58692018-08-09 22:43:0012#include "chrome/browser/favicon/favicon_service_factory.h"
David Rogerf53a0752018-06-18 14:46:4813#include "chrome/browser/signin/account_consistency_mode_manager.h"
Hector Carmona207744f2018-10-25 23:49:5414#include "chrome/browser/ui/webui/welcome/nux/bookmark_handler.h"
Scott Chenf68c9b22018-10-12 02:15:2515#include "chrome/browser/ui/webui/welcome/nux/constants.h"
16#include "chrome/browser/ui/webui/welcome/nux/email_handler.h"
17#include "chrome/browser/ui/webui/welcome/nux/google_apps_handler.h"
18#include "chrome/browser/ui/webui/welcome/nux/set_as_default_handler.h"
Scott Chenc74ed762018-09-21 00:23:1619#include "chrome/browser/ui/webui/welcome/nux_helper.h"
Scott Chen532ec2c2018-09-26 21:50:0520#include "chrome/browser/ui/webui/welcome/welcome_handler.h"
tmartino6254f472016-11-21 01:22:5621#include "chrome/common/pref_names.h"
tmartinoe3f9c38e2016-09-13 14:05:3222#include "chrome/grit/browser_resources.h"
23#include "chrome/grit/chrome_unscaled_resources.h"
24#include "chrome/grit/chromium_strings.h"
25#include "chrome/grit/generated_resources.h"
dpapadb1f8e9a2018-10-18 21:36:0826#include "chrome/grit/onboarding_welcome_resources.h"
27#include "chrome/grit/onboarding_welcome_resources_map.h"
tmartino6254f472016-11-21 01:22:5628#include "components/prefs/pref_service.h"
Scott Chen395516b2018-10-23 00:05:4829#include "components/strings/grit/components_strings.h"
Scott Chenf68c9b22018-10-12 02:15:2530#include "content/public/browser/web_contents.h"
tmartinoe3f9c38e2016-09-13 14:05:3231#include "content/public/browser/web_ui_data_source.h"
tmartino7f0818b2016-09-27 23:39:0732#include "net/base/url_util.h"
tmartinoe3f9c38e2016-09-13 14:05:3233#include "ui/base/l10n/l10n_util.h"
tmartinoe3f9c38e2016-09-13 14:05:3234
Scott Chene8414882018-10-30 03:14:3535#if defined(OS_WIN)
36#include "base/win/windows_version.h"
37#endif
38
Scott Chenc6706672017-11-17 17:40:2739namespace {
Scott Chen532ec2c2018-09-26 21:50:0540const bool kIsBranded =
Scott Chenc6706672017-11-17 17:40:2741#if defined(GOOGLE_CHROME_BUILD)
Scott Chen532ec2c2018-09-26 21:50:0542 true;
Scott Chenc6706672017-11-17 17:40:2743#else
Scott Chen532ec2c2018-09-26 21:50:0544 false;
Scott Chenc6706672017-11-17 17:40:2745#endif
Scott Chen532ec2c2018-09-26 21:50:0546} // namespace
Scott Chenc6706672017-11-17 17:40:2747
Scott Chen395516b2018-10-23 00:05:4848// TODO(scottchen): reuse instead of copy from
49// md_settings_localized_strings_provider.cc.
50struct LocalizedString {
51 const char* name;
52 int id;
53};
54
55void AddOnboardingStrings(content::WebUIDataSource* html_source) {
56 static constexpr LocalizedString kLocalizedStrings[] = {
57 // Shared strings.
Scott Chen395516b2018-10-23 00:05:4858 {"acceptText", IDS_WELCOME_ACCEPT_BUTTON},
Scott Chen395516b2018-10-23 00:05:4859 {"bookmarkAdded", IDS_ONBOARDING_WELCOME_BOOKMARK_ADDED},
60 {"bookmarkRemoved", IDS_ONBOARDING_WELCOME_BOOKMARK_REMOVED},
61 {"bookmarkReplaced", IDS_ONBOARDING_WELCOME_BOOKMARK_REPLACED},
Scott Chenebfdce732018-10-26 02:34:2662 {"getStarted", IDS_ONBOARDING_WELCOME_GET_STARTED},
63 {"headerText", IDS_WELCOME_HEADER},
64 {"next", IDS_ONBOARDING_WELCOME_NEXT},
65 {"noThanks", IDS_NO_THANKS},
66 {"skip", IDS_ONBOARDING_WELCOME_SKIP},
Scott Chen395516b2018-10-23 00:05:4867
68 // Sign-in view strings.
69 {"signInHeader", IDS_ONBOARDING_WELCOME_SIGNIN_VIEW_HEADER},
70 {"signInSubHeader", IDS_ONBOARDING_WELCOME_SIGNIN_VIEW_SUB_HEADER},
71 {"signIn", IDS_ONBOARDING_WELCOME_SIGNIN_VIEW_SIGNIN},
72
73 // Email provider module strings.
Scott Chenebfdce732018-10-26 02:34:2674 {"emailProviderTitle", IDS_ONBOARDING_WELCOME_NUX_EMAIL_TITLE},
Scott Chen395516b2018-10-23 00:05:4875
76 // Google apps module strings.
77 {"googleAppsDescription",
78 IDS_ONBOARDING_WELCOME_NUX_GOOGLE_APPS_DESCRIPTION},
79
80 // Set as default module strings.
81 {"setDefaultHeader", IDS_ONBOARDING_WELCOME_NUX_SET_AS_DEFAULT_HEADER},
82 {"setDefaultSubHeader",
83 IDS_ONBOARDING_WELCOME_NUX_SET_AS_DEFAULT_SUB_HEADER},
84 {"setDefaultSkip", IDS_ONBOARDING_WELCOME_NUX_SET_AS_DEFAULT_SKIP},
85 {"setDefaultConfirm",
86 IDS_ONBOARDING_WELCOME_NUX_SET_AS_DEFAULT_SET_AS_DEFAULT},
Scott Chen618035d2018-10-24 00:48:1587
88 // Landing view strings.
89 {"landingTitle", IDS_ONBOARDING_WELCOME_LANDING_TITLE},
90 {"landingDescription", IDS_ONBOARDING_WELCOME_LANDING_DESCRIPTION},
91 {"landingNewUser", IDS_ONBOARDING_WELCOME_LANDING_NEW_USER},
92 {"landingExistingUser", IDS_ONBOARDING_WELCOME_LANDING_EXISTING_USER},
93
94 // Email interstitial strings.
95 {"emailInterstitialTitle",
96 IDS_ONBOARDING_WELCOME_EMAIL_INTERSTITIAL_TITLE},
97 {"emailInterstitialContinue",
98 IDS_ONBOARDING_WELCOME_EMAIL_INTERSTITIAL_CONTINUE},
Scott Chen395516b2018-10-23 00:05:4899 };
100
101 // TODO(scottchen): reuse instead of copy from
102 // md_settings_localized_strings_provider.cc.
103 for (size_t i = 0; i < base::size(kLocalizedStrings); i++) {
104 html_source->AddLocalizedString(kLocalizedStrings[i].name,
105 kLocalizedStrings[i].id);
106 }
107}
108
tmartinoe3f9c38e2016-09-13 14:05:32109WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url)
110 : content::WebUIController(web_ui) {
tmartino7f0818b2016-09-27 23:39:07111 Profile* profile = Profile::FromWebUI(web_ui);
112
113 // This page is not shown to incognito or guest profiles. If one should end up
114 // here, we return, causing a 404-like page.
115 if (!profile ||
116 profile->GetProfileType() != Profile::ProfileType::REGULAR_PROFILE) {
117 return;
118 }
119
Scott Chenf68c9b22018-10-12 02:15:25120 StorePageSeen(profile);
tmartino6254f472016-11-21 01:22:56121
Jinho Bang7ab7a4e2018-01-15 14:36:07122 web_ui->AddMessageHandler(std::make_unique<WelcomeHandler>(web_ui));
tmartinoe3f9c38e2016-09-13 14:05:32123
124 content::WebUIDataSource* html_source =
125 content::WebUIDataSource::Create(url.host());
126
David Rogerf53a0752018-06-18 14:46:48127 bool is_dice =
128 AccountConsistencyModeManager::IsDiceEnabledForProfile(profile);
tmartinoe3f9c38e2016-09-13 14:05:32129
Scott Chenc6706672017-11-17 17:40:27130 // There are multiple possible configurations that affects the layout, but
131 // first add resources that are shared across all layouts.
tmartinoe3f9c38e2016-09-13 14:05:32132 html_source->AddResourcePath("logo.png", IDR_PRODUCT_LOGO_128);
133 html_source->AddResourcePath("logo2x.png", IDR_PRODUCT_LOGO_256);
Scott Chena1264452017-11-14 13:32:08134
Scott Chenf68c9b22018-10-12 02:15:25135 if (nux::IsNuxOnboardingEnabled(profile)) {
Scott Chenc74ed762018-09-21 00:23:16136 // Add Onboarding welcome strings.
Scott Chen395516b2018-10-23 00:05:48137 AddOnboardingStrings(html_source);
Scott Chenc74ed762018-09-21 00:23:16138
dpapadb1f8e9a2018-10-18 21:36:08139 // Add all Onboarding resources.
140 for (size_t i = 0; i < kOnboardingWelcomeResourcesSize; ++i) {
141 html_source->AddResourcePath(kOnboardingWelcomeResources[i].name,
142 kOnboardingWelcomeResources[i].value);
143 }
Scott Chenaac2e182018-10-23 01:49:44144
145 // chrome://welcome
Scott Chenc74ed762018-09-21 00:23:16146 html_source->SetDefaultResource(
147 IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_HTML);
Scott Chenf68c9b22018-10-12 02:15:25148
Scott Chenaac2e182018-10-23 01:49:44149 // chrome://welcome/email-interstitial
150 html_source->AddResourcePath(
151 "email-interstitial",
152 IDR_WELCOME_ONBOARDING_WELCOME_EMAIL_INTERSTITIAL_HTML);
153
Scott Chend92e6ff2018-10-16 23:54:39154 html_source->AddResourcePath(
155 "images/background_svgs/blue_circle.svg",
156 IDR_WELCOME_ONBOARDING_WELCOME_IMAGES_BACKGROUND_SVGS_BLUE_CIRCLE_SVG);
157 html_source->AddResourcePath(
158 "images/background_svgs/green_rectangle.svg",
159 IDR_WELCOME_ONBOARDING_WELCOME_IMAGES_BACKGROUND_SVGS_GREEN_RECTANGLE_SVG);
160 html_source->AddResourcePath(
161 "images/background_svgs/grey_oval.svg",
162 IDR_WELCOME_ONBOARDING_WELCOME_IMAGES_BACKGROUND_SVGS_GREY_OVAL_SVG);
163 html_source->AddResourcePath(
164 "images/background_svgs/grey_rounded_rectangle.svg",
165 IDR_WELCOME_ONBOARDING_WELCOME_IMAGES_BACKGROUND_SVGS_GREY_ROUNDED_RECTANGLE_SVG);
166 html_source->AddResourcePath(
167 "images/background_svgs/red_triangle.svg",
168 IDR_WELCOME_ONBOARDING_WELCOME_IMAGES_BACKGROUND_SVGS_RED_TRIANGLE_SVG);
169 html_source->AddResourcePath(
170 "images/background_svgs/yellow_dots.svg",
171 IDR_WELCOME_ONBOARDING_WELCOME_IMAGES_BACKGROUND_SVGS_YELLOW_DOTS_SVG);
172 html_source->AddResourcePath(
173 "images/background_svgs/yellow_semicircle.svg",
174 IDR_WELCOME_ONBOARDING_WELCOME_IMAGES_BACKGROUND_SVGS_YELLOW_SEMICIRCLE_SVG);
Scott Chenf68c9b22018-10-12 02:15:25175
Scott Chenebfdce732018-10-26 02:34:26176 html_source->AddResourcePath("images/email_provider_1x.png",
177 IDR_NUX_EMAIL_PROVIDER_LOGO_1X);
178 html_source->AddResourcePath("images/email_provider_2x.png",
179 IDR_NUX_EMAIL_PROVIDER_LOGO_2X);
180 html_source->AddResourcePath("images/set_as_default_1x.png",
181 IDR_NUX_SET_AS_DEFAULT_LOGO_1X);
182 html_source->AddResourcePath("images/set_as_default_2x.png",
183 IDR_NUX_SET_AS_DEFAULT_LOGO_2X);
184 html_source->AddResourcePath("images/set_as_default_illustration_1x.png",
185 IDR_NUX_SET_AS_DEFAULT_ILLUSTRATION_1X);
186 html_source->AddResourcePath("images/set_as_default_illustration_2x.png",
187 IDR_NUX_SET_AS_DEFAULT_ILLUSTRATION_2X);
188
Scott Chene8414882018-10-30 03:14:35189#if defined(OS_WIN)
190 html_source->AddBoolean(
191 "is_win10", base::win::GetVersion() >= base::win::VERSION_WIN10);
192#endif
193
Hector Carmona207744f2018-10-25 23:49:54194 // Add the shared bookmark handler for onboarding modules.
195 web_ui->AddMessageHandler(
196 std::make_unique<nux::BookmarkHandler>(profile->GetPrefs()));
Hector Carmona207744f2018-10-25 23:49:54197
Scott Chenf68c9b22018-10-12 02:15:25198 // Add email provider bookmarking onboarding module.
199 web_ui->AddMessageHandler(std::make_unique<nux::EmailHandler>(
Hector Carmona207744f2018-10-25 23:49:54200 FaviconServiceFactory::GetForProfile(
201 profile, ServiceAccessType::EXPLICIT_ACCESS)));
202 nux::EmailHandler::AddSources(html_source);
Scott Chenf68c9b22018-10-12 02:15:25203
204 // Add google apps bookmarking onboarding module.
Scott Chenf68c9b22018-10-12 02:15:25205 web_ui->AddMessageHandler(std::make_unique<nux::GoogleAppsHandler>(
Hector Carmona207744f2018-10-25 23:49:54206 FaviconServiceFactory::GetForProfile(
207 profile, ServiceAccessType::EXPLICIT_ACCESS)));
208 nux::GoogleAppsHandler::AddSources(html_source);
Scott Chenf68c9b22018-10-12 02:15:25209
210 // Add set-as-default onboarding module.
211 web_ui->AddMessageHandler(std::make_unique<nux::SetAsDefaultHandler>());
Scott Chenc74ed762018-09-21 00:23:16212 } else if (kIsBranded && is_dice) {
213 // Use special layout if the application is branded and DICE is enabled.
Scott Chenc6706672017-11-17 17:40:27214 html_source->AddLocalizedString("headerText", IDS_WELCOME_HEADER);
Thomas Tangl441b06782018-09-27 19:37:07215 html_source->AddLocalizedString("acceptText",
216 IDS_PROFILES_DICE_SIGNIN_BUTTON);
Scott Chenc6706672017-11-17 17:40:27217 html_source->AddLocalizedString("secondHeaderText",
218 IDS_DICE_WELCOME_SECOND_HEADER);
219 html_source->AddLocalizedString("descriptionText",
220 IDS_DICE_WELCOME_DESCRIPTION);
221 html_source->AddLocalizedString("declineText",
222 IDS_DICE_WELCOME_DECLINE_BUTTON);
Mihai Sardarescu631f3b472018-05-04 15:08:15223 html_source->AddResourcePath("welcome_browser_proxy.html",
224 IDR_DICE_WELCOME_BROWSER_PROXY_HTML);
225 html_source->AddResourcePath("welcome_browser_proxy.js",
226 IDR_DICE_WELCOME_BROWSER_PROXY_JS);
Scott Chenc6706672017-11-17 17:40:27227 html_source->AddResourcePath("welcome_app.html", IDR_DICE_WELCOME_APP_HTML);
228 html_source->AddResourcePath("welcome_app.js", IDR_DICE_WELCOME_APP_JS);
Scott Chena1264452017-11-14 13:32:08229 html_source->AddResourcePath("welcome.css", IDR_DICE_WELCOME_CSS);
230 html_source->SetDefaultResource(IDR_DICE_WELCOME_HTML);
231 } else {
Mihai Sardarescu631f3b472018-05-04 15:08:15232 // Use default layout for non-DICE or unbranded build.
233 std::string value;
234 bool is_everywhere_variant =
235 (net::GetValueForKeyInQuery(url, "variant", &value) &&
236 value == "everywhere");
237
Scott Chenc6706672017-11-17 17:40:27238 if (kIsBranded) {
239 base::string16 subheader =
240 is_everywhere_variant
241 ? base::string16()
242 : l10n_util::GetStringUTF16(IDS_WELCOME_SUBHEADER);
243 html_source->AddString("subheaderText", subheader);
244 }
245
246 int header_id = is_everywhere_variant ? IDS_WELCOME_HEADER_AFTER_FIRST_RUN
247 : IDS_WELCOME_HEADER;
248 html_source->AddString("headerText", l10n_util::GetStringUTF16(header_id));
Thomas Tangl441b06782018-09-27 19:37:07249 html_source->AddLocalizedString("acceptText", IDS_WELCOME_ACCEPT_BUTTON);
Scott Chenc6706672017-11-17 17:40:27250 html_source->AddLocalizedString("descriptionText", IDS_WELCOME_DESCRIPTION);
251 html_source->AddLocalizedString("declineText", IDS_WELCOME_DECLINE_BUTTON);
Scott Chena1264452017-11-14 13:32:08252 html_source->AddResourcePath("welcome.js", IDR_WELCOME_JS);
253 html_source->AddResourcePath("welcome.css", IDR_WELCOME_CSS);
254 html_source->SetDefaultResource(IDR_WELCOME_HTML);
255 }
tmartinoe3f9c38e2016-09-13 14:05:32256
tmartinoe3f9c38e2016-09-13 14:05:32257 content::WebUIDataSource::Add(profile, html_source);
258}
259
260WelcomeUI::~WelcomeUI() {}
Hector Carmona8f2c3cb2018-07-12 21:07:58261
Scott Chenf68c9b22018-10-12 02:15:25262void WelcomeUI::StorePageSeen(Profile* profile) {
Hector Carmona8f2c3cb2018-07-12 21:07:58263 // Store that this profile has been shown the Welcome page.
264 profile->GetPrefs()->SetBoolean(prefs::kHasSeenWelcomePage, true);
265}