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" |
tmartino | 6254f47 | 2016-11-21 01:22:56 | [diff] [blame] | 25 | #include "components/prefs/pref_service.h" |
Scott Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 26 | #include "content/public/browser/web_contents.h" |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 27 | #include "content/public/browser/web_ui_data_source.h" |
tmartino | 7f0818b | 2016-09-27 23:39:07 | [diff] [blame] | 28 | #include "net/base/url_util.h" |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 29 | #include "ui/base/l10n/l10n_util.h" |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 30 | |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 31 | namespace { |
Scott Chen | 532ec2c | 2018-09-26 21:50:05 | [diff] [blame] | 32 | const bool kIsBranded = |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 33 | #if defined(GOOGLE_CHROME_BUILD) |
Scott Chen | 532ec2c | 2018-09-26 21:50:05 | [diff] [blame] | 34 | true; |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 35 | #else |
Scott Chen | 532ec2c | 2018-09-26 21:50:05 | [diff] [blame] | 36 | false; |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 37 | #endif |
Scott Chen | 532ec2c | 2018-09-26 21:50:05 | [diff] [blame] | 38 | } // namespace |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 39 | |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 40 | WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url) |
| 41 | : content::WebUIController(web_ui) { |
tmartino | 7f0818b | 2016-09-27 23:39:07 | [diff] [blame] | 42 | 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 Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 51 | StorePageSeen(profile); |
tmartino | 6254f47 | 2016-11-21 01:22:56 | [diff] [blame] | 52 | |
Jinho Bang | 7ab7a4e | 2018-01-15 14:36:07 | [diff] [blame] | 53 | web_ui->AddMessageHandler(std::make_unique<WelcomeHandler>(web_ui)); |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 54 | |
| 55 | content::WebUIDataSource* html_source = |
| 56 | content::WebUIDataSource::Create(url.host()); |
| 57 | |
David Roger | f53a075 | 2018-06-18 14:46:48 | [diff] [blame] | 58 | bool is_dice = |
| 59 | AccountConsistencyModeManager::IsDiceEnabledForProfile(profile); |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 60 | |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 61 | // There are multiple possible configurations that affects the layout, but |
| 62 | // first add resources that are shared across all layouts. |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 63 | html_source->AddResourcePath("logo.png", IDR_PRODUCT_LOGO_128); |
| 64 | html_source->AddResourcePath("logo2x.png", IDR_PRODUCT_LOGO_256); |
Scott Chen | a126445 | 2017-11-14 13:32:08 | [diff] [blame] | 65 | |
Scott Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 66 | if (nux::IsNuxOnboardingEnabled(profile)) { |
Scott Chen | c74ed76 | 2018-09-21 00:23:16 | [diff] [blame] | 67 | // Add Onboarding welcome strings. |
| 68 | html_source->AddLocalizedString("headerText", IDS_WELCOME_HEADER); |
Thomas Tangl | 441b0678 | 2018-09-27 19:37:07 | [diff] [blame] | 69 | html_source->AddLocalizedString("acceptText", IDS_WELCOME_ACCEPT_BUTTON); |
Scott Chen | c74ed76 | 2018-09-21 00:23:16 | [diff] [blame] | 70 | |
| 71 | // Add onboarding welcome resources. |
Scott Chen | c74ed76 | 2018-09-21 00:23:16 | [diff] [blame] | 72 | html_source->SetDefaultResource( |
| 73 | IDR_WELCOME_ONBOARDING_WELCOME_WELCOME_HTML); |
Scott Chen | 7c55fd6 | 2018-09-21 02:44:49 | [diff] [blame] | 74 | 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 Chen | 83748da | 2018-09-24 19:50:02 | [diff] [blame] | 78 | 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 Chen | 7c55fd6 | 2018-09-21 02:44:49 | [diff] [blame] | 84 | 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 Chen | d2d64c9f | 2018-09-24 21:57:14 | [diff] [blame] | 90 | 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 Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 96 | |
| 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 Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 111 | web_ui->AddMessageHandler(std::make_unique<nux::GoogleAppsHandler>( |
Hector Carmona | 3bde83f9 | 2018-10-13 01:03:07 | [diff] [blame] | 112 | profile->GetPrefs(), FaviconServiceFactory::GetForProfile( |
| 113 | profile, ServiceAccessType::EXPLICIT_ACCESS))); |
Hector Carmona | 104147fd | 2018-10-16 03:32:05 | [diff] [blame^] | 114 | nux::GoogleAppsHandler::AddSources(html_source, profile->GetPrefs()); |
Scott Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 115 | |
| 116 | // Add set-as-default onboarding module. |
| 117 | web_ui->AddMessageHandler(std::make_unique<nux::SetAsDefaultHandler>()); |
| 118 | nux::SetAsDefaultHandler::AddSources(html_source); |
Scott Chen | c74ed76 | 2018-09-21 00:23:16 | [diff] [blame] | 119 | } else if (kIsBranded && is_dice) { |
| 120 | // Use special layout if the application is branded and DICE is enabled. |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 121 | html_source->AddLocalizedString("headerText", IDS_WELCOME_HEADER); |
Thomas Tangl | 441b0678 | 2018-09-27 19:37:07 | [diff] [blame] | 122 | html_source->AddLocalizedString("acceptText", |
| 123 | IDS_PROFILES_DICE_SIGNIN_BUTTON); |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 124 | 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 Sardarescu | 631f3b47 | 2018-05-04 15:08:15 | [diff] [blame] | 130 | 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 Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 134 | html_source->AddResourcePath("welcome_app.html", IDR_DICE_WELCOME_APP_HTML); |
| 135 | html_source->AddResourcePath("welcome_app.js", IDR_DICE_WELCOME_APP_JS); |
Scott Chen | a126445 | 2017-11-14 13:32:08 | [diff] [blame] | 136 | html_source->AddResourcePath("welcome.css", IDR_DICE_WELCOME_CSS); |
| 137 | html_source->SetDefaultResource(IDR_DICE_WELCOME_HTML); |
| 138 | } else { |
Mihai Sardarescu | 631f3b47 | 2018-05-04 15:08:15 | [diff] [blame] | 139 | // 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 Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 145 | 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 Tangl | 441b0678 | 2018-09-27 19:37:07 | [diff] [blame] | 156 | html_source->AddLocalizedString("acceptText", IDS_WELCOME_ACCEPT_BUTTON); |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 157 | html_source->AddLocalizedString("descriptionText", IDS_WELCOME_DESCRIPTION); |
| 158 | html_source->AddLocalizedString("declineText", IDS_WELCOME_DECLINE_BUTTON); |
Scott Chen | a126445 | 2017-11-14 13:32:08 | [diff] [blame] | 159 | 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 | } |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 163 | |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 164 | content::WebUIDataSource::Add(profile, html_source); |
| 165 | } |
| 166 | |
| 167 | WelcomeUI::~WelcomeUI() {} |
Hector Carmona | 8f2c3cb | 2018-07-12 21:07:58 | [diff] [blame] | 168 | |
Scott Chen | f68c9b2 | 2018-10-12 02:15:25 | [diff] [blame] | 169 | void WelcomeUI::StorePageSeen(Profile* profile) { |
Hector Carmona | 8f2c3cb | 2018-07-12 21:07:58 | [diff] [blame] | 170 | // Store that this profile has been shown the Welcome page. |
| 171 | profile->GetPrefs()->SetBoolean(prefs::kHasSeenWelcomePage, true); |
| 172 | } |