tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 1 | // 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 Chen | 532ec2c | 2018-09-26 21:50:05 | [diff] [blame^] | 5 | #include "chrome/browser/ui/webui/welcome/welcome_ui.h" |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 6 | |
Jinho Bang | 7ab7a4e | 2018-01-15 14:36:07 | [diff] [blame] | 7 | #include <memory> |
Hector Carmona | 8f2c3cb | 2018-07-12 21:07:58 | [diff] [blame] | 8 | #include <string> |
Jinho Bang | 7ab7a4e | 2018-01-15 14:36:07 | [diff] [blame] | 9 | |
Hector Carmona | c98557a99 | 2018-06-27 17:51:43 | [diff] [blame] | 10 | #include "build/build_config.h" |
Hector Carmona | 82ae5869 | 2018-08-09 22:43:00 | [diff] [blame] | 11 | #include "chrome/browser/favicon/favicon_service_factory.h" |
David Roger | f53a075 | 2018-06-18 14:46:48 | [diff] [blame] | 12 | #include "chrome/browser/signin/account_consistency_mode_manager.h" |
Scott Chen | c74ed76 | 2018-09-21 00:23:16 | [diff] [blame] | 13 | #include "chrome/browser/ui/webui/welcome/nux_helper.h" |
Scott Chen | 532ec2c | 2018-09-26 21:50:05 | [diff] [blame^] | 14 | #include "chrome/browser/ui/webui/welcome/welcome_handler.h" |
tmartino | 6254f47 | 2016-11-21 01:22:56 | [diff] [blame] | 15 | #include "chrome/common/pref_names.h" |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 16 | #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" |
tmartino | 6254f47 | 2016-11-21 01:22:56 | [diff] [blame] | 20 | #include "components/prefs/pref_service.h" |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 21 | #include "content/public/browser/web_ui_data_source.h" |
tmartino | 7f0818b | 2016-09-27 23:39:07 | [diff] [blame] | 22 | #include "net/base/url_util.h" |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 23 | #include "ui/base/l10n/l10n_util.h" |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 24 | |
Hector Carmona | 8f2c3cb | 2018-07-12 21:07:58 | [diff] [blame] | 25 | #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) |
Hector Carmona | bf593d54 | 2018-07-31 21:43:05 | [diff] [blame] | 26 | #include "base/metrics/histogram_macros.h" |
Hector Carmona | 71eb6b2 | 2018-07-25 21:43:56 | [diff] [blame] | 27 | #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
Scott Chen | 750635e | 2018-08-29 23:02:09 | [diff] [blame] | 28 | #include "components/nux/constants.h" |
Hector Carmona | 8a6cc7e | 2018-08-23 17:37:25 | [diff] [blame] | 29 | #include "components/nux/email/email_handler.h" |
Hector Carmona | 8e6f1aa | 2018-08-23 00:12:00 | [diff] [blame] | 30 | #include "components/nux/google_apps/google_apps_handler.h" |
Scott Chen | de13ab1 | 2018-09-05 03:06:10 | [diff] [blame] | 31 | #include "components/nux/set_as_default/set_as_default_handler.h" |
Hector Carmona | 71eb6b2 | 2018-07-25 21:43:56 | [diff] [blame] | 32 | #include "components/nux/show_promo_delegate.h" |
Hector Carmona | 71eb6b2 | 2018-07-25 21:43:56 | [diff] [blame] | 33 | #include "content/public/browser/web_contents.h" |
Hector Carmona | 8f2c3cb | 2018-07-12 21:07:58 | [diff] [blame] | 34 | #endif // defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) |
Hector Carmona | 1a0aa176 | 2018-06-21 23:12:17 | [diff] [blame] | 35 | |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 36 | namespace { |
Scott Chen | 532ec2c | 2018-09-26 21:50:05 | [diff] [blame^] | 37 | const bool kIsBranded = |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 38 | #if defined(GOOGLE_CHROME_BUILD) |
Scott Chen | 532ec2c | 2018-09-26 21:50:05 | [diff] [blame^] | 39 | true; |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 40 | #else |
Scott Chen | 532ec2c | 2018-09-26 21:50:05 | [diff] [blame^] | 41 | false; |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 42 | #endif |
Scott Chen | 532ec2c | 2018-09-26 21:50:05 | [diff] [blame^] | 43 | } // namespace |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 44 | |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 45 | WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url) |
| 46 | : content::WebUIController(web_ui) { |
tmartino | 7f0818b | 2016-09-27 23:39:07 | [diff] [blame] | 47 | 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 Carmona | 8f2c3cb | 2018-07-12 21:07:58 | [diff] [blame] | 56 | StorePageSeen(profile, url); |
tmartino | 6254f47 | 2016-11-21 01:22:56 | [diff] [blame] | 57 | |
Jinho Bang | 7ab7a4e | 2018-01-15 14:36:07 | [diff] [blame] | 58 | web_ui->AddMessageHandler(std::make_unique<WelcomeHandler>(web_ui)); |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 59 | |
| 60 | content::WebUIDataSource* html_source = |
| 61 | content::WebUIDataSource::Create(url.host()); |
| 62 | |
David Roger | f53a075 | 2018-06-18 14:46:48 | [diff] [blame] | 63 | bool is_dice = |
| 64 | AccountConsistencyModeManager::IsDiceEnabledForProfile(profile); |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 65 | |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 66 | // There are multiple possible configurations that affects the layout, but |
| 67 | // first add resources that are shared across all layouts. |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 68 | html_source->AddLocalizedString("acceptText", IDS_WELCOME_ACCEPT_BUTTON); |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 69 | html_source->AddResourcePath("logo.png", IDR_PRODUCT_LOGO_128); |
| 70 | html_source->AddResourcePath("logo2x.png", IDR_PRODUCT_LOGO_256); |
Scott Chen | a126445 | 2017-11-14 13:32:08 | [diff] [blame] | 71 | |
Scott Chen | c74ed76 | 2018-09-21 00:23:16 | [diff] [blame] | 72 | if (nux::IsNuxOnboardingEnabled()) { |
| 73 | // Add Onboarding welcome strings. |
| 74 | html_source->AddLocalizedString("headerText", IDS_WELCOME_HEADER); |
| 75 | |
| 76 | // Add onboarding welcome resources. |
Scott Chen | c74ed76 | 2018-09-21 00:23:16 | [diff] [blame] | 77 | html_source->SetDefaultResource( |
| 78 | IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_HTML); |
Scott Chen | 7c55fd6 | 2018-09-21 02:44:49 | [diff] [blame] | 79 | 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 Chen | 83748da | 2018-09-24 19:50:02 | [diff] [blame] | 83 | 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 Chen | 7c55fd6 | 2018-09-21 02:44:49 | [diff] [blame] | 89 | 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 Chen | d2d64c9f | 2018-09-24 21:57:14 | [diff] [blame] | 95 | 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 Chen | c74ed76 | 2018-09-21 00:23:16 | [diff] [blame] | 101 | } 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 Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 104 | 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 Sardarescu | 631f3b47 | 2018-05-04 15:08:15 | [diff] [blame] | 111 | 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 Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 115 | html_source->AddResourcePath("welcome_app.html", IDR_DICE_WELCOME_APP_HTML); |
| 116 | html_source->AddResourcePath("welcome_app.js", IDR_DICE_WELCOME_APP_JS); |
Scott Chen | a126445 | 2017-11-14 13:32:08 | [diff] [blame] | 117 | html_source->AddResourcePath("welcome.css", IDR_DICE_WELCOME_CSS); |
| 118 | html_source->SetDefaultResource(IDR_DICE_WELCOME_HTML); |
| 119 | } else { |
Mihai Sardarescu | 631f3b47 | 2018-05-04 15:08:15 | [diff] [blame] | 120 | // 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 Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 126 | 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 Chen | a126445 | 2017-11-14 13:32:08 | [diff] [blame] | 139 | 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 | } |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 143 | |
Hector Carmona | 8f2c3cb | 2018-07-12 21:07:58 | [diff] [blame] | 144 | #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) |
Scott Chen | de13ab1 | 2018-09-05 03:06:10 | [diff] [blame] | 145 | 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 Chen | 90dd804 | 2018-09-07 22:33:01 | [diff] [blame] | 153 | // 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 Carmona | 8a6cc7e | 2018-08-23 17:37:25 | [diff] [blame] | 162 | web_ui->AddMessageHandler(std::make_unique<nux::EmailHandler>( |
Hector Carmona | 0659b19 | 2018-09-11 01:33:21 | [diff] [blame] | 163 | profile->GetPrefs(), FaviconServiceFactory::GetForProfile( |
| 164 | profile, ServiceAccessType::EXPLICIT_ACCESS))); |
Hector Carmona | 8a6cc7e | 2018-08-23 17:37:25 | [diff] [blame] | 165 | |
Hector Carmona | d048470 | 2018-09-06 20:11:27 | [diff] [blame] | 166 | nux::EmailHandler::AddSources(html_source, profile->GetPrefs()); |
Hector Carmona | 8a6cc7e | 2018-08-23 17:37:25 | [diff] [blame] | 167 | } |
| 168 | |
Scott Chen | 90dd804 | 2018-09-07 22:33:01 | [diff] [blame] | 169 | if (onboard_during_nux && |
| 170 | base::FeatureList::IsEnabled(nux::kNuxGoogleAppsFeature)) { |
Hector Carmona | 71eb6b2 | 2018-07-25 21:43:56 | [diff] [blame] | 171 | content::BrowserContext* browser_context = |
| 172 | web_ui->GetWebContents()->GetBrowserContext(); |
Hector Carmona | 8e6f1aa | 2018-08-23 00:12:00 | [diff] [blame] | 173 | 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 Carmona | 71eb6b2 | 2018-07-25 21:43:56 | [diff] [blame] | 178 | |
Hector Carmona | 8e6f1aa | 2018-08-23 00:12:00 | [diff] [blame] | 179 | nux::GoogleAppsHandler::AddSources(html_source); |
Hector Carmona | 1a0aa176 | 2018-06-21 23:12:17 | [diff] [blame] | 180 | } |
Hector Carmona | 8f2c3cb | 2018-07-12 21:07:58 | [diff] [blame] | 181 | #endif // defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD |
Hector Carmona | 1a0aa176 | 2018-06-21 23:12:17 | [diff] [blame] | 182 | |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 183 | content::WebUIDataSource::Add(profile, html_source); |
| 184 | } |
| 185 | |
| 186 | WelcomeUI::~WelcomeUI() {} |
Hector Carmona | 8f2c3cb | 2018-07-12 21:07:58 | [diff] [blame] | 187 | |
| 188 | void WelcomeUI::StorePageSeen(Profile* profile, const GURL& url) { |
| 189 | #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) |
Hector Carmona | 8e6f1aa | 2018-08-23 00:12:00 | [diff] [blame] | 190 | if (url.EqualsIgnoringRef(GURL(nux::kNuxGoogleAppsUrl))) { |
Hector Carmona | 8f2c3cb | 2018-07-12 21:07:58 | [diff] [blame] | 191 | // Record that the new user experience page was visited. |
| 192 | profile->GetPrefs()->SetBoolean(prefs::kHasSeenGoogleAppsPromoPage, true); |
Hector Carmona | bf593d54 | 2018-07-31 21:43:05 | [diff] [blame] | 193 | |
| 194 | // Record UMA. |
Hector Carmona | 8e6f1aa | 2018-08-23 00:12:00 | [diff] [blame] | 195 | UMA_HISTOGRAM_ENUMERATION(nux::kGoogleAppsInteractionHistogram, |
| 196 | nux::GoogleAppsInteraction::kPromptShown, |
| 197 | nux::GoogleAppsInteraction::kCount); |
Hector Carmona | 8f2c3cb | 2018-07-12 21:07:58 | [diff] [blame] | 198 | return; |
| 199 | } |
Scott Chen | 90dd804 | 2018-09-07 22:33:01 | [diff] [blame] | 200 | |
| 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 Carmona | 8f2c3cb | 2018-07-12 21:07:58 | [diff] [blame] | 209 | #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 | } |