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