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" |
tmartino | 7f0818b | 2016-09-27 23:39:07 | [diff] [blame] | 10 | #include "chrome/browser/ui/webui/welcome_handler.h" |
tmartino | 6254f47 | 2016-11-21 01:22:56 | [diff] [blame] | 11 | #include "chrome/common/pref_names.h" |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 12 | #include "chrome/grit/browser_resources.h" |
| 13 | #include "chrome/grit/chrome_unscaled_resources.h" |
| 14 | #include "chrome/grit/chromium_strings.h" |
| 15 | #include "chrome/grit/generated_resources.h" |
tmartino | 6254f47 | 2016-11-21 01:22:56 | [diff] [blame] | 16 | #include "components/prefs/pref_service.h" |
Scott Chen | a126445 | 2017-11-14 13:32:08 | [diff] [blame] | 17 | #include "components/signin/core/browser/profile_management_switches.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 | |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 50 | bool is_dice = signin::IsDiceEnabledForProfile(profile->GetPrefs()); |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 51 | |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 52 | // There are multiple possible configurations that affects the layout, but |
| 53 | // first add resources that are shared across all layouts. |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 54 | html_source->AddLocalizedString("acceptText", IDS_WELCOME_ACCEPT_BUTTON); |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 55 | html_source->AddResourcePath("logo.png", IDR_PRODUCT_LOGO_128); |
| 56 | html_source->AddResourcePath("logo2x.png", IDR_PRODUCT_LOGO_256); |
Scott Chen | a126445 | 2017-11-14 13:32:08 | [diff] [blame] | 57 | |
Mihai Sardarescu | 631f3b47 | 2018-05-04 15:08:15 | [diff] [blame^] | 58 | // Use special layout if the application is branded and DICE is enabled. |
| 59 | // Otherwise use the default layout. |
| 60 | if (kIsBranded && is_dice) { |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 61 | html_source->AddLocalizedString("headerText", IDS_WELCOME_HEADER); |
| 62 | html_source->AddLocalizedString("secondHeaderText", |
| 63 | IDS_DICE_WELCOME_SECOND_HEADER); |
| 64 | html_source->AddLocalizedString("descriptionText", |
| 65 | IDS_DICE_WELCOME_DESCRIPTION); |
| 66 | html_source->AddLocalizedString("declineText", |
| 67 | IDS_DICE_WELCOME_DECLINE_BUTTON); |
Mihai Sardarescu | 631f3b47 | 2018-05-04 15:08:15 | [diff] [blame^] | 68 | html_source->AddResourcePath("welcome_browser_proxy.html", |
| 69 | IDR_DICE_WELCOME_BROWSER_PROXY_HTML); |
| 70 | html_source->AddResourcePath("welcome_browser_proxy.js", |
| 71 | IDR_DICE_WELCOME_BROWSER_PROXY_JS); |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 72 | html_source->AddResourcePath("welcome_app.html", IDR_DICE_WELCOME_APP_HTML); |
| 73 | html_source->AddResourcePath("welcome_app.js", IDR_DICE_WELCOME_APP_JS); |
Scott Chen | a126445 | 2017-11-14 13:32:08 | [diff] [blame] | 74 | html_source->AddResourcePath("welcome.css", IDR_DICE_WELCOME_CSS); |
| 75 | html_source->SetDefaultResource(IDR_DICE_WELCOME_HTML); |
| 76 | } else { |
Mihai Sardarescu | 631f3b47 | 2018-05-04 15:08:15 | [diff] [blame^] | 77 | // Use default layout for non-DICE or unbranded build. |
| 78 | std::string value; |
| 79 | bool is_everywhere_variant = |
| 80 | (net::GetValueForKeyInQuery(url, "variant", &value) && |
| 81 | value == "everywhere"); |
| 82 | |
Scott Chen | c670667 | 2017-11-17 17:40:27 | [diff] [blame] | 83 | if (kIsBranded) { |
| 84 | base::string16 subheader = |
| 85 | is_everywhere_variant |
| 86 | ? base::string16() |
| 87 | : l10n_util::GetStringUTF16(IDS_WELCOME_SUBHEADER); |
| 88 | html_source->AddString("subheaderText", subheader); |
| 89 | } |
| 90 | |
| 91 | int header_id = is_everywhere_variant ? IDS_WELCOME_HEADER_AFTER_FIRST_RUN |
| 92 | : IDS_WELCOME_HEADER; |
| 93 | html_source->AddString("headerText", l10n_util::GetStringUTF16(header_id)); |
| 94 | html_source->AddLocalizedString("descriptionText", IDS_WELCOME_DESCRIPTION); |
| 95 | html_source->AddLocalizedString("declineText", IDS_WELCOME_DECLINE_BUTTON); |
Scott Chen | a126445 | 2017-11-14 13:32:08 | [diff] [blame] | 96 | html_source->AddResourcePath("welcome.js", IDR_WELCOME_JS); |
| 97 | html_source->AddResourcePath("welcome.css", IDR_WELCOME_CSS); |
| 98 | html_source->SetDefaultResource(IDR_WELCOME_HTML); |
| 99 | } |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 100 | |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 101 | content::WebUIDataSource::Add(profile, html_source); |
| 102 | } |
| 103 | |
| 104 | WelcomeUI::~WelcomeUI() {} |