blob: 4bcca49cb976ca079c264d62ceee94f6e01e4090 [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>
Hector Carmona8f2c3cb2018-07-12 21:07:588#include <string>
Jinho Bang7ab7a4e2018-01-15 14:36:079
Hector Carmonac98557a992018-06-27 17:51:4310#include "build/build_config.h"
Hector Carmona82ae58692018-08-09 22:43:0011#include "chrome/browser/favicon/favicon_service_factory.h"
David Rogerf53a0752018-06-18 14:46:4812#include "chrome/browser/signin/account_consistency_mode_manager.h"
tmartino7f0818b2016-09-27 23:39:0713#include "chrome/browser/ui/webui/welcome_handler.h"
tmartino6254f472016-11-21 01:22:5614#include "chrome/common/pref_names.h"
tmartinoe3f9c38e2016-09-13 14:05:3215#include "chrome/grit/browser_resources.h"
16#include "chrome/grit/chrome_unscaled_resources.h"
17#include "chrome/grit/chromium_strings.h"
18#include "chrome/grit/generated_resources.h"
tmartino6254f472016-11-21 01:22:5619#include "components/prefs/pref_service.h"
Hector Carmona82ae58692018-08-09 22:43:0020#include "components/sync/driver/sync_service.h"
tmartinoe3f9c38e2016-09-13 14:05:3221#include "content/public/browser/web_ui_data_source.h"
tmartino7f0818b2016-09-27 23:39:0722#include "net/base/url_util.h"
tmartinoe3f9c38e2016-09-13 14:05:3223#include "ui/base/l10n/l10n_util.h"
tmartinoe3f9c38e2016-09-13 14:05:3224
Hector Carmona8f2c3cb2018-07-12 21:07:5825#if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)
Hector Carmonabf593d542018-07-31 21:43:0526#include "base/metrics/histogram_macros.h"
Hector Carmona71eb6b22018-07-25 21:43:5627#include "chrome/browser/bookmarks/bookmark_model_factory.h"
28#include "components/nux/show_promo_delegate.h"
Hector Carmona1a0aa1762018-06-21 23:12:1729#include "components/nux_google_apps/constants.h"
Hector Carmona71eb6b22018-07-25 21:43:5630#include "components/nux_google_apps/google_apps_handler.h"
31#include "content/public/browser/web_contents.h"
Hector Carmona8f2c3cb2018-07-12 21:07:5832#endif // defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)
Hector Carmona1a0aa1762018-06-21 23:12:1733
Scott Chenc6706672017-11-17 17:40:2734namespace {
35 const bool kIsBranded =
36#if defined(GOOGLE_CHROME_BUILD)
37 true;
38#else
39 false;
40#endif
41}
42
tmartinoe3f9c38e2016-09-13 14:05:3243WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url)
44 : content::WebUIController(web_ui) {
tmartino7f0818b2016-09-27 23:39:0745 Profile* profile = Profile::FromWebUI(web_ui);
46
47 // This page is not shown to incognito or guest profiles. If one should end up
48 // here, we return, causing a 404-like page.
49 if (!profile ||
50 profile->GetProfileType() != Profile::ProfileType::REGULAR_PROFILE) {
51 return;
52 }
53
Hector Carmona8f2c3cb2018-07-12 21:07:5854 StorePageSeen(profile, url);
tmartino6254f472016-11-21 01:22:5655
Jinho Bang7ab7a4e2018-01-15 14:36:0756 web_ui->AddMessageHandler(std::make_unique<WelcomeHandler>(web_ui));
tmartinoe3f9c38e2016-09-13 14:05:3257
58 content::WebUIDataSource* html_source =
59 content::WebUIDataSource::Create(url.host());
60
David Rogerf53a0752018-06-18 14:46:4861 bool is_dice =
62 AccountConsistencyModeManager::IsDiceEnabledForProfile(profile);
tmartinoe3f9c38e2016-09-13 14:05:3263
Scott Chenc6706672017-11-17 17:40:2764 // There are multiple possible configurations that affects the layout, but
65 // first add resources that are shared across all layouts.
tmartinoe3f9c38e2016-09-13 14:05:3266 html_source->AddLocalizedString("acceptText", IDS_WELCOME_ACCEPT_BUTTON);
tmartinoe3f9c38e2016-09-13 14:05:3267 html_source->AddResourcePath("logo.png", IDR_PRODUCT_LOGO_128);
68 html_source->AddResourcePath("logo2x.png", IDR_PRODUCT_LOGO_256);
Scott Chena1264452017-11-14 13:32:0869
Mihai Sardarescu631f3b472018-05-04 15:08:1570 // Use special layout if the application is branded and DICE is enabled.
71 // Otherwise use the default layout.
72 if (kIsBranded && is_dice) {
Scott Chenc6706672017-11-17 17:40:2773 html_source->AddLocalizedString("headerText", IDS_WELCOME_HEADER);
74 html_source->AddLocalizedString("secondHeaderText",
75 IDS_DICE_WELCOME_SECOND_HEADER);
76 html_source->AddLocalizedString("descriptionText",
77 IDS_DICE_WELCOME_DESCRIPTION);
78 html_source->AddLocalizedString("declineText",
79 IDS_DICE_WELCOME_DECLINE_BUTTON);
Mihai Sardarescu631f3b472018-05-04 15:08:1580 html_source->AddResourcePath("welcome_browser_proxy.html",
81 IDR_DICE_WELCOME_BROWSER_PROXY_HTML);
82 html_source->AddResourcePath("welcome_browser_proxy.js",
83 IDR_DICE_WELCOME_BROWSER_PROXY_JS);
Scott Chenc6706672017-11-17 17:40:2784 html_source->AddResourcePath("welcome_app.html", IDR_DICE_WELCOME_APP_HTML);
85 html_source->AddResourcePath("welcome_app.js", IDR_DICE_WELCOME_APP_JS);
Scott Chena1264452017-11-14 13:32:0886 html_source->AddResourcePath("welcome.css", IDR_DICE_WELCOME_CSS);
87 html_source->SetDefaultResource(IDR_DICE_WELCOME_HTML);
88 } else {
Mihai Sardarescu631f3b472018-05-04 15:08:1589 // Use default layout for non-DICE or unbranded build.
90 std::string value;
91 bool is_everywhere_variant =
92 (net::GetValueForKeyInQuery(url, "variant", &value) &&
93 value == "everywhere");
94
Scott Chenc6706672017-11-17 17:40:2795 if (kIsBranded) {
96 base::string16 subheader =
97 is_everywhere_variant
98 ? base::string16()
99 : l10n_util::GetStringUTF16(IDS_WELCOME_SUBHEADER);
100 html_source->AddString("subheaderText", subheader);
101 }
102
103 int header_id = is_everywhere_variant ? IDS_WELCOME_HEADER_AFTER_FIRST_RUN
104 : IDS_WELCOME_HEADER;
105 html_source->AddString("headerText", l10n_util::GetStringUTF16(header_id));
106 html_source->AddLocalizedString("descriptionText", IDS_WELCOME_DESCRIPTION);
107 html_source->AddLocalizedString("declineText", IDS_WELCOME_DECLINE_BUTTON);
Scott Chena1264452017-11-14 13:32:08108 html_source->AddResourcePath("welcome.js", IDR_WELCOME_JS);
109 html_source->AddResourcePath("welcome.css", IDR_WELCOME_CSS);
110 html_source->SetDefaultResource(IDR_WELCOME_HTML);
111 }
tmartinoe3f9c38e2016-09-13 14:05:32112
Hector Carmona8f2c3cb2018-07-12 21:07:58113#if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)
Hector Carmona1a0aa1762018-06-21 23:12:17114 if (base::FeatureList::IsEnabled(nux_google_apps::kNuxGoogleAppsFeature)) {
Hector Carmona71eb6b22018-07-25 21:43:56115 content::BrowserContext* browser_context =
116 web_ui->GetWebContents()->GetBrowserContext();
117 web_ui->AddMessageHandler(
118 std::make_unique<nux_google_apps::GoogleAppsHandler>(
119 profile->GetPrefs(),
Hector Carmona82ae58692018-08-09 22:43:00120 FaviconServiceFactory::GetForProfile(
121 profile, ServiceAccessType::EXPLICIT_ACCESS),
Hector Carmona71eb6b22018-07-25 21:43:56122 BookmarkModelFactory::GetForBrowserContext(browser_context)));
123
124 nux_google_apps::GoogleAppsHandler::AddSources(html_source);
Hector Carmona1a0aa1762018-06-21 23:12:17125 }
Hector Carmona8f2c3cb2018-07-12 21:07:58126#endif // defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD
Hector Carmona1a0aa1762018-06-21 23:12:17127
tmartinoe3f9c38e2016-09-13 14:05:32128 content::WebUIDataSource::Add(profile, html_source);
129}
130
131WelcomeUI::~WelcomeUI() {}
Hector Carmona8f2c3cb2018-07-12 21:07:58132
133void WelcomeUI::StorePageSeen(Profile* profile, const GURL& url) {
134#if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)
135 if (url.EqualsIgnoringRef(GURL(nux_google_apps::kNuxGoogleAppsUrl))) {
136 // Record that the new user experience page was visited.
137 profile->GetPrefs()->SetBoolean(prefs::kHasSeenGoogleAppsPromoPage, true);
Hector Carmonabf593d542018-07-31 21:43:05138
139 // Record UMA.
140 UMA_HISTOGRAM_ENUMERATION(
141 nux_google_apps::kGoogleAppsInteractionHistogram,
142 nux_google_apps::GoogleAppsInteraction::kPromptShown,
143 nux_google_apps::GoogleAppsInteraction::kCount);
Hector Carmona8f2c3cb2018-07-12 21:07:58144 return;
145 }
146#endif // defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)
147
148 // Store that this profile has been shown the Welcome page.
149 profile->GetPrefs()->SetBoolean(prefs::kHasSeenWelcomePage, true);
150}