OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/webui/welcome_win10_ui.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/feature_list.h" | |
10 #include "chrome/browser/profiles/profile.h" | |
11 #include "chrome/browser/ui/webui/welcome_win10_handler.h" | |
12 #include "chrome/common/url_constants.h" | |
13 #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" | |
17 #include "chrome/grit/theme_resources.h" | |
18 #include "content/public/browser/web_ui_data_source.h" | |
19 #include "net/base/url_util.h" | |
20 #include "ui/base/l10n/l10n_util.h" | |
21 | |
22 namespace { | |
23 | |
24 // Helper function to check the presence of a key/value inside the query in the | |
25 // |url|. | |
26 bool UrlContainsKeyValueInQuery(const GURL& url, | |
27 const std::string& key, | |
28 const std::string& expected_value) { | |
29 std::string value; | |
30 return net::GetValueForKeyInQuery(url, key, &value) && | |
31 value == expected_value; | |
32 } | |
33 | |
34 // Returns true if the inline style variant should be displayed. This is usually | |
35 // set via the Feature API, but it can be overridden with a query in the URL. | |
36 bool IsInlineVariant(const GURL& url) { | |
tmartino
2016/10/12 22:06:40
Let's set this only using the URL, and not with th
Patrick Monette
2016/10/13 21:30:06
Done since I don't have a strong opinion.
IMO the
| |
37 static constexpr base::Feature kWin10WelcomePageInlineVariant{ | |
38 "Win10WelcomePageInlineVariant", base::FEATURE_DISABLED_BY_DEFAULT}; | |
39 | |
40 if (UrlContainsKeyValueInQuery(url, "style", "inline")) | |
41 return true; | |
42 | |
43 return base::FeatureList::IsEnabled(kWin10WelcomePageInlineVariant); | |
44 } | |
45 | |
46 // Adds all the needed localized strings to |html_source|. | |
47 void AddLocalizedStrings(content::WebUIDataSource* html_source, | |
48 bool combined_variant) { | |
49 html_source->AddLocalizedString("headerText", IDS_WELCOME_HEADER); | |
tmartino
2016/10/12 22:06:40
I landed Win10-specific versions of the header str
Patrick Monette
2016/10/13 21:30:06
Done.
| |
50 | |
51 // The subheader describes the browser as being "by Google", so we only show | |
tmartino
2016/10/12 22:06:40
I don't think we're actually using this text, are
Patrick Monette
2016/10/13 21:30:06
Removed.
| |
52 // it in the "Welcome to Chrome" variant, and only on branded builds. | |
53 base::string16 subheader_string; | |
54 #if defined(GOOGLE_CHROME_BUILD) | |
55 subheader_string = l10n_util::GetStringUTF16(IDS_WELCOME_SUBHEADER); | |
56 #endif | |
57 html_source->AddString("subheaderText", subheader_string); | |
58 | |
59 html_source->AddLocalizedString("continueText", IDS_WIN10_WELCOME_CONTINUE); | |
60 | |
61 // Default browser strings. | |
62 html_source->AddLocalizedString("defaultBrowserSubheaderText", | |
63 IDS_WIN10_WELCOME_MAKE_DEFAULT_SUBHEADING); | |
64 html_source->AddLocalizedString("openSettingsText", | |
65 IDS_WIN10_WELCOME_OPEN_SETTINGS); | |
66 html_source->AddLocalizedString("clickEdgeText", | |
67 IDS_WIN10_WELCOME_CLICK_EDGE); | |
68 html_source->AddLocalizedString("clickSelectChrome", | |
69 IDS_WIN10_WELCOME_SELECT); | |
70 html_source->AddLocalizedString("webBrowserLabel", | |
71 IDS_WIN10_WELCOME_BROWSER_LABEL); | |
72 html_source->AddLocalizedString("microsoftEdgeLabel", | |
73 IDS_WIN10_WELCOME_EDGE_LABEL); | |
74 | |
75 // Taskbar pin strings. | |
76 if (combined_variant) { | |
77 html_source->AddLocalizedString("pinSubheaderText", | |
78 IDS_WIN10_WELCOME_PIN_SUBHEADING); | |
79 html_source->AddLocalizedString("rightClickText", | |
80 IDS_WIN10_WELCOME_RIGHT_CLICK_TASKBAR); | |
81 html_source->AddLocalizedString("pinInstructionText", | |
82 IDS_WIN10_WELCOME_PIN_INSTRUCTION); | |
83 html_source->AddLocalizedString("pinToTaskbarLabel", | |
84 IDS_WIN10_WELCOME_PIN_LABEL); | |
85 } | |
86 } | |
87 | |
88 } // namespace | |
89 | |
90 WelcomeWin10UI::WelcomeWin10UI(content::WebUI* web_ui, const GURL& url) | |
91 : content::WebUIController(web_ui) { | |
92 static const char kCssFilePath[] = "welcome.css"; | |
93 static const char kJsFilePath[] = "welcome.js"; | |
94 | |
95 web_ui->AddMessageHandler(new WelcomeWin10Handler(web_ui)); | |
96 | |
97 content::WebUIDataSource* html_source = | |
98 content::WebUIDataSource::Create(url.host()); | |
99 | |
100 bool combined_variant = | |
101 UrlContainsKeyValueInQuery(url, "variant", "combined"); | |
102 AddLocalizedStrings(html_source, combined_variant); | |
103 | |
104 html_source->SetJsonPath("strings.js"); | |
105 html_source->AddResourcePath("logo.png", IDR_PRODUCT_LOGO_16); | |
106 html_source->AddResourcePath("logo2x.png", IDR_PRODUCT_LOGO_32); | |
107 html_source->AddResourcePath("logo4x.png", IDR_PRODUCT_LOGO_64); | |
108 | |
109 if (IsInlineVariant(url)) { | |
110 html_source->AddResourcePath(kCssFilePath, IDR_WELCOME_WIN10_INLINE_CSS); | |
111 if (combined_variant) { | |
112 html_source->AddResourcePath(kJsFilePath, | |
113 IDR_WELCOME_WIN10_INLINE_COMBINED_JS); | |
114 html_source->SetDefaultResource(IDR_WELCOME_WIN10_INLINE_COMBINED_HTML); | |
115 } else { | |
116 html_source->AddResourcePath(kJsFilePath, | |
117 IDR_WELCOME_WIN10_INLINE_DEFAULT_JS); | |
118 html_source->SetDefaultResource(IDR_WELCOME_WIN10_INLINE_DEFAULT_HTML); | |
119 } | |
120 } else { | |
121 html_source->AddResourcePath(kCssFilePath, IDR_WELCOME_WIN10_SECTIONED_CSS); | |
122 if (combined_variant) { | |
123 html_source->AddResourcePath(kJsFilePath, | |
124 IDR_WELCOME_WIN10_SECTIONED_COMBINED_JS); | |
125 html_source->SetDefaultResource( | |
126 IDR_WELCOME_WIN10_SECTIONED_COMBINED_HTML); | |
127 } else { | |
128 html_source->AddResourcePath(kJsFilePath, | |
129 IDR_WELCOME_WIN10_SECTIONED_DEFAULT_JS); | |
130 html_source->SetDefaultResource(IDR_WELCOME_WIN10_SECTIONED_DEFAULT_HTML); | |
131 } | |
132 } | |
133 | |
134 Profile* profile = Profile::FromWebUI(web_ui); | |
tmartino
2016/10/12 22:06:40
If we're not using profile again, just inline it i
Patrick Monette
2016/10/13 21:30:06
Done.
| |
135 content::WebUIDataSource::Add(profile, html_source); | |
136 } | |
137 | |
138 WelcomeWin10UI::~WelcomeWin10UI() {} | |
OLD | NEW |