blob: 157214e230ed15bfcdaf9a8144a78040a64774c9 [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"
Scott Chenf68c9b22018-10-12 02:15:2512#include "chrome/browser/bookmarks/bookmark_model_factory.h"
Hector Carmona82ae58692018-08-09 22:43:0013#include "chrome/browser/favicon/favicon_service_factory.h"
David Rogerf53a0752018-06-18 14:46:4814#include "chrome/browser/signin/account_consistency_mode_manager.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"
19#include "chrome/browser/ui/webui/welcome/nux/show_promo_delegate.h"
Scott Chenc74ed762018-09-21 00:23:1620#include "chrome/browser/ui/webui/welcome/nux_helper.h"
Scott Chen532ec2c2018-09-26 21:50:0521#include "chrome/browser/ui/webui/welcome/welcome_handler.h"
tmartino6254f472016-11-21 01:22:5622#include "chrome/common/pref_names.h"
tmartinoe3f9c38e2016-09-13 14:05:3223#include "chrome/grit/browser_resources.h"
24#include "chrome/grit/chrome_unscaled_resources.h"
25#include "chrome/grit/chromium_strings.h"
26#include "chrome/grit/generated_resources.h"
tmartino6254f472016-11-21 01:22:5627#include "components/prefs/pref_service.h"
Scott Chenf68c9b22018-10-12 02:15:2528#include "content/public/browser/web_contents.h"
tmartinoe3f9c38e2016-09-13 14:05:3229#include "content/public/browser/web_ui_data_source.h"
tmartino7f0818b2016-09-27 23:39:0730#include "net/base/url_util.h"
tmartinoe3f9c38e2016-09-13 14:05:3231#include "ui/base/l10n/l10n_util.h"
tmartinoe3f9c38e2016-09-13 14:05:3232
Scott Chenc6706672017-11-17 17:40:2733namespace {
Scott Chen532ec2c2018-09-26 21:50:0534const bool kIsBranded =
Scott Chenc6706672017-11-17 17:40:2735#if defined(GOOGLE_CHROME_BUILD)
Scott Chen532ec2c2018-09-26 21:50:0536 true;
Scott Chenc6706672017-11-17 17:40:2737#else
Scott Chen532ec2c2018-09-26 21:50:0538 false;
Scott Chenc6706672017-11-17 17:40:2739#endif
Scott Chen532ec2c2018-09-26 21:50:0540} // namespace
Scott Chenc6706672017-11-17 17:40:2741
tmartinoe3f9c38e2016-09-13 14:05:3242WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url)
43 : content::WebUIController(web_ui) {
tmartino7f0818b2016-09-27 23:39:0744 Profile* profile = Profile::FromWebUI(web_ui);
45
46 // This page is not shown to incognito or guest profiles. If one should end up
47 // here, we return, causing a 404-like page.
48 if (!profile ||
49 profile->GetProfileType() != Profile::ProfileType::REGULAR_PROFILE) {
50 return;
51 }
52
Scott Chenf68c9b22018-10-12 02:15:2553 StorePageSeen(profile);
tmartino6254f472016-11-21 01:22:5654
Jinho Bang7ab7a4e2018-01-15 14:36:0755 web_ui->AddMessageHandler(std::make_unique<WelcomeHandler>(web_ui));
tmartinoe3f9c38e2016-09-13 14:05:3256
57 content::WebUIDataSource* html_source =
58 content::WebUIDataSource::Create(url.host());
59
David Rogerf53a0752018-06-18 14:46:4860 bool is_dice =
61 AccountConsistencyModeManager::IsDiceEnabledForProfile(profile);
tmartinoe3f9c38e2016-09-13 14:05:3262
Scott Chenc6706672017-11-17 17:40:2763 // There are multiple possible configurations that affects the layout, but
64 // first add resources that are shared across all layouts.
tmartinoe3f9c38e2016-09-13 14:05:3265 html_source->AddResourcePath("logo.png", IDR_PRODUCT_LOGO_128);
66 html_source->AddResourcePath("logo2x.png", IDR_PRODUCT_LOGO_256);
Scott Chena1264452017-11-14 13:32:0867
Scott Chenf68c9b22018-10-12 02:15:2568 if (nux::IsNuxOnboardingEnabled(profile)) {
Scott Chenc74ed762018-09-21 00:23:1669 // Add Onboarding welcome strings.
70 html_source->AddLocalizedString("headerText", IDS_WELCOME_HEADER);
Thomas Tangl441b06782018-09-27 19:37:0771 html_source->AddLocalizedString("acceptText", IDS_WELCOME_ACCEPT_BUTTON);
Scott Chenc74ed762018-09-21 00:23:1672
73 // Add onboarding welcome resources.
Scott Chenc74ed762018-09-21 00:23:1674 html_source->SetDefaultResource(
75 IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_HTML);
Scott Chen7c55fd62018-09-21 02:44:4976 html_source->AddResourcePath(
77 "landing_view.html", IDR_WELCOME_ONBOARDING_WELCOME_LANDING_VIEW_HTML);
78 html_source->AddResourcePath(
79 "landing_view.js", IDR_WELCOME_ONBOARDING_WELCOME_LANDING_VIEW_JS);
Scott Chen83748da2018-09-24 19:50:0280 html_source->AddResourcePath(
81 "navigation_behavior.html",
82 IDR_WELCOME_ONBOARDING_WELCOME_NAVIGATION_BEHAVIOR_HTML);
83 html_source->AddResourcePath(
84 "navigation_behavior.js",
85 IDR_WELCOME_ONBOARDING_WELCOME_NAVIGATION_BEHAVIOR_JS);
Scott Chen7c55fd62018-09-21 02:44:4986 html_source->AddResourcePath("welcome.css",
87 IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_CSS);
88 html_source->AddResourcePath(
89 "welcome_app.html", IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_APP_HTML);
90 html_source->AddResourcePath("welcome_app.js",
91 IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_APP_JS);
Scott Chend2d64c9f2018-09-24 21:57:1492 html_source->AddResourcePath(
93 "welcome_browser_proxy.html",
94 IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_BROWSER_PROXY_HTML);
95 html_source->AddResourcePath(
96 "welcome_browser_proxy.js",
97 IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_BROWSER_PROXY_JS);
Scott Chenf68c9b22018-10-12 02:15:2598
99 // Add resources shared by the NUX modules.
100 html_source->AddResourcePath("shared/chooser_shared_css.html",
101 IDR_NUX_CHOOSER_SHARED_CSS);
102 html_source->AddResourcePath(
103 "shared/i18n_setup.html",
104 IDR_WELCOME_ONBOARDING_WELCOME_SHARED_I18N_SETUP_HTML);
105
106 // Add email provider bookmarking onboarding module.
107 web_ui->AddMessageHandler(std::make_unique<nux::EmailHandler>(
108 profile->GetPrefs(), FaviconServiceFactory::GetForProfile(
109 profile, ServiceAccessType::EXPLICIT_ACCESS)));
110 nux::EmailHandler::AddSources(html_source, profile->GetPrefs());
111
112 // Add google apps bookmarking onboarding module.
113 content::BrowserContext* browser_context =
114 web_ui->GetWebContents()->GetBrowserContext();
115 web_ui->AddMessageHandler(std::make_unique<nux::GoogleAppsHandler>(
116 profile->GetPrefs(),
117 FaviconServiceFactory::GetForProfile(
118 profile, ServiceAccessType::EXPLICIT_ACCESS),
119 BookmarkModelFactory::GetForBrowserContext(browser_context)));
120 nux::GoogleAppsHandler::AddSources(html_source);
121
122 // Add set-as-default onboarding module.
123 web_ui->AddMessageHandler(std::make_unique<nux::SetAsDefaultHandler>());
124 nux::SetAsDefaultHandler::AddSources(html_source);
Scott Chenc74ed762018-09-21 00:23:16125 } else if (kIsBranded && is_dice) {
126 // Use special layout if the application is branded and DICE is enabled.
Scott Chenc6706672017-11-17 17:40:27127 html_source->AddLocalizedString("headerText", IDS_WELCOME_HEADER);
Thomas Tangl441b06782018-09-27 19:37:07128 html_source->AddLocalizedString("acceptText",
129 IDS_PROFILES_DICE_SIGNIN_BUTTON);
Scott Chenc6706672017-11-17 17:40:27130 html_source->AddLocalizedString("secondHeaderText",
131 IDS_DICE_WELCOME_SECOND_HEADER);
132 html_source->AddLocalizedString("descriptionText",
133 IDS_DICE_WELCOME_DESCRIPTION);
134 html_source->AddLocalizedString("declineText",
135 IDS_DICE_WELCOME_DECLINE_BUTTON);
Mihai Sardarescu631f3b472018-05-04 15:08:15136 html_source->AddResourcePath("welcome_browser_proxy.html",
137 IDR_DICE_WELCOME_BROWSER_PROXY_HTML);
138 html_source->AddResourcePath("welcome_browser_proxy.js",
139 IDR_DICE_WELCOME_BROWSER_PROXY_JS);
Scott Chenc6706672017-11-17 17:40:27140 html_source->AddResourcePath("welcome_app.html", IDR_DICE_WELCOME_APP_HTML);
141 html_source->AddResourcePath("welcome_app.js", IDR_DICE_WELCOME_APP_JS);
Scott Chena1264452017-11-14 13:32:08142 html_source->AddResourcePath("welcome.css", IDR_DICE_WELCOME_CSS);
143 html_source->SetDefaultResource(IDR_DICE_WELCOME_HTML);
144 } else {
Mihai Sardarescu631f3b472018-05-04 15:08:15145 // Use default layout for non-DICE or unbranded build.
146 std::string value;
147 bool is_everywhere_variant =
148 (net::GetValueForKeyInQuery(url, "variant", &value) &&
149 value == "everywhere");
150
Scott Chenc6706672017-11-17 17:40:27151 if (kIsBranded) {
152 base::string16 subheader =
153 is_everywhere_variant
154 ? base::string16()
155 : l10n_util::GetStringUTF16(IDS_WELCOME_SUBHEADER);
156 html_source->AddString("subheaderText", subheader);
157 }
158
159 int header_id = is_everywhere_variant ? IDS_WELCOME_HEADER_AFTER_FIRST_RUN
160 : IDS_WELCOME_HEADER;
161 html_source->AddString("headerText", l10n_util::GetStringUTF16(header_id));
Thomas Tangl441b06782018-09-27 19:37:07162 html_source->AddLocalizedString("acceptText", IDS_WELCOME_ACCEPT_BUTTON);
Scott Chenc6706672017-11-17 17:40:27163 html_source->AddLocalizedString("descriptionText", IDS_WELCOME_DESCRIPTION);
164 html_source->AddLocalizedString("declineText", IDS_WELCOME_DECLINE_BUTTON);
Scott Chena1264452017-11-14 13:32:08165 html_source->AddResourcePath("welcome.js", IDR_WELCOME_JS);
166 html_source->AddResourcePath("welcome.css", IDR_WELCOME_CSS);
167 html_source->SetDefaultResource(IDR_WELCOME_HTML);
168 }
tmartinoe3f9c38e2016-09-13 14:05:32169
tmartinoe3f9c38e2016-09-13 14:05:32170 content::WebUIDataSource::Add(profile, html_source);
171}
172
173WelcomeUI::~WelcomeUI() {}
Hector Carmona8f2c3cb2018-07-12 21:07:58174
Scott Chenf68c9b22018-10-12 02:15:25175void WelcomeUI::StorePageSeen(Profile* profile) {
Hector Carmona8f2c3cb2018-07-12 21:07:58176 // Store that this profile has been shown the Welcome page.
177 profile->GetPrefs()->SetBoolean(prefs::kHasSeenWelcomePage, true);
178}