blob: 501dbc713a7285de5982168ec9c4f3d837c962f7 [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
Hector Carmonac98557a992018-06-27 17:51:4310#include "build/build_config.h"
Hector Carmona82ae58692018-08-09 22:43:0011#include "chrome/browser/favicon/favicon_service_factory.h"
David Rogerf53a0752018-06-18 14:46:4812#include "chrome/browser/signin/account_consistency_mode_manager.h"
Scott Chenc74ed762018-09-21 00:23:1613#include "chrome/browser/ui/webui/welcome/nux_helper.h"
Scott Chen532ec2c2018-09-26 21:50:0514#include "chrome/browser/ui/webui/welcome/welcome_handler.h"
tmartino6254f472016-11-21 01:22:5615#include "chrome/common/pref_names.h"
tmartinoe3f9c38e2016-09-13 14:05:3216#include "chrome/grit/browser_resources.h"
17#include "chrome/grit/chrome_unscaled_resources.h"
18#include "chrome/grit/chromium_strings.h"
19#include "chrome/grit/generated_resources.h"
tmartino6254f472016-11-21 01:22:5620#include "components/prefs/pref_service.h"
tmartinoe3f9c38e2016-09-13 14:05:3221#include "content/public/browser/web_ui_data_source.h"
tmartino7f0818b2016-09-27 23:39:0722#include "net/base/url_util.h"
tmartinoe3f9c38e2016-09-13 14:05:3223#include "ui/base/l10n/l10n_util.h"
tmartinoe3f9c38e2016-09-13 14:05:3224
Hector Carmona8f2c3cb2018-07-12 21:07:5825#if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)
Hector Carmonabf593d542018-07-31 21:43:0526#include "base/metrics/histogram_macros.h"
Hector Carmona71eb6b22018-07-25 21:43:5627#include "chrome/browser/bookmarks/bookmark_model_factory.h"
Scott Chen750635e2018-08-29 23:02:0928#include "components/nux/constants.h"
Hector Carmona8a6cc7e2018-08-23 17:37:2529#include "components/nux/email/email_handler.h"
Hector Carmona8e6f1aa2018-08-23 00:12:0030#include "components/nux/google_apps/google_apps_handler.h"
Scott Chende13ab12018-09-05 03:06:1031#include "components/nux/set_as_default/set_as_default_handler.h"
Hector Carmona71eb6b22018-07-25 21:43:5632#include "components/nux/show_promo_delegate.h"
Hector Carmona71eb6b22018-07-25 21:43:5633#include "content/public/browser/web_contents.h"
Hector Carmona8f2c3cb2018-07-12 21:07:5834#endif // defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)
Hector Carmona1a0aa1762018-06-21 23:12:1735
Scott Chenc6706672017-11-17 17:40:2736namespace {
Scott Chen532ec2c2018-09-26 21:50:0537const bool kIsBranded =
Scott Chenc6706672017-11-17 17:40:2738#if defined(GOOGLE_CHROME_BUILD)
Scott Chen532ec2c2018-09-26 21:50:0539 true;
Scott Chenc6706672017-11-17 17:40:2740#else
Scott Chen532ec2c2018-09-26 21:50:0541 false;
Scott Chenc6706672017-11-17 17:40:2742#endif
Scott Chen532ec2c2018-09-26 21:50:0543} // namespace
Scott Chenc6706672017-11-17 17:40:2744
tmartinoe3f9c38e2016-09-13 14:05:3245WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url)
46 : content::WebUIController(web_ui) {
tmartino7f0818b2016-09-27 23:39:0747 Profile* profile = Profile::FromWebUI(web_ui);
48
49 // This page is not shown to incognito or guest profiles. If one should end up
50 // here, we return, causing a 404-like page.
51 if (!profile ||
52 profile->GetProfileType() != Profile::ProfileType::REGULAR_PROFILE) {
53 return;
54 }
55
Hector Carmona8f2c3cb2018-07-12 21:07:5856 StorePageSeen(profile, url);
tmartino6254f472016-11-21 01:22:5657
Jinho Bang7ab7a4e2018-01-15 14:36:0758 web_ui->AddMessageHandler(std::make_unique<WelcomeHandler>(web_ui));
tmartinoe3f9c38e2016-09-13 14:05:3259
60 content::WebUIDataSource* html_source =
61 content::WebUIDataSource::Create(url.host());
62
David Rogerf53a0752018-06-18 14:46:4863 bool is_dice =
64 AccountConsistencyModeManager::IsDiceEnabledForProfile(profile);
tmartinoe3f9c38e2016-09-13 14:05:3265
Scott Chenc6706672017-11-17 17:40:2766 // There are multiple possible configurations that affects the layout, but
67 // first add resources that are shared across all layouts.
tmartinoe3f9c38e2016-09-13 14:05:3268 html_source->AddLocalizedString("acceptText", IDS_WELCOME_ACCEPT_BUTTON);
tmartinoe3f9c38e2016-09-13 14:05:3269 html_source->AddResourcePath("logo.png", IDR_PRODUCT_LOGO_128);
70 html_source->AddResourcePath("logo2x.png", IDR_PRODUCT_LOGO_256);
Scott Chena1264452017-11-14 13:32:0871
Scott Chenc74ed762018-09-21 00:23:1672 if (nux::IsNuxOnboardingEnabled()) {
73 // Add Onboarding welcome strings.
74 html_source->AddLocalizedString("headerText", IDS_WELCOME_HEADER);
75
76 // Add onboarding welcome resources.
Scott Chenc74ed762018-09-21 00:23:1677 html_source->SetDefaultResource(
78 IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_HTML);
Scott Chen7c55fd62018-09-21 02:44:4979 html_source->AddResourcePath(
80 "landing_view.html", IDR_WELCOME_ONBOARDING_WELCOME_LANDING_VIEW_HTML);
81 html_source->AddResourcePath(
82 "landing_view.js", IDR_WELCOME_ONBOARDING_WELCOME_LANDING_VIEW_JS);
Scott Chen83748da2018-09-24 19:50:0283 html_source->AddResourcePath(
84 "navigation_behavior.html",
85 IDR_WELCOME_ONBOARDING_WELCOME_NAVIGATION_BEHAVIOR_HTML);
86 html_source->AddResourcePath(
87 "navigation_behavior.js",
88 IDR_WELCOME_ONBOARDING_WELCOME_NAVIGATION_BEHAVIOR_JS);
Scott Chen7c55fd62018-09-21 02:44:4989 html_source->AddResourcePath("welcome.css",
90 IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_CSS);
91 html_source->AddResourcePath(
92 "welcome_app.html", IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_APP_HTML);
93 html_source->AddResourcePath("welcome_app.js",
94 IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_APP_JS);
Scott Chend2d64c9f2018-09-24 21:57:1495 html_source->AddResourcePath(
96 "welcome_browser_proxy.html",
97 IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_BROWSER_PROXY_HTML);
98 html_source->AddResourcePath(
99 "welcome_browser_proxy.js",
100 IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_BROWSER_PROXY_JS);
Scott Chenc74ed762018-09-21 00:23:16101 } else if (kIsBranded && is_dice) {
102 // Use special layout if the application is branded and DICE is enabled.
103 // Otherwise use the default layout.
Scott Chenc6706672017-11-17 17:40:27104 html_source->AddLocalizedString("headerText", IDS_WELCOME_HEADER);
105 html_source->AddLocalizedString("secondHeaderText",
106 IDS_DICE_WELCOME_SECOND_HEADER);
107 html_source->AddLocalizedString("descriptionText",
108 IDS_DICE_WELCOME_DESCRIPTION);
109 html_source->AddLocalizedString("declineText",
110 IDS_DICE_WELCOME_DECLINE_BUTTON);
Mihai Sardarescu631f3b472018-05-04 15:08:15111 html_source->AddResourcePath("welcome_browser_proxy.html",
112 IDR_DICE_WELCOME_BROWSER_PROXY_HTML);
113 html_source->AddResourcePath("welcome_browser_proxy.js",
114 IDR_DICE_WELCOME_BROWSER_PROXY_JS);
Scott Chenc6706672017-11-17 17:40:27115 html_source->AddResourcePath("welcome_app.html", IDR_DICE_WELCOME_APP_HTML);
116 html_source->AddResourcePath("welcome_app.js", IDR_DICE_WELCOME_APP_JS);
Scott Chena1264452017-11-14 13:32:08117 html_source->AddResourcePath("welcome.css", IDR_DICE_WELCOME_CSS);
118 html_source->SetDefaultResource(IDR_DICE_WELCOME_HTML);
119 } else {
Mihai Sardarescu631f3b472018-05-04 15:08:15120 // Use default layout for non-DICE or unbranded build.
121 std::string value;
122 bool is_everywhere_variant =
123 (net::GetValueForKeyInQuery(url, "variant", &value) &&
124 value == "everywhere");
125
Scott Chenc6706672017-11-17 17:40:27126 if (kIsBranded) {
127 base::string16 subheader =
128 is_everywhere_variant
129 ? base::string16()
130 : l10n_util::GetStringUTF16(IDS_WELCOME_SUBHEADER);
131 html_source->AddString("subheaderText", subheader);
132 }
133
134 int header_id = is_everywhere_variant ? IDS_WELCOME_HEADER_AFTER_FIRST_RUN
135 : IDS_WELCOME_HEADER;
136 html_source->AddString("headerText", l10n_util::GetStringUTF16(header_id));
137 html_source->AddLocalizedString("descriptionText", IDS_WELCOME_DESCRIPTION);
138 html_source->AddLocalizedString("declineText", IDS_WELCOME_DECLINE_BUTTON);
Scott Chena1264452017-11-14 13:32:08139 html_source->AddResourcePath("welcome.js", IDR_WELCOME_JS);
140 html_source->AddResourcePath("welcome.css", IDR_WELCOME_CSS);
141 html_source->SetDefaultResource(IDR_WELCOME_HTML);
142 }
tmartinoe3f9c38e2016-09-13 14:05:32143
Hector Carmona8f2c3cb2018-07-12 21:07:58144#if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)
Scott Chende13ab12018-09-05 03:06:10145 if (base::FeatureList::IsEnabled(nux::kNuxOnboardingFeature)) {
146 web_ui->AddMessageHandler(std::make_unique<nux::SetAsDefaultHandler>());
147 nux::SetAsDefaultHandler::AddSources(html_source);
148
149 // TODO(scottchen): move all NUX features under this flag once individual
150 // experiments launch.
151 }
152
Scott Chen90dd8042018-09-07 22:33:01153 // To avoid diluting data collection, existing users should not be assigned
154 // an NUX group. So, the kOnboardDuringNUX flag is used to short-circuit the
155 // feature checks below.
156 PrefService* prefs = profile->GetPrefs();
157 bool onboard_during_nux =
158 prefs && prefs->GetBoolean(prefs::kOnboardDuringNUX);
159
160 if (onboard_during_nux &&
161 base::FeatureList::IsEnabled(nux::kNuxEmailFeature)) {
Hector Carmona8a6cc7e2018-08-23 17:37:25162 web_ui->AddMessageHandler(std::make_unique<nux::EmailHandler>(
Hector Carmona0659b192018-09-11 01:33:21163 profile->GetPrefs(), FaviconServiceFactory::GetForProfile(
164 profile, ServiceAccessType::EXPLICIT_ACCESS)));
Hector Carmona8a6cc7e2018-08-23 17:37:25165
Hector Carmonad0484702018-09-06 20:11:27166 nux::EmailHandler::AddSources(html_source, profile->GetPrefs());
Hector Carmona8a6cc7e2018-08-23 17:37:25167 }
168
Scott Chen90dd8042018-09-07 22:33:01169 if (onboard_during_nux &&
170 base::FeatureList::IsEnabled(nux::kNuxGoogleAppsFeature)) {
Hector Carmona71eb6b22018-07-25 21:43:56171 content::BrowserContext* browser_context =
172 web_ui->GetWebContents()->GetBrowserContext();
Hector Carmona8e6f1aa2018-08-23 00:12:00173 web_ui->AddMessageHandler(std::make_unique<nux::GoogleAppsHandler>(
174 profile->GetPrefs(),
175 FaviconServiceFactory::GetForProfile(
176 profile, ServiceAccessType::EXPLICIT_ACCESS),
177 BookmarkModelFactory::GetForBrowserContext(browser_context)));
Hector Carmona71eb6b22018-07-25 21:43:56178
Hector Carmona8e6f1aa2018-08-23 00:12:00179 nux::GoogleAppsHandler::AddSources(html_source);
Hector Carmona1a0aa1762018-06-21 23:12:17180 }
Hector Carmona8f2c3cb2018-07-12 21:07:58181#endif // defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD
Hector Carmona1a0aa1762018-06-21 23:12:17182
tmartinoe3f9c38e2016-09-13 14:05:32183 content::WebUIDataSource::Add(profile, html_source);
184}
185
186WelcomeUI::~WelcomeUI() {}
Hector Carmona8f2c3cb2018-07-12 21:07:58187
188void WelcomeUI::StorePageSeen(Profile* profile, const GURL& url) {
189#if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)
Hector Carmona8e6f1aa2018-08-23 00:12:00190 if (url.EqualsIgnoringRef(GURL(nux::kNuxGoogleAppsUrl))) {
Hector Carmona8f2c3cb2018-07-12 21:07:58191 // Record that the new user experience page was visited.
192 profile->GetPrefs()->SetBoolean(prefs::kHasSeenGoogleAppsPromoPage, true);
Hector Carmonabf593d542018-07-31 21:43:05193
194 // Record UMA.
Hector Carmona8e6f1aa2018-08-23 00:12:00195 UMA_HISTOGRAM_ENUMERATION(nux::kGoogleAppsInteractionHistogram,
196 nux::GoogleAppsInteraction::kPromptShown,
197 nux::GoogleAppsInteraction::kCount);
Hector Carmona8f2c3cb2018-07-12 21:07:58198 return;
199 }
Scott Chen90dd8042018-09-07 22:33:01200
201 if (url.EqualsIgnoringRef(GURL(nux::kNuxEmailUrl))) {
202 // Record that the new user experience page was visited.
203 profile->GetPrefs()->SetBoolean(prefs::kHasSeenEmailPromoPage, true);
204
205 // TODO(scottchen): Record UMA.
206
207 return;
208 }
Hector Carmona8f2c3cb2018-07-12 21:07:58209#endif // defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)
210
211 // Store that this profile has been shown the Welcome page.
212 profile->GetPrefs()->SetBoolean(prefs::kHasSeenWelcomePage, true);
213}