Chromium Code Reviews| Index: chrome/browser/ui/webui/welcome_win10_ui.cc |
| diff --git a/chrome/browser/ui/webui/welcome_win10_ui.cc b/chrome/browser/ui/webui/welcome_win10_ui.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..63fa07443a7dc3c7e881fb8c35bd2976d493330f |
| --- /dev/null |
| +++ b/chrome/browser/ui/webui/welcome_win10_ui.cc |
| @@ -0,0 +1,138 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/webui/welcome_win10_ui.h" |
| + |
| +#include <string> |
| + |
| +#include "base/feature_list.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/ui/webui/welcome_win10_handler.h" |
| +#include "chrome/common/url_constants.h" |
| +#include "chrome/grit/browser_resources.h" |
| +#include "chrome/grit/chrome_unscaled_resources.h" |
| +#include "chrome/grit/chromium_strings.h" |
| +#include "chrome/grit/generated_resources.h" |
| +#include "chrome/grit/theme_resources.h" |
| +#include "content/public/browser/web_ui_data_source.h" |
| +#include "net/base/url_util.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| + |
| +namespace { |
| + |
| +// Helper function to check the presence of a key/value inside the query in the |
| +// |url|. |
| +bool UrlContainsKeyValueInQuery(const GURL& url, |
| + const std::string& key, |
| + const std::string& expected_value) { |
| + std::string value; |
| + return net::GetValueForKeyInQuery(url, key, &value) && |
| + value == expected_value; |
| +} |
| + |
| +// Returns true if the inline style variant should be displayed. This is usually |
| +// set via the Feature API, but it can be overridden with a query in the URL. |
| +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
|
| + static constexpr base::Feature kWin10WelcomePageInlineVariant{ |
| + "Win10WelcomePageInlineVariant", base::FEATURE_DISABLED_BY_DEFAULT}; |
| + |
| + if (UrlContainsKeyValueInQuery(url, "style", "inline")) |
| + return true; |
| + |
| + return base::FeatureList::IsEnabled(kWin10WelcomePageInlineVariant); |
| +} |
| + |
| +// Adds all the needed localized strings to |html_source|. |
| +void AddLocalizedStrings(content::WebUIDataSource* html_source, |
| + bool combined_variant) { |
| + 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.
|
| + |
| + // 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.
|
| + // it in the "Welcome to Chrome" variant, and only on branded builds. |
| + base::string16 subheader_string; |
| +#if defined(GOOGLE_CHROME_BUILD) |
| + subheader_string = l10n_util::GetStringUTF16(IDS_WELCOME_SUBHEADER); |
| +#endif |
| + html_source->AddString("subheaderText", subheader_string); |
| + |
| + html_source->AddLocalizedString("continueText", IDS_WIN10_WELCOME_CONTINUE); |
| + |
| + // Default browser strings. |
| + html_source->AddLocalizedString("defaultBrowserSubheaderText", |
| + IDS_WIN10_WELCOME_MAKE_DEFAULT_SUBHEADING); |
| + html_source->AddLocalizedString("openSettingsText", |
| + IDS_WIN10_WELCOME_OPEN_SETTINGS); |
| + html_source->AddLocalizedString("clickEdgeText", |
| + IDS_WIN10_WELCOME_CLICK_EDGE); |
| + html_source->AddLocalizedString("clickSelectChrome", |
| + IDS_WIN10_WELCOME_SELECT); |
| + html_source->AddLocalizedString("webBrowserLabel", |
| + IDS_WIN10_WELCOME_BROWSER_LABEL); |
| + html_source->AddLocalizedString("microsoftEdgeLabel", |
| + IDS_WIN10_WELCOME_EDGE_LABEL); |
| + |
| + // Taskbar pin strings. |
| + if (combined_variant) { |
| + html_source->AddLocalizedString("pinSubheaderText", |
| + IDS_WIN10_WELCOME_PIN_SUBHEADING); |
| + html_source->AddLocalizedString("rightClickText", |
| + IDS_WIN10_WELCOME_RIGHT_CLICK_TASKBAR); |
| + html_source->AddLocalizedString("pinInstructionText", |
| + IDS_WIN10_WELCOME_PIN_INSTRUCTION); |
| + html_source->AddLocalizedString("pinToTaskbarLabel", |
| + IDS_WIN10_WELCOME_PIN_LABEL); |
| + } |
| +} |
| + |
| +} // namespace |
| + |
| +WelcomeWin10UI::WelcomeWin10UI(content::WebUI* web_ui, const GURL& url) |
| + : content::WebUIController(web_ui) { |
| + static const char kCssFilePath[] = "welcome.css"; |
| + static const char kJsFilePath[] = "welcome.js"; |
| + |
| + web_ui->AddMessageHandler(new WelcomeWin10Handler(web_ui)); |
| + |
| + content::WebUIDataSource* html_source = |
| + content::WebUIDataSource::Create(url.host()); |
| + |
| + bool combined_variant = |
| + UrlContainsKeyValueInQuery(url, "variant", "combined"); |
| + AddLocalizedStrings(html_source, combined_variant); |
| + |
| + html_source->SetJsonPath("strings.js"); |
| + html_source->AddResourcePath("logo.png", IDR_PRODUCT_LOGO_16); |
| + html_source->AddResourcePath("logo2x.png", IDR_PRODUCT_LOGO_32); |
| + html_source->AddResourcePath("logo4x.png", IDR_PRODUCT_LOGO_64); |
| + |
| + if (IsInlineVariant(url)) { |
| + html_source->AddResourcePath(kCssFilePath, IDR_WELCOME_WIN10_INLINE_CSS); |
| + if (combined_variant) { |
| + html_source->AddResourcePath(kJsFilePath, |
| + IDR_WELCOME_WIN10_INLINE_COMBINED_JS); |
| + html_source->SetDefaultResource(IDR_WELCOME_WIN10_INLINE_COMBINED_HTML); |
| + } else { |
| + html_source->AddResourcePath(kJsFilePath, |
| + IDR_WELCOME_WIN10_INLINE_DEFAULT_JS); |
| + html_source->SetDefaultResource(IDR_WELCOME_WIN10_INLINE_DEFAULT_HTML); |
| + } |
| + } else { |
| + html_source->AddResourcePath(kCssFilePath, IDR_WELCOME_WIN10_SECTIONED_CSS); |
| + if (combined_variant) { |
| + html_source->AddResourcePath(kJsFilePath, |
| + IDR_WELCOME_WIN10_SECTIONED_COMBINED_JS); |
| + html_source->SetDefaultResource( |
| + IDR_WELCOME_WIN10_SECTIONED_COMBINED_HTML); |
| + } else { |
| + html_source->AddResourcePath(kJsFilePath, |
| + IDR_WELCOME_WIN10_SECTIONED_DEFAULT_JS); |
| + html_source->SetDefaultResource(IDR_WELCOME_WIN10_SECTIONED_DEFAULT_HTML); |
| + } |
| + } |
| + |
| + 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.
|
| + content::WebUIDataSource::Add(profile, html_source); |
| +} |
| + |
| +WelcomeWin10UI::~WelcomeWin10UI() {} |