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 | |
Scott Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 10 | #include "base/metrics/histogram_macros.h" |
Hector Carmona | c98557a99 | 2018-06-27 17:51:43 | [diff] [blame] | 11 | #include "build/build_config.h" |
Hector Carmona | 82ae5869 | 2018-08-09 22:43:00 | [diff] [blame] | 12 | #include "chrome/browser/favicon/favicon_service_factory.h" |
David Roger | f53a075 | 2018-06-18 14:46:48 | [diff] [blame] | 13 | #include "chrome/browser/signin/account_consistency_mode_manager.h" |
Scott Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 14 | #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 Chen | c74ed76 | 2018-09-21 00:23:16 | [diff] [blame] | 18 | #include "chrome/browser/ui/webui/welcome/nux_helper.h" |
Scott Chen | 532ec2c | 2018-09-26 21:50:05 | [diff] [blame] | 19 | #include "chrome/browser/ui/webui/welcome/welcome_handler.h" |
tmartino | 6254f47 | 2016-11-21 01:22:56 | [diff] [blame] | 20 | #include "chrome/common/pref_names.h" |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 21 | #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" |
dpapad | b1f8e9a | 2018-10-18 21:36:08 | [diff] [blame] | 25 | #include "chrome/grit/onboarding_welcome_resources.h" |
| 26 | #include "chrome/grit/onboarding_welcome_resources_map.h" |
tmartino | 6254f47 | 2016-11-21 01:22:56 | [diff] [blame] | 27 | #include "components/prefs/pref_service.h" |
Scott Chen | 395516b | 2018-10-23 00:05:48 | [diff] [blame] | 28 | #include "components/strings/grit/components_strings.h" |
Scott Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 29 | #include "content/public/browser/web_contents.h" |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 30 | #include "content/public/browser/web_ui_data_source.h" |
tmartino | 7f0818b | 2016-09-27 23:39:07 | [diff] [blame] | 31 | #include "net/base/url_util.h" |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 32 | #include "ui/base/l10n/l10n_util.h" |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 33 | |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 34 | namespace { |
Scott Chen | 532ec2c | 2018-09-26 21:50:05 | [diff] [blame] | 35 | const bool kIsBranded = |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 36 | #if defined(GOOGLE_CHROME_BUILD) |
Scott Chen | 532ec2c | 2018-09-26 21:50:05 | [diff] [blame] | 37 | true; |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 38 | #else |
Scott Chen | 532ec2c | 2018-09-26 21:50:05 | [diff] [blame] | 39 | false; |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 40 | #endif |
Scott Chen | 532ec2c | 2018-09-26 21:50:05 | [diff] [blame] | 41 | } // namespace |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 42 | |
Scott Chen | 395516b | 2018-10-23 00:05:48 | [diff] [blame] | 43 | // TODO(scottchen): reuse instead of copy from |
| 44 | // md_settings_localized_strings_provider.cc. |
| 45 | struct LocalizedString { |
| 46 | const char* name; |
| 47 | int id; |
| 48 | }; |
| 49 | |
| 50 | void 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 | |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 91 | WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url) |
| 92 | : content::WebUIController(web_ui) { |
tmartino | 7f0818b | 2016-09-27 23:39:07 | [diff] [blame] | 93 | 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 Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 102 | StorePageSeen(profile); |
tmartino | 6254f47 | 2016-11-21 01:22:56 | [diff] [blame] | 103 | |
Jinho Bang | 7ab7a4e | 2018-01-15 14:36:07 | [diff] [blame] | 104 | web_ui->AddMessageHandler(std::make_unique<WelcomeHandler>(web_ui)); |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 105 | |
| 106 | content::WebUIDataSource* html_source = |
| 107 | content::WebUIDataSource::Create(url.host()); |
| 108 | |
David Roger | f53a075 | 2018-06-18 14:46:48 | [diff] [blame] | 109 | bool is_dice = |
| 110 | AccountConsistencyModeManager::IsDiceEnabledForProfile(profile); |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 111 | |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 112 | // There are multiple possible configurations that affects the layout, but |
| 113 | // first add resources that are shared across all layouts. |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 114 | html_source->AddResourcePath("logo.png", IDR_PRODUCT_LOGO_128); |
| 115 | html_source->AddResourcePath("logo2x.png", IDR_PRODUCT_LOGO_256); |
Scott Chen | a126445 | 2017-11-14 13:32:08 | [diff] [blame] | 116 | |
Scott Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 117 | if (nux::IsNuxOnboardingEnabled(profile)) { |
Scott Chen | c74ed76 | 2018-09-21 00:23:16 | [diff] [blame] | 118 | // Add Onboarding welcome strings. |
Scott Chen | 395516b | 2018-10-23 00:05:48 | [diff] [blame] | 119 | AddOnboardingStrings(html_source); |
Scott Chen | c74ed76 | 2018-09-21 00:23:16 | [diff] [blame] | 120 | |
dpapad | b1f8e9a | 2018-10-18 21:36:08 | [diff] [blame] | 121 | // 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 Chen | aac2e18 | 2018-10-23 01:49:44 | [diff] [blame^] | 126 | |
| 127 | // chrome://welcome |
Scott Chen | c74ed76 | 2018-09-21 00:23:16 | [diff] [blame] | 128 | html_source->SetDefaultResource( |
| 129 | IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_HTML); |
Scott Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 130 | |
Scott Chen | aac2e18 | 2018-10-23 01:49:44 | [diff] [blame^] | 131 | // chrome://welcome/email-interstitial |
| 132 | html_source->AddResourcePath( |
| 133 | "email-interstitial", |
| 134 | IDR_WELCOME_ONBOARDING_WELCOME_EMAIL_INTERSTITIAL_HTML); |
| 135 | |
Scott Chen | d92e6ff | 2018-10-16 23:54:39 | [diff] [blame] | 136 | 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 Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 157 | |
| 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 Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 165 | web_ui->AddMessageHandler(std::make_unique<nux::GoogleAppsHandler>( |
Hector Carmona | 3bde83f9 | 2018-10-13 01:03:07 | [diff] [blame] | 166 | profile->GetPrefs(), FaviconServiceFactory::GetForProfile( |
| 167 | profile, ServiceAccessType::EXPLICIT_ACCESS))); |
Hector Carmona | 104147fd | 2018-10-16 03:32:05 | [diff] [blame] | 168 | nux::GoogleAppsHandler::AddSources(html_source, profile->GetPrefs()); |
Scott Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 169 | |
| 170 | // Add set-as-default onboarding module. |
| 171 | web_ui->AddMessageHandler(std::make_unique<nux::SetAsDefaultHandler>()); |
Scott Chen | c74ed76 | 2018-09-21 00:23:16 | [diff] [blame] | 172 | } else if (kIsBranded && is_dice) { |
| 173 | // Use special layout if the application is branded and DICE is enabled. |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 174 | html_source->AddLocalizedString("headerText", IDS_WELCOME_HEADER); |
Thomas Tangl | 441b0678 | 2018-09-27 19:37:07 | [diff] [blame] | 175 | html_source->AddLocalizedString("acceptText", |
| 176 | IDS_PROFILES_DICE_SIGNIN_BUTTON); |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 177 | 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 Sardarescu | 631f3b47 | 2018-05-04 15:08:15 | [diff] [blame] | 183 | 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 Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 187 | html_source->AddResourcePath("welcome_app.html", IDR_DICE_WELCOME_APP_HTML); |
| 188 | html_source->AddResourcePath("welcome_app.js", IDR_DICE_WELCOME_APP_JS); |
Scott Chen | a126445 | 2017-11-14 13:32:08 | [diff] [blame] | 189 | html_source->AddResourcePath("welcome.css", IDR_DICE_WELCOME_CSS); |
| 190 | html_source->SetDefaultResource(IDR_DICE_WELCOME_HTML); |
| 191 | } else { |
Mihai Sardarescu | 631f3b47 | 2018-05-04 15:08:15 | [diff] [blame] | 192 | // 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 Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 198 | 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 Tangl | 441b0678 | 2018-09-27 19:37:07 | [diff] [blame] | 209 | html_source->AddLocalizedString("acceptText", IDS_WELCOME_ACCEPT_BUTTON); |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 210 | html_source->AddLocalizedString("descriptionText", IDS_WELCOME_DESCRIPTION); |
| 211 | html_source->AddLocalizedString("declineText", IDS_WELCOME_DECLINE_BUTTON); |
Scott Chen | a126445 | 2017-11-14 13:32:08 | [diff] [blame] | 212 | 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 | } |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 216 | |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 217 | content::WebUIDataSource::Add(profile, html_source); |
| 218 | } |
| 219 | |
| 220 | WelcomeUI::~WelcomeUI() {} |
Hector Carmona | 8f2c3cb | 2018-07-12 21:07:58 | [diff] [blame] | 221 | |
Scott Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 222 | void WelcomeUI::StorePageSeen(Profile* profile) { |
Hector Carmona | 8f2c3cb | 2018-07-12 21:07:58 | [diff] [blame] | 223 | // Store that this profile has been shown the Welcome page. |
| 224 | profile->GetPrefs()->SetBoolean(prefs::kHasSeenWelcomePage, true); |
| 225 | } |