blob: 4501072230cac6fb0a2f044aac292d9e68534924 [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"
tmartino6254f472016-11-21 01:22:5625#include "components/prefs/pref_service.h"
Scott Chenf68c9b22018-10-12 02:15:2526#include "content/public/browser/web_contents.h"
tmartinoe3f9c38e2016-09-13 14:05:3227#include "content/public/browser/web_ui_data_source.h"
tmartino7f0818b2016-09-27 23:39:0728#include "net/base/url_util.h"
tmartinoe3f9c38e2016-09-13 14:05:3229#include "ui/base/l10n/l10n_util.h"
tmartinoe3f9c38e2016-09-13 14:05:3230
Scott Chenc6706672017-11-17 17:40:2731namespace {
Scott Chen532ec2c2018-09-26 21:50:0532const bool kIsBranded =
Scott Chenc6706672017-11-17 17:40:2733#if defined(GOOGLE_CHROME_BUILD)
Scott Chen532ec2c2018-09-26 21:50:0534 true;
Scott Chenc6706672017-11-17 17:40:2735#else
Scott Chen532ec2c2018-09-26 21:50:0536 false;
Scott Chenc6706672017-11-17 17:40:2737#endif
Scott Chen532ec2c2018-09-26 21:50:0538} // namespace
Scott Chenc6706672017-11-17 17:40:2739
tmartinoe3f9c38e2016-09-13 14:05:3240WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url)
41 : content::WebUIController(web_ui) {
tmartino7f0818b2016-09-27 23:39:0742 Profile* profile = Profile::FromWebUI(web_ui);
43
44 // This page is not shown to incognito or guest profiles. If one should end up
45 // here, we return, causing a 404-like page.
46 if (!profile ||
47 profile->GetProfileType() != Profile::ProfileType::REGULAR_PROFILE) {
48 return;
49 }
50
Scott Chenf68c9b22018-10-12 02:15:2551 StorePageSeen(profile);
tmartino6254f472016-11-21 01:22:5652
Jinho Bang7ab7a4e2018-01-15 14:36:0753 web_ui->AddMessageHandler(std::make_unique<WelcomeHandler>(web_ui));
tmartinoe3f9c38e2016-09-13 14:05:3254
55 content::WebUIDataSource* html_source =
56 content::WebUIDataSource::Create(url.host());
57
David Rogerf53a0752018-06-18 14:46:4858 bool is_dice =
59 AccountConsistencyModeManager::IsDiceEnabledForProfile(profile);
tmartinoe3f9c38e2016-09-13 14:05:3260
Scott Chenc6706672017-11-17 17:40:2761 // There are multiple possible configurations that affects the layout, but
62 // first add resources that are shared across all layouts.
tmartinoe3f9c38e2016-09-13 14:05:3263 html_source->AddResourcePath("logo.png", IDR_PRODUCT_LOGO_128);
64 html_source->AddResourcePath("logo2x.png", IDR_PRODUCT_LOGO_256);
Scott Chena1264452017-11-14 13:32:0865
Scott Chenf68c9b22018-10-12 02:15:2566 if (nux::IsNuxOnboardingEnabled(profile)) {
Scott Chenc74ed762018-09-21 00:23:1667 // Add Onboarding welcome strings.
68 html_source->AddLocalizedString("headerText", IDS_WELCOME_HEADER);
Thomas Tangl441b06782018-09-27 19:37:0769 html_source->AddLocalizedString("acceptText", IDS_WELCOME_ACCEPT_BUTTON);
Scott Chenc74ed762018-09-21 00:23:1670
71 // Add onboarding welcome resources.
Scott Chenc74ed762018-09-21 00:23:1672 html_source->SetDefaultResource(
73 IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_HTML);
Scott Chen7c55fd62018-09-21 02:44:4974 html_source->AddResourcePath(
75 "landing_view.html", IDR_WELCOME_ONBOARDING_WELCOME_LANDING_VIEW_HTML);
76 html_source->AddResourcePath(
77 "landing_view.js", IDR_WELCOME_ONBOARDING_WELCOME_LANDING_VIEW_JS);
Scott Chen83748da2018-09-24 19:50:0278 html_source->AddResourcePath(
79 "navigation_behavior.html",
80 IDR_WELCOME_ONBOARDING_WELCOME_NAVIGATION_BEHAVIOR_HTML);
81 html_source->AddResourcePath(
82 "navigation_behavior.js",
83 IDR_WELCOME_ONBOARDING_WELCOME_NAVIGATION_BEHAVIOR_JS);
Scott Chen7c55fd62018-09-21 02:44:4984 html_source->AddResourcePath("welcome.css",
85 IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_CSS);
86 html_source->AddResourcePath(
87 "welcome_app.html", IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_APP_HTML);
88 html_source->AddResourcePath("welcome_app.js",
89 IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_APP_JS);
Scott Chend2d64c9f2018-09-24 21:57:1490 html_source->AddResourcePath(
91 "welcome_browser_proxy.html",
92 IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_BROWSER_PROXY_HTML);
93 html_source->AddResourcePath(
94 "welcome_browser_proxy.js",
95 IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_BROWSER_PROXY_JS);
Scott Chenf68c9b22018-10-12 02:15:2596
97 // Add resources shared by the NUX modules.
98 html_source->AddResourcePath("shared/chooser_shared_css.html",
99 IDR_NUX_CHOOSER_SHARED_CSS);
100 html_source->AddResourcePath(
101 "shared/i18n_setup.html",
102 IDR_WELCOME_ONBOARDING_WELCOME_SHARED_I18N_SETUP_HTML);
103
104 // Add email provider bookmarking onboarding module.
105 web_ui->AddMessageHandler(std::make_unique<nux::EmailHandler>(
106 profile->GetPrefs(), FaviconServiceFactory::GetForProfile(
107 profile, ServiceAccessType::EXPLICIT_ACCESS)));
108 nux::EmailHandler::AddSources(html_source, profile->GetPrefs());
109
110 // Add google apps bookmarking onboarding module.
Scott Chenf68c9b22018-10-12 02:15:25111 web_ui->AddMessageHandler(std::make_unique<nux::GoogleAppsHandler>(
Hector Carmona3bde83f92018-10-13 01:03:07112 profile->GetPrefs(), FaviconServiceFactory::GetForProfile(
113 profile, ServiceAccessType::EXPLICIT_ACCESS)));
Hector Carmona104147fd2018-10-16 03:32:05114 nux::GoogleAppsHandler::AddSources(html_source, profile->GetPrefs());
Scott Chenf68c9b22018-10-12 02:15:25115
116 // Add set-as-default onboarding module.
117 web_ui->AddMessageHandler(std::make_unique<nux::SetAsDefaultHandler>());
118 nux::SetAsDefaultHandler::AddSources(html_source);
Scott Chenc74ed762018-09-21 00:23:16119 } else if (kIsBranded && is_dice) {
120 // Use special layout if the application is branded and DICE is enabled.
Scott Chenc6706672017-11-17 17:40:27121 html_source->AddLocalizedString("headerText", IDS_WELCOME_HEADER);
Thomas Tangl441b06782018-09-27 19:37:07122 html_source->AddLocalizedString("acceptText",
123 IDS_PROFILES_DICE_SIGNIN_BUTTON);
Scott Chenc6706672017-11-17 17:40:27124 html_source->AddLocalizedString("secondHeaderText",
125 IDS_DICE_WELCOME_SECOND_HEADER);
126 html_source->AddLocalizedString("descriptionText",
127 IDS_DICE_WELCOME_DESCRIPTION);
128 html_source->AddLocalizedString("declineText",
129 IDS_DICE_WELCOME_DECLINE_BUTTON);
Mihai Sardarescu631f3b472018-05-04 15:08:15130 html_source->AddResourcePath("welcome_browser_proxy.html",
131 IDR_DICE_WELCOME_BROWSER_PROXY_HTML);
132 html_source->AddResourcePath("welcome_browser_proxy.js",
133 IDR_DICE_WELCOME_BROWSER_PROXY_JS);
Scott Chenc6706672017-11-17 17:40:27134 html_source->AddResourcePath("welcome_app.html", IDR_DICE_WELCOME_APP_HTML);
135 html_source->AddResourcePath("welcome_app.js", IDR_DICE_WELCOME_APP_JS);
Scott Chena1264452017-11-14 13:32:08136 html_source->AddResourcePath("welcome.css", IDR_DICE_WELCOME_CSS);
137 html_source->SetDefaultResource(IDR_DICE_WELCOME_HTML);
138 } else {
Mihai Sardarescu631f3b472018-05-04 15:08:15139 // Use default layout for non-DICE or unbranded build.
140 std::string value;
141 bool is_everywhere_variant =
142 (net::GetValueForKeyInQuery(url, "variant", &value) &&
143 value == "everywhere");
144
Scott Chenc6706672017-11-17 17:40:27145 if (kIsBranded) {
146 base::string16 subheader =
147 is_everywhere_variant
148 ? base::string16()
149 : l10n_util::GetStringUTF16(IDS_WELCOME_SUBHEADER);
150 html_source->AddString("subheaderText", subheader);
151 }
152
153 int header_id = is_everywhere_variant ? IDS_WELCOME_HEADER_AFTER_FIRST_RUN
154 : IDS_WELCOME_HEADER;
155 html_source->AddString("headerText", l10n_util::GetStringUTF16(header_id));
Thomas Tangl441b06782018-09-27 19:37:07156 html_source->AddLocalizedString("acceptText", IDS_WELCOME_ACCEPT_BUTTON);
Scott Chenc6706672017-11-17 17:40:27157 html_source->AddLocalizedString("descriptionText", IDS_WELCOME_DESCRIPTION);
158 html_source->AddLocalizedString("declineText", IDS_WELCOME_DECLINE_BUTTON);
Scott Chena1264452017-11-14 13:32:08159 html_source->AddResourcePath("welcome.js", IDR_WELCOME_JS);
160 html_source->AddResourcePath("welcome.css", IDR_WELCOME_CSS);
161 html_source->SetDefaultResource(IDR_WELCOME_HTML);
162 }
tmartinoe3f9c38e2016-09-13 14:05:32163
tmartinoe3f9c38e2016-09-13 14:05:32164 content::WebUIDataSource::Add(profile, html_source);
165}
166
167WelcomeUI::~WelcomeUI() {}
Hector Carmona8f2c3cb2018-07-12 21:07:58168
Scott Chenf68c9b22018-10-12 02:15:25169void WelcomeUI::StorePageSeen(Profile* profile) {
Hector Carmona8f2c3cb2018-07-12 21:07:58170 // Store that this profile has been shown the Welcome page.
171 profile->GetPrefs()->SetBoolean(prefs::kHasSeenWelcomePage, true);
172}