blob: 9ee2f1ff1ae0791fe3e1f4a6a848c1590a8b74b3 [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"
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 Chenc6706672017-11-17 17:40:2734namespace {
Scott Chen532ec2c2018-09-26 21:50:0535const bool kIsBranded =
Scott Chenc6706672017-11-17 17:40:2736#if defined(GOOGLE_CHROME_BUILD)
Scott Chen532ec2c2018-09-26 21:50:0537 true;
Scott Chenc6706672017-11-17 17:40:2738#else
Scott Chen532ec2c2018-09-26 21:50:0539 false;
Scott Chenc6706672017-11-17 17:40:2740#endif
Scott Chen532ec2c2018-09-26 21:50:0541} // namespace
Scott Chenc6706672017-11-17 17:40:2742
Scott Chen395516b2018-10-23 00:05:4843// TODO(scottchen): reuse instead of copy from
44// md_settings_localized_strings_provider.cc.
45struct LocalizedString {
46 const char* name;
47 int id;
48};
49
50void AddOnboardingStrings(content::WebUIDataSource* html_source) {
51 static constexpr LocalizedString kLocalizedStrings[] = {
52 // Shared strings.
53 {"headerText", IDS_WELCOME_HEADER},
54 {"acceptText", IDS_WELCOME_ACCEPT_BUTTON},
55 {"noThanks", IDS_NO_THANKS},
56 {"getStarted", IDS_ONBOARDING_WELCOME_GET_STARTED},
57 {"bookmarkAdded", IDS_ONBOARDING_WELCOME_BOOKMARK_ADDED},
58 {"bookmarkRemoved", IDS_ONBOARDING_WELCOME_BOOKMARK_REMOVED},
59 {"bookmarkReplaced", IDS_ONBOARDING_WELCOME_BOOKMARK_REPLACED},
60
61 // Sign-in view strings.
62 {"signInHeader", IDS_ONBOARDING_WELCOME_SIGNIN_VIEW_HEADER},
63 {"signInSubHeader", IDS_ONBOARDING_WELCOME_SIGNIN_VIEW_SUB_HEADER},
64 {"signIn", IDS_ONBOARDING_WELCOME_SIGNIN_VIEW_SIGNIN},
65
66 // Email provider module strings.
67 {"welcomeTitle", IDS_ONBOARDING_WELCOME_NUX_EMAIL_WELCOME_TITLE},
68 {"emailPrompt", IDS_ONBOARDING_WELCOME_NUX_EMAIL_PROMPT},
69
70 // Google apps module strings.
71 {"googleAppsDescription",
72 IDS_ONBOARDING_WELCOME_NUX_GOOGLE_APPS_DESCRIPTION},
73
74 // Set as default module strings.
75 {"setDefaultHeader", IDS_ONBOARDING_WELCOME_NUX_SET_AS_DEFAULT_HEADER},
76 {"setDefaultSubHeader",
77 IDS_ONBOARDING_WELCOME_NUX_SET_AS_DEFAULT_SUB_HEADER},
78 {"setDefaultSkip", IDS_ONBOARDING_WELCOME_NUX_SET_AS_DEFAULT_SKIP},
79 {"setDefaultConfirm",
80 IDS_ONBOARDING_WELCOME_NUX_SET_AS_DEFAULT_SET_AS_DEFAULT},
81 };
82
83 // TODO(scottchen): reuse instead of copy from
84 // md_settings_localized_strings_provider.cc.
85 for (size_t i = 0; i < base::size(kLocalizedStrings); i++) {
86 html_source->AddLocalizedString(kLocalizedStrings[i].name,
87 kLocalizedStrings[i].id);
88 }
89}
90
tmartinoe3f9c38e2016-09-13 14:05:3291WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url)
92 : content::WebUIController(web_ui) {
tmartino7f0818b2016-09-27 23:39:0793 Profile* profile = Profile::FromWebUI(web_ui);
94
95 // This page is not shown to incognito or guest profiles. If one should end up
96 // here, we return, causing a 404-like page.
97 if (!profile ||
98 profile->GetProfileType() != Profile::ProfileType::REGULAR_PROFILE) {
99 return;
100 }
101
Scott Chenf68c9b22018-10-12 02:15:25102 StorePageSeen(profile);
tmartino6254f472016-11-21 01:22:56103
Jinho Bang7ab7a4e2018-01-15 14:36:07104 web_ui->AddMessageHandler(std::make_unique<WelcomeHandler>(web_ui));
tmartinoe3f9c38e2016-09-13 14:05:32105
106 content::WebUIDataSource* html_source =
107 content::WebUIDataSource::Create(url.host());
108
David Rogerf53a0752018-06-18 14:46:48109 bool is_dice =
110 AccountConsistencyModeManager::IsDiceEnabledForProfile(profile);
tmartinoe3f9c38e2016-09-13 14:05:32111
Scott Chenc6706672017-11-17 17:40:27112 // There are multiple possible configurations that affects the layout, but
113 // first add resources that are shared across all layouts.
tmartinoe3f9c38e2016-09-13 14:05:32114 html_source->AddResourcePath("logo.png", IDR_PRODUCT_LOGO_128);
115 html_source->AddResourcePath("logo2x.png", IDR_PRODUCT_LOGO_256);
Scott Chena1264452017-11-14 13:32:08116
Scott Chenf68c9b22018-10-12 02:15:25117 if (nux::IsNuxOnboardingEnabled(profile)) {
Scott Chenc74ed762018-09-21 00:23:16118 // Add Onboarding welcome strings.
Scott Chen395516b2018-10-23 00:05:48119 AddOnboardingStrings(html_source);
Scott Chenc74ed762018-09-21 00:23:16120
dpapadb1f8e9a2018-10-18 21:36:08121 // Add all Onboarding resources.
122 for (size_t i = 0; i < kOnboardingWelcomeResourcesSize; ++i) {
123 html_source->AddResourcePath(kOnboardingWelcomeResources[i].name,
124 kOnboardingWelcomeResources[i].value);
125 }
Scott Chenaac2e182018-10-23 01:49:44126
127 // chrome://welcome
Scott Chenc74ed762018-09-21 00:23:16128 html_source->SetDefaultResource(
129 IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_HTML);
Scott Chenf68c9b22018-10-12 02:15:25130
Scott Chenaac2e182018-10-23 01:49:44131 // chrome://welcome/email-interstitial
132 html_source->AddResourcePath(
133 "email-interstitial",
134 IDR_WELCOME_ONBOARDING_WELCOME_EMAIL_INTERSTITIAL_HTML);
135
Scott Chend92e6ff2018-10-16 23:54:39136 html_source->AddResourcePath(
137 "images/background_svgs/blue_circle.svg",
138 IDR_WELCOME_ONBOARDING_WELCOME_IMAGES_BACKGROUND_SVGS_BLUE_CIRCLE_SVG);
139 html_source->AddResourcePath(
140 "images/background_svgs/green_rectangle.svg",
141 IDR_WELCOME_ONBOARDING_WELCOME_IMAGES_BACKGROUND_SVGS_GREEN_RECTANGLE_SVG);
142 html_source->AddResourcePath(
143 "images/background_svgs/grey_oval.svg",
144 IDR_WELCOME_ONBOARDING_WELCOME_IMAGES_BACKGROUND_SVGS_GREY_OVAL_SVG);
145 html_source->AddResourcePath(
146 "images/background_svgs/grey_rounded_rectangle.svg",
147 IDR_WELCOME_ONBOARDING_WELCOME_IMAGES_BACKGROUND_SVGS_GREY_ROUNDED_RECTANGLE_SVG);
148 html_source->AddResourcePath(
149 "images/background_svgs/red_triangle.svg",
150 IDR_WELCOME_ONBOARDING_WELCOME_IMAGES_BACKGROUND_SVGS_RED_TRIANGLE_SVG);
151 html_source->AddResourcePath(
152 "images/background_svgs/yellow_dots.svg",
153 IDR_WELCOME_ONBOARDING_WELCOME_IMAGES_BACKGROUND_SVGS_YELLOW_DOTS_SVG);
154 html_source->AddResourcePath(
155 "images/background_svgs/yellow_semicircle.svg",
156 IDR_WELCOME_ONBOARDING_WELCOME_IMAGES_BACKGROUND_SVGS_YELLOW_SEMICIRCLE_SVG);
Scott Chenf68c9b22018-10-12 02:15:25157
158 // Add email provider bookmarking onboarding module.
159 web_ui->AddMessageHandler(std::make_unique<nux::EmailHandler>(
160 profile->GetPrefs(), FaviconServiceFactory::GetForProfile(
161 profile, ServiceAccessType::EXPLICIT_ACCESS)));
162 nux::EmailHandler::AddSources(html_source, profile->GetPrefs());
163
164 // Add google apps bookmarking onboarding module.
Scott Chenf68c9b22018-10-12 02:15:25165 web_ui->AddMessageHandler(std::make_unique<nux::GoogleAppsHandler>(
Hector Carmona3bde83f92018-10-13 01:03:07166 profile->GetPrefs(), FaviconServiceFactory::GetForProfile(
167 profile, ServiceAccessType::EXPLICIT_ACCESS)));
Hector Carmona104147fd2018-10-16 03:32:05168 nux::GoogleAppsHandler::AddSources(html_source, profile->GetPrefs());
Scott Chenf68c9b22018-10-12 02:15:25169
170 // Add set-as-default onboarding module.
171 web_ui->AddMessageHandler(std::make_unique<nux::SetAsDefaultHandler>());
Scott Chenc74ed762018-09-21 00:23:16172 } else if (kIsBranded && is_dice) {
173 // Use special layout if the application is branded and DICE is enabled.
Scott Chenc6706672017-11-17 17:40:27174 html_source->AddLocalizedString("headerText", IDS_WELCOME_HEADER);
Thomas Tangl441b06782018-09-27 19:37:07175 html_source->AddLocalizedString("acceptText",
176 IDS_PROFILES_DICE_SIGNIN_BUTTON);
Scott Chenc6706672017-11-17 17:40:27177 html_source->AddLocalizedString("secondHeaderText",
178 IDS_DICE_WELCOME_SECOND_HEADER);
179 html_source->AddLocalizedString("descriptionText",
180 IDS_DICE_WELCOME_DESCRIPTION);
181 html_source->AddLocalizedString("declineText",
182 IDS_DICE_WELCOME_DECLINE_BUTTON);
Mihai Sardarescu631f3b472018-05-04 15:08:15183 html_source->AddResourcePath("welcome_browser_proxy.html",
184 IDR_DICE_WELCOME_BROWSER_PROXY_HTML);
185 html_source->AddResourcePath("welcome_browser_proxy.js",
186 IDR_DICE_WELCOME_BROWSER_PROXY_JS);
Scott Chenc6706672017-11-17 17:40:27187 html_source->AddResourcePath("welcome_app.html", IDR_DICE_WELCOME_APP_HTML);
188 html_source->AddResourcePath("welcome_app.js", IDR_DICE_WELCOME_APP_JS);
Scott Chena1264452017-11-14 13:32:08189 html_source->AddResourcePath("welcome.css", IDR_DICE_WELCOME_CSS);
190 html_source->SetDefaultResource(IDR_DICE_WELCOME_HTML);
191 } else {
Mihai Sardarescu631f3b472018-05-04 15:08:15192 // Use default layout for non-DICE or unbranded build.
193 std::string value;
194 bool is_everywhere_variant =
195 (net::GetValueForKeyInQuery(url, "variant", &value) &&
196 value == "everywhere");
197
Scott Chenc6706672017-11-17 17:40:27198 if (kIsBranded) {
199 base::string16 subheader =
200 is_everywhere_variant
201 ? base::string16()
202 : l10n_util::GetStringUTF16(IDS_WELCOME_SUBHEADER);
203 html_source->AddString("subheaderText", subheader);
204 }
205
206 int header_id = is_everywhere_variant ? IDS_WELCOME_HEADER_AFTER_FIRST_RUN
207 : IDS_WELCOME_HEADER;
208 html_source->AddString("headerText", l10n_util::GetStringUTF16(header_id));
Thomas Tangl441b06782018-09-27 19:37:07209 html_source->AddLocalizedString("acceptText", IDS_WELCOME_ACCEPT_BUTTON);
Scott Chenc6706672017-11-17 17:40:27210 html_source->AddLocalizedString("descriptionText", IDS_WELCOME_DESCRIPTION);
211 html_source->AddLocalizedString("declineText", IDS_WELCOME_DECLINE_BUTTON);
Scott Chena1264452017-11-14 13:32:08212 html_source->AddResourcePath("welcome.js", IDR_WELCOME_JS);
213 html_source->AddResourcePath("welcome.css", IDR_WELCOME_CSS);
214 html_source->SetDefaultResource(IDR_WELCOME_HTML);
215 }
tmartinoe3f9c38e2016-09-13 14:05:32216
tmartinoe3f9c38e2016-09-13 14:05:32217 content::WebUIDataSource::Add(profile, html_source);
218}
219
220WelcomeUI::~WelcomeUI() {}
Hector Carmona8f2c3cb2018-07-12 21:07:58221
Scott Chenf68c9b22018-10-12 02:15:25222void WelcomeUI::StorePageSeen(Profile* profile) {
Hector Carmona8f2c3cb2018-07-12 21:07:58223 // Store that this profile has been shown the Welcome page.
224 profile->GetPrefs()->SetBoolean(prefs::kHasSeenWelcomePage, true);
225}