blob: c5bf7e9a6ad73ece37be31bf81ab3d811bc7285b [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
weisert3dab3b92017-01-10 10:31:177#include "base/memory/ptr_util.h"
tmartinoe3f9c38e2016-09-13 14:05:328#include "chrome/browser/profiles/profile.h"
tmartino7f0818b2016-09-27 23:39:079#include "chrome/browser/ui/webui/welcome_handler.h"
tmartino6254f472016-11-21 01:22:5610#include "chrome/common/pref_names.h"
tmartinoe3f9c38e2016-09-13 14:05:3211#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"
tmartino6254f472016-11-21 01:22:5615#include "components/prefs/pref_service.h"
Scott Chena1264452017-11-14 13:32:0816#include "components/signin/core/browser/profile_management_switches.h"
tmartinoe3f9c38e2016-09-13 14:05:3217#include "content/public/browser/web_ui_data_source.h"
tmartino7f0818b2016-09-27 23:39:0718#include "net/base/url_util.h"
tmartinoe3f9c38e2016-09-13 14:05:3219#include "ui/base/l10n/l10n_util.h"
20#include "ui/resources/grit/webui_resources.h"
21
tmartinoe3f9c38e2016-09-13 14:05:3222WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url)
23 : content::WebUIController(web_ui) {
tmartino7f0818b2016-09-27 23:39:0724 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
tmartino6254f472016-11-21 01:22:5633 // Store that this profile has been shown the Welcome page.
34 profile->GetPrefs()->SetBoolean(prefs::kHasSeenWelcomePage, true);
35
weisert3dab3b92017-01-10 10:31:1736 web_ui->AddMessageHandler(base::MakeUnique<WelcomeHandler>(web_ui));
tmartinoe3f9c38e2016-09-13 14:05:3237
38 content::WebUIDataSource* html_source =
39 content::WebUIDataSource::Create(url.host());
40
41 // Check URL for variations.
tmartino7f0818b2016-09-27 23:39:0742 std::string value;
43 bool is_everywhere_variant =
44 (net::GetValueForKeyInQuery(url, "variant", &value) &&
45 value == "everywhere");
tmartinoe3f9c38e2016-09-13 14:05:3246
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
tmartinoe3f9c38e2016-09-13 14:05:3264 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 Chena1264452017-11-14 13:32:0867
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 }
tmartinoe3f9c38e2016-09-13 14:05:3277
tmartinoe3f9c38e2016-09-13 14:05:3278 content::WebUIDataSource::Add(profile, html_source);
79}
80
81WelcomeUI::~WelcomeUI() {}