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 | |
| 5 | #include "chrome/browser/ui/webui/welcome_ui.h" |
| 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" |
tmartino | 7f0818b | 2016-09-27 23:39:07 | [diff] [blame] | 13 | #include "chrome/browser/ui/webui/welcome_handler.h" |
tmartino | 6254f47 | 2016-11-21 01:22:56 | [diff] [blame] | 14 | #include "chrome/common/pref_names.h" |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 15 | #include "chrome/grit/browser_resources.h" |
| 16 | #include "chrome/grit/chrome_unscaled_resources.h" |
| 17 | #include "chrome/grit/chromium_strings.h" |
| 18 | #include "chrome/grit/generated_resources.h" |
tmartino | 6254f47 | 2016-11-21 01:22:56 | [diff] [blame] | 19 | #include "components/prefs/pref_service.h" |
Hector Carmona | 82ae5869 | 2018-08-09 22:43:00 | [diff] [blame^] | 20 | #include "components/sync/driver/sync_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" |
| 28 | #include "components/nux/show_promo_delegate.h" |
Hector Carmona | 1a0aa176 | 2018-06-21 23:12:17 | [diff] [blame] | 29 | #include "components/nux_google_apps/constants.h" |
Hector Carmona | 71eb6b2 | 2018-07-25 21:43:56 | [diff] [blame] | 30 | #include "components/nux_google_apps/google_apps_handler.h" |
| 31 | #include "content/public/browser/web_contents.h" |
Hector Carmona | 8f2c3cb | 2018-07-12 21:07:58 | [diff] [blame] | 32 | #endif // defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) |
Hector Carmona | 1a0aa176 | 2018-06-21 23:12:17 | [diff] [blame] | 33 | |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 34 | namespace { |
| 35 | const bool kIsBranded = |
| 36 | #if defined(GOOGLE_CHROME_BUILD) |
| 37 | true; |
| 38 | #else |
| 39 | false; |
| 40 | #endif |
| 41 | } |
| 42 | |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 43 | WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url) |
| 44 | : content::WebUIController(web_ui) { |
tmartino | 7f0818b | 2016-09-27 23:39:07 | [diff] [blame] | 45 | Profile* profile = Profile::FromWebUI(web_ui); |
| 46 | |
| 47 | // This page is not shown to incognito or guest profiles. If one should end up |
| 48 | // here, we return, causing a 404-like page. |
| 49 | if (!profile || |
| 50 | profile->GetProfileType() != Profile::ProfileType::REGULAR_PROFILE) { |
| 51 | return; |
| 52 | } |
| 53 | |
Hector Carmona | 8f2c3cb | 2018-07-12 21:07:58 | [diff] [blame] | 54 | StorePageSeen(profile, url); |
tmartino | 6254f47 | 2016-11-21 01:22:56 | [diff] [blame] | 55 | |
Jinho Bang | 7ab7a4e | 2018-01-15 14:36:07 | [diff] [blame] | 56 | web_ui->AddMessageHandler(std::make_unique<WelcomeHandler>(web_ui)); |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 57 | |
| 58 | content::WebUIDataSource* html_source = |
| 59 | content::WebUIDataSource::Create(url.host()); |
| 60 | |
David Roger | f53a075 | 2018-06-18 14:46:48 | [diff] [blame] | 61 | bool is_dice = |
| 62 | AccountConsistencyModeManager::IsDiceEnabledForProfile(profile); |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 63 | |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 64 | // There are multiple possible configurations that affects the layout, but |
| 65 | // first add resources that are shared across all layouts. |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 66 | html_source->AddLocalizedString("acceptText", IDS_WELCOME_ACCEPT_BUTTON); |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 67 | html_source->AddResourcePath("logo.png", IDR_PRODUCT_LOGO_128); |
| 68 | html_source->AddResourcePath("logo2x.png", IDR_PRODUCT_LOGO_256); |
Scott Chen | a126445 | 2017-11-14 13:32:08 | [diff] [blame] | 69 | |
Mihai Sardarescu | 631f3b47 | 2018-05-04 15:08:15 | [diff] [blame] | 70 | // Use special layout if the application is branded and DICE is enabled. |
| 71 | // Otherwise use the default layout. |
| 72 | if (kIsBranded && is_dice) { |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 73 | html_source->AddLocalizedString("headerText", IDS_WELCOME_HEADER); |
| 74 | html_source->AddLocalizedString("secondHeaderText", |
| 75 | IDS_DICE_WELCOME_SECOND_HEADER); |
| 76 | html_source->AddLocalizedString("descriptionText", |
| 77 | IDS_DICE_WELCOME_DESCRIPTION); |
| 78 | html_source->AddLocalizedString("declineText", |
| 79 | IDS_DICE_WELCOME_DECLINE_BUTTON); |
Mihai Sardarescu | 631f3b47 | 2018-05-04 15:08:15 | [diff] [blame] | 80 | html_source->AddResourcePath("welcome_browser_proxy.html", |
| 81 | IDR_DICE_WELCOME_BROWSER_PROXY_HTML); |
| 82 | html_source->AddResourcePath("welcome_browser_proxy.js", |
| 83 | IDR_DICE_WELCOME_BROWSER_PROXY_JS); |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 84 | html_source->AddResourcePath("welcome_app.html", IDR_DICE_WELCOME_APP_HTML); |
| 85 | html_source->AddResourcePath("welcome_app.js", IDR_DICE_WELCOME_APP_JS); |
Scott Chen | a126445 | 2017-11-14 13:32:08 | [diff] [blame] | 86 | html_source->AddResourcePath("welcome.css", IDR_DICE_WELCOME_CSS); |
| 87 | html_source->SetDefaultResource(IDR_DICE_WELCOME_HTML); |
| 88 | } else { |
Mihai Sardarescu | 631f3b47 | 2018-05-04 15:08:15 | [diff] [blame] | 89 | // Use default layout for non-DICE or unbranded build. |
| 90 | std::string value; |
| 91 | bool is_everywhere_variant = |
| 92 | (net::GetValueForKeyInQuery(url, "variant", &value) && |
| 93 | value == "everywhere"); |
| 94 | |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 95 | if (kIsBranded) { |
| 96 | base::string16 subheader = |
| 97 | is_everywhere_variant |
| 98 | ? base::string16() |
| 99 | : l10n_util::GetStringUTF16(IDS_WELCOME_SUBHEADER); |
| 100 | html_source->AddString("subheaderText", subheader); |
| 101 | } |
| 102 | |
| 103 | int header_id = is_everywhere_variant ? IDS_WELCOME_HEADER_AFTER_FIRST_RUN |
| 104 | : IDS_WELCOME_HEADER; |
| 105 | html_source->AddString("headerText", l10n_util::GetStringUTF16(header_id)); |
| 106 | html_source->AddLocalizedString("descriptionText", IDS_WELCOME_DESCRIPTION); |
| 107 | html_source->AddLocalizedString("declineText", IDS_WELCOME_DECLINE_BUTTON); |
Scott Chen | a126445 | 2017-11-14 13:32:08 | [diff] [blame] | 108 | html_source->AddResourcePath("welcome.js", IDR_WELCOME_JS); |
| 109 | html_source->AddResourcePath("welcome.css", IDR_WELCOME_CSS); |
| 110 | html_source->SetDefaultResource(IDR_WELCOME_HTML); |
| 111 | } |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 112 | |
Hector Carmona | 8f2c3cb | 2018-07-12 21:07:58 | [diff] [blame] | 113 | #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) |
Hector Carmona | 1a0aa176 | 2018-06-21 23:12:17 | [diff] [blame] | 114 | if (base::FeatureList::IsEnabled(nux_google_apps::kNuxGoogleAppsFeature)) { |
Hector Carmona | 71eb6b2 | 2018-07-25 21:43:56 | [diff] [blame] | 115 | content::BrowserContext* browser_context = |
| 116 | web_ui->GetWebContents()->GetBrowserContext(); |
| 117 | web_ui->AddMessageHandler( |
| 118 | std::make_unique<nux_google_apps::GoogleAppsHandler>( |
| 119 | profile->GetPrefs(), |
Hector Carmona | 82ae5869 | 2018-08-09 22:43:00 | [diff] [blame^] | 120 | FaviconServiceFactory::GetForProfile( |
| 121 | profile, ServiceAccessType::EXPLICIT_ACCESS), |
Hector Carmona | 71eb6b2 | 2018-07-25 21:43:56 | [diff] [blame] | 122 | BookmarkModelFactory::GetForBrowserContext(browser_context))); |
| 123 | |
| 124 | nux_google_apps::GoogleAppsHandler::AddSources(html_source); |
Hector Carmona | 1a0aa176 | 2018-06-21 23:12:17 | [diff] [blame] | 125 | } |
Hector Carmona | 8f2c3cb | 2018-07-12 21:07:58 | [diff] [blame] | 126 | #endif // defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD |
Hector Carmona | 1a0aa176 | 2018-06-21 23:12:17 | [diff] [blame] | 127 | |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 128 | content::WebUIDataSource::Add(profile, html_source); |
| 129 | } |
| 130 | |
| 131 | WelcomeUI::~WelcomeUI() {} |
Hector Carmona | 8f2c3cb | 2018-07-12 21:07:58 | [diff] [blame] | 132 | |
| 133 | void WelcomeUI::StorePageSeen(Profile* profile, const GURL& url) { |
| 134 | #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) |
| 135 | if (url.EqualsIgnoringRef(GURL(nux_google_apps::kNuxGoogleAppsUrl))) { |
| 136 | // Record that the new user experience page was visited. |
| 137 | profile->GetPrefs()->SetBoolean(prefs::kHasSeenGoogleAppsPromoPage, true); |
Hector Carmona | bf593d54 | 2018-07-31 21:43:05 | [diff] [blame] | 138 | |
| 139 | // Record UMA. |
| 140 | UMA_HISTOGRAM_ENUMERATION( |
| 141 | nux_google_apps::kGoogleAppsInteractionHistogram, |
| 142 | nux_google_apps::GoogleAppsInteraction::kPromptShown, |
| 143 | nux_google_apps::GoogleAppsInteraction::kCount); |
Hector Carmona | 8f2c3cb | 2018-07-12 21:07:58 | [diff] [blame] | 144 | return; |
| 145 | } |
| 146 | #endif // defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) |
| 147 | |
| 148 | // Store that this profile has been shown the Welcome page. |
| 149 | profile->GetPrefs()->SetBoolean(prefs::kHasSeenWelcomePage, true); |
| 150 | } |