Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(597)

Side by Side Diff: chrome/browser/ui/webui/welcome_ui.cc

Issue 2338213007: Adding JS and C++ handlers for events on new Welcome page. (Closed)
Patch Set: Forward Declarations Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/webui/welcome_ui.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/welcome_ui.h" 5 #include "chrome/browser/ui/webui/welcome_ui.h"
6 6
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/common/url_constants.h" 8 #include "chrome/browser/ui/webui/welcome_handler.h"
9 #include "chrome/grit/browser_resources.h" 9 #include "chrome/grit/browser_resources.h"
10 #include "chrome/grit/chrome_unscaled_resources.h" 10 #include "chrome/grit/chrome_unscaled_resources.h"
11 #include "chrome/grit/chromium_strings.h" 11 #include "chrome/grit/chromium_strings.h"
12 #include "chrome/grit/generated_resources.h" 12 #include "chrome/grit/generated_resources.h"
13 #include "content/public/browser/web_ui_data_source.h" 13 #include "content/public/browser/web_ui_data_source.h"
14 #include "net/base/url_util.h"
14 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/resources/grit/webui_resources.h" 16 #include "ui/resources/grit/webui_resources.h"
16 17
17 namespace {
18
19 // A URL ending in /1 indicates that we should modify the page to use the
20 // "Take Chrome Everywhere" text.
21 const char* kEverywhereVariantPath = "/1";
22
23 } // namespace
24
25 WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url) 18 WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url)
26 : content::WebUIController(web_ui) { 19 : content::WebUIController(web_ui) {
27 // TODO(tmartino): Create WelcomeHandler, and add here. 20 Profile* profile = Profile::FromWebUI(web_ui);
21
22 // This page is not shown to incognito or guest profiles. If one should end up
23 // here, we return, causing a 404-like page.
michaelpg 2016/09/27 21:14:12 Cool, didn't know that. It doesn't trip a DCHECK o
24 if (!profile ||
25 profile->GetProfileType() != Profile::ProfileType::REGULAR_PROFILE) {
26 return;
27 }
28
29 web_ui->AddMessageHandler(new WelcomeHandler(web_ui));
28 30
29 content::WebUIDataSource* html_source = 31 content::WebUIDataSource* html_source =
30 content::WebUIDataSource::Create(url.host()); 32 content::WebUIDataSource::Create(url.host());
31 33
32 // Check URL for variations. 34 // Check URL for variations.
33 bool is_everywhere_variant = url.path() == kEverywhereVariantPath; 35 std::string value;
36 bool is_everywhere_variant =
37 (net::GetValueForKeyInQuery(url, "variant", &value) &&
38 value == "everywhere");
34 39
35 int header_id = is_everywhere_variant ? IDS_WELCOME_HEADER_AFTER_FIRST_RUN 40 int header_id = is_everywhere_variant ? IDS_WELCOME_HEADER_AFTER_FIRST_RUN
36 : IDS_WELCOME_HEADER; 41 : IDS_WELCOME_HEADER;
37 html_source->AddString("headerText", l10n_util::GetStringUTF16(header_id)); 42 html_source->AddString("headerText", l10n_util::GetStringUTF16(header_id));
38 43
39 // The subheader describes the browser as being "by Google", so we only show 44 // The subheader describes the browser as being "by Google", so we only show
40 // it in the "Welcome to Chrome" variant, and only on branded builds. 45 // it in the "Welcome to Chrome" variant, and only on branded builds.
41 #if defined(GOOGLE_CHROME_BUILD) 46 #if defined(GOOGLE_CHROME_BUILD)
42 base::string16 subheader = 47 base::string16 subheader =
43 is_everywhere_variant ? base::string16() 48 is_everywhere_variant ? base::string16()
44 : l10n_util::GetStringUTF16(IDS_WELCOME_SUBHEADER); 49 : l10n_util::GetStringUTF16(IDS_WELCOME_SUBHEADER);
45 html_source->AddString("subheaderText", subheader); 50 html_source->AddString("subheaderText", subheader);
46 #endif 51 #endif
47 52
48 html_source->AddLocalizedString("descriptionText", IDS_WELCOME_DESCRIPTION); 53 html_source->AddLocalizedString("descriptionText", IDS_WELCOME_DESCRIPTION);
49 html_source->AddLocalizedString("acceptText", IDS_WELCOME_ACCEPT_BUTTON); 54 html_source->AddLocalizedString("acceptText", IDS_WELCOME_ACCEPT_BUTTON);
50 html_source->AddLocalizedString("declineText", IDS_WELCOME_DECLINE_BUTTON); 55 html_source->AddLocalizedString("declineText", IDS_WELCOME_DECLINE_BUTTON);
51 56
52 html_source->AddResourcePath("welcome.js", IDR_WELCOME_JS); 57 html_source->AddResourcePath("welcome.js", IDR_WELCOME_JS);
53 html_source->AddResourcePath("welcome.css", IDR_WELCOME_CSS); 58 html_source->AddResourcePath("welcome.css", IDR_WELCOME_CSS);
54 html_source->AddResourcePath("logo.png", IDR_PRODUCT_LOGO_128); 59 html_source->AddResourcePath("logo.png", IDR_PRODUCT_LOGO_128);
55 html_source->AddResourcePath("logo2x.png", IDR_PRODUCT_LOGO_256); 60 html_source->AddResourcePath("logo2x.png", IDR_PRODUCT_LOGO_256);
56 html_source->AddResourcePath("watermark.svg", IDR_WEBUI_IMAGES_GOOGLE_LOGO); 61 html_source->AddResourcePath("watermark.svg", IDR_WEBUI_IMAGES_GOOGLE_LOGO);
57 html_source->SetDefaultResource(IDR_WELCOME_HTML); 62 html_source->SetDefaultResource(IDR_WELCOME_HTML);
58 63
59 Profile* profile = Profile::FromWebUI(web_ui);
60 content::WebUIDataSource::Add(profile, html_source); 64 content::WebUIDataSource::Add(profile, html_source);
61 } 65 }
62 66
63 WelcomeUI::~WelcomeUI() {} 67 WelcomeUI::~WelcomeUI() {}
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/welcome_ui.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698