blob: 16af7154fea4010d31d4ad2e2d6c1b4b4d7980de [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
tmartinoe3f9c38e2016-09-13 14:05:329#include "chrome/browser/profiles/profile.h"
tmartino7f0818b2016-09-27 23:39:0710#include "chrome/browser/ui/webui/welcome_handler.h"
tmartino6254f472016-11-21 01:22:5611#include "chrome/common/pref_names.h"
tmartinoe3f9c38e2016-09-13 14:05:3212#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"
tmartino6254f472016-11-21 01:22:5616#include "components/prefs/pref_service.h"
Scott Chena1264452017-11-14 13:32:0817#include "components/signin/core/browser/profile_management_switches.h"
tmartinoe3f9c38e2016-09-13 14:05:3218#include "content/public/browser/web_ui_data_source.h"
tmartino7f0818b2016-09-27 23:39:0719#include "net/base/url_util.h"
tmartinoe3f9c38e2016-09-13 14:05:3220#include "ui/base/l10n/l10n_util.h"
tmartinoe3f9c38e2016-09-13 14:05:3221
Scott Chenc6706672017-11-17 17:40:2722namespace {
23 const bool kIsBranded =
24#if defined(GOOGLE_CHROME_BUILD)
25 true;
26#else
27 false;
28#endif
29}
30
tmartinoe3f9c38e2016-09-13 14:05:3231WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url)
32 : content::WebUIController(web_ui) {
tmartino7f0818b2016-09-27 23:39:0733 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
tmartino6254f472016-11-21 01:22:5642 // Store that this profile has been shown the Welcome page.
43 profile->GetPrefs()->SetBoolean(prefs::kHasSeenWelcomePage, true);
44
Jinho Bang7ab7a4e2018-01-15 14:36:0745 web_ui->AddMessageHandler(std::make_unique<WelcomeHandler>(web_ui));
tmartinoe3f9c38e2016-09-13 14:05:3246
47 content::WebUIDataSource* html_source =
48 content::WebUIDataSource::Create(url.host());
49
Scott Chenc6706672017-11-17 17:40:2750 bool is_dice = signin::IsDiceEnabledForProfile(profile->GetPrefs());
tmartinoe3f9c38e2016-09-13 14:05:3251
Scott Chenc6706672017-11-17 17:40:2752 // There are multiple possible configurations that affects the layout, but
53 // first add resources that are shared across all layouts.
tmartinoe3f9c38e2016-09-13 14:05:3254 html_source->AddLocalizedString("acceptText", IDS_WELCOME_ACCEPT_BUTTON);
tmartinoe3f9c38e2016-09-13 14:05:3255 html_source->AddResourcePath("logo.png", IDR_PRODUCT_LOGO_128);
56 html_source->AddResourcePath("logo2x.png", IDR_PRODUCT_LOGO_256);
Scott Chena1264452017-11-14 13:32:0857
Mihai Sardarescu631f3b472018-05-04 15:08:1558 // Use special layout if the application is branded and DICE is enabled.
59 // Otherwise use the default layout.
60 if (kIsBranded && is_dice) {
Scott Chenc6706672017-11-17 17:40:2761 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 Sardarescu631f3b472018-05-04 15:08:1568 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 Chenc6706672017-11-17 17:40:2772 html_source->AddResourcePath("welcome_app.html", IDR_DICE_WELCOME_APP_HTML);
73 html_source->AddResourcePath("welcome_app.js", IDR_DICE_WELCOME_APP_JS);
Scott Chena1264452017-11-14 13:32:0874 html_source->AddResourcePath("welcome.css", IDR_DICE_WELCOME_CSS);
75 html_source->SetDefaultResource(IDR_DICE_WELCOME_HTML);
76 } else {
Mihai Sardarescu631f3b472018-05-04 15:08:1577 // 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 Chenc6706672017-11-17 17:40:2783 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 Chena1264452017-11-14 13:32:0896 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 }
tmartinoe3f9c38e2016-09-13 14:05:32100
tmartinoe3f9c38e2016-09-13 14:05:32101 content::WebUIDataSource::Add(profile, html_source);
102}
103
104WelcomeUI::~WelcomeUI() {}