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