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 | |
weisert | 3dab3b9 | 2017-01-10 10:31:17 | [diff] [blame] | 7 | #include "base/memory/ptr_util.h" |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 8 | #include "chrome/browser/profiles/profile.h" |
tmartino | 7f0818b | 2016-09-27 23:39:07 | [diff] [blame] | 9 | #include "chrome/browser/ui/webui/welcome_handler.h" |
tmartino | 6254f47 | 2016-11-21 01:22:56 | [diff] [blame] | 10 | #include "chrome/common/pref_names.h" |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 11 | #include "chrome/grit/browser_resources.h" |
| 12 | #include "chrome/grit/chrome_unscaled_resources.h" |
| 13 | #include "chrome/grit/chromium_strings.h" |
| 14 | #include "chrome/grit/generated_resources.h" |
tmartino | 6254f47 | 2016-11-21 01:22:56 | [diff] [blame] | 15 | #include "components/prefs/pref_service.h" |
Scott Chen | a126445 | 2017-11-14 13:32:08 | [diff] [blame^] | 16 | #include "components/signin/core/browser/profile_management_switches.h" |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 17 | #include "content/public/browser/web_ui_data_source.h" |
tmartino | 7f0818b | 2016-09-27 23:39:07 | [diff] [blame] | 18 | #include "net/base/url_util.h" |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 19 | #include "ui/base/l10n/l10n_util.h" |
| 20 | #include "ui/resources/grit/webui_resources.h" |
| 21 | |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 22 | WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url) |
| 23 | : content::WebUIController(web_ui) { |
tmartino | 7f0818b | 2016-09-27 23:39:07 | [diff] [blame] | 24 | Profile* profile = Profile::FromWebUI(web_ui); |
| 25 | |
| 26 | // This page is not shown to incognito or guest profiles. If one should end up |
| 27 | // here, we return, causing a 404-like page. |
| 28 | if (!profile || |
| 29 | profile->GetProfileType() != Profile::ProfileType::REGULAR_PROFILE) { |
| 30 | return; |
| 31 | } |
| 32 | |
tmartino | 6254f47 | 2016-11-21 01:22:56 | [diff] [blame] | 33 | // Store that this profile has been shown the Welcome page. |
| 34 | profile->GetPrefs()->SetBoolean(prefs::kHasSeenWelcomePage, true); |
| 35 | |
weisert | 3dab3b9 | 2017-01-10 10:31:17 | [diff] [blame] | 36 | web_ui->AddMessageHandler(base::MakeUnique<WelcomeHandler>(web_ui)); |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 37 | |
| 38 | content::WebUIDataSource* html_source = |
| 39 | content::WebUIDataSource::Create(url.host()); |
| 40 | |
| 41 | // Check URL for variations. |
tmartino | 7f0818b | 2016-09-27 23:39:07 | [diff] [blame] | 42 | std::string value; |
| 43 | bool is_everywhere_variant = |
| 44 | (net::GetValueForKeyInQuery(url, "variant", &value) && |
| 45 | value == "everywhere"); |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 46 | |
| 47 | int header_id = is_everywhere_variant ? IDS_WELCOME_HEADER_AFTER_FIRST_RUN |
| 48 | : IDS_WELCOME_HEADER; |
| 49 | html_source->AddString("headerText", l10n_util::GetStringUTF16(header_id)); |
| 50 | |
| 51 | // The subheader describes the browser as being "by Google", so we only show |
| 52 | // it in the "Welcome to Chrome" variant, and only on branded builds. |
| 53 | #if defined(GOOGLE_CHROME_BUILD) |
| 54 | base::string16 subheader = |
| 55 | is_everywhere_variant ? base::string16() |
| 56 | : l10n_util::GetStringUTF16(IDS_WELCOME_SUBHEADER); |
| 57 | html_source->AddString("subheaderText", subheader); |
| 58 | #endif |
| 59 | |
| 60 | html_source->AddLocalizedString("descriptionText", IDS_WELCOME_DESCRIPTION); |
| 61 | html_source->AddLocalizedString("acceptText", IDS_WELCOME_ACCEPT_BUTTON); |
| 62 | html_source->AddLocalizedString("declineText", IDS_WELCOME_DECLINE_BUTTON); |
| 63 | |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 64 | html_source->AddResourcePath("logo.png", IDR_PRODUCT_LOGO_128); |
| 65 | html_source->AddResourcePath("logo2x.png", IDR_PRODUCT_LOGO_256); |
| 66 | html_source->AddResourcePath("watermark.svg", IDR_WEBUI_IMAGES_GOOGLE_LOGO); |
Scott Chen | a126445 | 2017-11-14 13:32:08 | [diff] [blame^] | 67 | |
| 68 | if (signin::IsDiceEnabledForProfile(profile->GetPrefs())) { |
| 69 | html_source->AddResourcePath("welcome.js", IDR_DICE_WELCOME_JS); |
| 70 | html_source->AddResourcePath("welcome.css", IDR_DICE_WELCOME_CSS); |
| 71 | html_source->SetDefaultResource(IDR_DICE_WELCOME_HTML); |
| 72 | } else { |
| 73 | html_source->AddResourcePath("welcome.js", IDR_WELCOME_JS); |
| 74 | html_source->AddResourcePath("welcome.css", IDR_WELCOME_CSS); |
| 75 | html_source->SetDefaultResource(IDR_WELCOME_HTML); |
| 76 | } |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 77 | |
tmartino | e3f9c38e | 2016-09-13 14:05:32 | [diff] [blame] | 78 | content::WebUIDataSource::Add(profile, html_source); |
| 79 | } |
| 80 | |
| 81 | WelcomeUI::~WelcomeUI() {} |