blob: 2be38b0a172279fca31875bc2ad66254560d720c [file] [log] [blame]
tmartinoe3f9c38e2016-09-13 14:05:321// 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 Bang7ab7a4e2018-01-15 14:36:077#include <memory>
8
Hector Carmonac98557a992018-06-27 17:51:439#include "build/build_config.h"
tmartinoe3f9c38e2016-09-13 14:05:3210#include "chrome/browser/profiles/profile.h"
David Rogerf53a0752018-06-18 14:46:4811#include "chrome/browser/signin/account_consistency_mode_manager.h"
tmartino7f0818b2016-09-27 23:39:0712#include "chrome/browser/ui/webui/welcome_handler.h"
tmartino6254f472016-11-21 01:22:5613#include "chrome/common/pref_names.h"
tmartinoe3f9c38e2016-09-13 14:05:3214#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"
tmartino6254f472016-11-21 01:22:5618#include "components/prefs/pref_service.h"
tmartinoe3f9c38e2016-09-13 14:05:3219#include "content/public/browser/web_ui_data_source.h"
tmartino7f0818b2016-09-27 23:39:0720#include "net/base/url_util.h"
tmartinoe3f9c38e2016-09-13 14:05:3221#include "ui/base/l10n/l10n_util.h"
tmartinoe3f9c38e2016-09-13 14:05:3222
Hector Carmonac98557a992018-06-27 17:51:4323#if defined(OS_WIN)
Hector Carmona1a0aa1762018-06-21 23:12:1724#include "components/nux_google_apps/constants.h"
25#include "components/nux_google_apps/webui.h"
Hector Carmonac98557a992018-06-27 17:51:4326#endif // OS_WIN
Hector Carmona1a0aa1762018-06-21 23:12:1727
Scott Chenc6706672017-11-17 17:40:2728namespace {
29 const bool kIsBranded =
30#if defined(GOOGLE_CHROME_BUILD)
31 true;
32#else
33 false;
34#endif
35}
36
tmartinoe3f9c38e2016-09-13 14:05:3237WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url)
38 : content::WebUIController(web_ui) {
tmartino7f0818b2016-09-27 23:39:0739 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
tmartino6254f472016-11-21 01:22:5648 // Store that this profile has been shown the Welcome page.
49 profile->GetPrefs()->SetBoolean(prefs::kHasSeenWelcomePage, true);
50
Jinho Bang7ab7a4e2018-01-15 14:36:0751 web_ui->AddMessageHandler(std::make_unique<WelcomeHandler>(web_ui));
tmartinoe3f9c38e2016-09-13 14:05:3252
53 content::WebUIDataSource* html_source =
54 content::WebUIDataSource::Create(url.host());
55
David Rogerf53a0752018-06-18 14:46:4856 bool is_dice =
57 AccountConsistencyModeManager::IsDiceEnabledForProfile(profile);
tmartinoe3f9c38e2016-09-13 14:05:3258
Scott Chenc6706672017-11-17 17:40:2759 // There are multiple possible configurations that affects the layout, but
60 // first add resources that are shared across all layouts.
tmartinoe3f9c38e2016-09-13 14:05:3261 html_source->AddLocalizedString("acceptText", IDS_WELCOME_ACCEPT_BUTTON);
tmartinoe3f9c38e2016-09-13 14:05:3262 html_source->AddResourcePath("logo.png", IDR_PRODUCT_LOGO_128);
63 html_source->AddResourcePath("logo2x.png", IDR_PRODUCT_LOGO_256);
Scott Chena1264452017-11-14 13:32:0864
Mihai Sardarescu631f3b472018-05-04 15:08:1565 // Use special layout if the application is branded and DICE is enabled.
66 // Otherwise use the default layout.
67 if (kIsBranded && is_dice) {
Scott Chenc6706672017-11-17 17:40:2768 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 Sardarescu631f3b472018-05-04 15:08:1575 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 Chenc6706672017-11-17 17:40:2779 html_source->AddResourcePath("welcome_app.html", IDR_DICE_WELCOME_APP_HTML);
80 html_source->AddResourcePath("welcome_app.js", IDR_DICE_WELCOME_APP_JS);
Scott Chena1264452017-11-14 13:32:0881 html_source->AddResourcePath("welcome.css", IDR_DICE_WELCOME_CSS);
82 html_source->SetDefaultResource(IDR_DICE_WELCOME_HTML);
83 } else {
Mihai Sardarescu631f3b472018-05-04 15:08:1584 // 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 Chenc6706672017-11-17 17:40:2790 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 Chena1264452017-11-14 13:32:08103 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 }
tmartinoe3f9c38e2016-09-13 14:05:32107
Hector Carmonac98557a992018-06-27 17:51:43108#if defined(OS_WIN)
Hector Carmona1a0aa1762018-06-21 23:12:17109 if (base::FeatureList::IsEnabled(nux_google_apps::kNuxGoogleAppsFeature)) {
110 nux_google_apps::AddSources(html_source);
111 }
Hector Carmonac98557a992018-06-27 17:51:43112#endif // OS_WIN
Hector Carmona1a0aa1762018-06-21 23:12:17113
tmartinoe3f9c38e2016-09-13 14:05:32114 content::WebUIDataSource::Add(profile, html_source);
115}
116
117WelcomeUI::~WelcomeUI() {}