blob: a6344041788bb451dc01b315a0606e64e4818d81 [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"
David Rogerf53a0752018-06-18 14:46:4810#include "chrome/browser/signin/account_consistency_mode_manager.h"
tmartino7f0818b2016-09-27 23:39:0711#include "chrome/browser/ui/webui/welcome_handler.h"
tmartino6254f472016-11-21 01:22:5612#include "chrome/common/pref_names.h"
tmartinoe3f9c38e2016-09-13 14:05:3213#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"
tmartino6254f472016-11-21 01:22:5617#include "components/prefs/pref_service.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
David Rogerf53a0752018-06-18 14:46:4850 bool is_dice =
51 AccountConsistencyModeManager::IsDiceEnabledForProfile(profile);
tmartinoe3f9c38e2016-09-13 14:05:3252
Scott Chenc6706672017-11-17 17:40:2753 // There are multiple possible configurations that affects the layout, but
54 // first add resources that are shared across all layouts.
tmartinoe3f9c38e2016-09-13 14:05:3255 html_source->AddLocalizedString("acceptText", IDS_WELCOME_ACCEPT_BUTTON);
tmartinoe3f9c38e2016-09-13 14:05:3256 html_source->AddResourcePath("logo.png", IDR_PRODUCT_LOGO_128);
57 html_source->AddResourcePath("logo2x.png", IDR_PRODUCT_LOGO_256);
Scott Chena1264452017-11-14 13:32:0858
Mihai Sardarescu631f3b472018-05-04 15:08:1559 // Use special layout if the application is branded and DICE is enabled.
60 // Otherwise use the default layout.
61 if (kIsBranded && is_dice) {
Scott Chenc6706672017-11-17 17:40:2762 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 Sardarescu631f3b472018-05-04 15:08:1569 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 Chenc6706672017-11-17 17:40:2773 html_source->AddResourcePath("welcome_app.html", IDR_DICE_WELCOME_APP_HTML);
74 html_source->AddResourcePath("welcome_app.js", IDR_DICE_WELCOME_APP_JS);
Scott Chena1264452017-11-14 13:32:0875 html_source->AddResourcePath("welcome.css", IDR_DICE_WELCOME_CSS);
76 html_source->SetDefaultResource(IDR_DICE_WELCOME_HTML);
77 } else {
Mihai Sardarescu631f3b472018-05-04 15:08:1578 // 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 Chenc6706672017-11-17 17:40:2784 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 Chena1264452017-11-14 13:32:0897 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 }
tmartinoe3f9c38e2016-09-13 14:05:32101
tmartinoe3f9c38e2016-09-13 14:05:32102 content::WebUIDataSource::Add(profile, html_source);
103}
104
105WelcomeUI::~WelcomeUI() {}