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..a54ab872cf76c05ae494c27c3b41a693f416345e |
| --- /dev/null |
| +++ b/chrome/browser/ui/webui/welcome_win10_ui.cc |
| @@ -0,0 +1,136 @@ |
| +// 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 "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; |
| +} |
| + |
| +// Adds all the needed localized strings to |html_source|, depending on the |
| +// combinaison of |is_first_run| and |is_combined_variant|. |
|
tmartino
2016/10/14 19:32:09
nit: combination, not combinaison
Patrick Monette
2016/10/14 21:37:25
Done.
|
| +void AddLocalizedStrings(content::WebUIDataSource* html_source, |
| + bool is_first_run, |
| + bool is_combined_variant) { |
| + // Don't show the "Welcome to Chrome" text when it's th |
|
tmartino
2016/10/14 19:32:10
Something got deleted here?
Patrick Monette
2016/10/14 21:37:25
Fixed.
|
| + int welcome_header_id = is_first_run |
| + ? IDS_WIN10_WELCOME_HEADER |
| + : IDS_WIN10_WELCOME_HEADER_AFTER_FIRST_RUN; |
| + html_source->AddLocalizedString("headerText", welcome_header_id); |
| + |
| + 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 (is_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"; |
| + |
| + web_ui->AddMessageHandler(new WelcomeWin10Handler(web_ui)); |
| + |
| + content::WebUIDataSource* html_source = |
| + content::WebUIDataSource::Create(url.host()); |
| + |
| + // Determine which variation to show. |
| + bool is_first_run = !UrlContainsKeyValueInQuery(url, "text", "faster"); |
| + bool is_combined_variant = |
| + UrlContainsKeyValueInQuery(url, "variant", "combined"); |
| + bool is_inline_style = UrlContainsKeyValueInQuery(url, "style", "inline"); |
| + |
| + AddLocalizedStrings(html_source, is_first_run, is_combined_variant); |
| + |
| + // Include localization strings file. |
| + html_source->SetJsonPath("strings.js"); |
| + |
| + // Javascript files |
| + html_source->AddResourcePath("welcome-win10.js", IDR_WELCOME_WIN10_JS); |
| + html_source->AddResourcePath("default-browser.js", |
| + IDR_WELCOME_WIN10_DEFAULT_BROWSER_JS); |
| + if (is_combined_variant) { |
| + html_source->AddResourcePath("taskbar-pin.js", |
| + IDR_WELCOME_WIN10_TASKBAR_PIN_JS); |
| + html_source->AddResourcePath("toggle-section.js", |
| + IDR_WELCOME_WIN10_TOGGLE_SECTION_JS); |
| + if (!is_inline_style) |
| + html_source->AddResourcePath("toggle-screenshot.js", |
| + IDR_WELCOME_WIN10_TOGGLE_SCREENSHOT_JS); |
| + } |
| + |
| + // CSS and HTML files. |
| + if (is_inline_style) { |
| + html_source->AddResourcePath(kCssFilePath, IDR_WELCOME_WIN10_INLINE_CSS); |
| + if (is_combined_variant) { |
| + html_source->SetDefaultResource(IDR_WELCOME_WIN10_INLINE_COMBINED_HTML); |
| + } else { |
| + html_source->SetDefaultResource(IDR_WELCOME_WIN10_INLINE_DEFAULT_HTML); |
| + } |
| + } else { |
| + html_source->AddResourcePath(kCssFilePath, IDR_WELCOME_WIN10_SECTIONED_CSS); |
| + if (is_combined_variant) { |
| + html_source->SetDefaultResource( |
| + IDR_WELCOME_WIN10_SECTIONED_COMBINED_HTML); |
| + } else { |
| + html_source->SetDefaultResource(IDR_WELCOME_WIN10_SECTIONED_DEFAULT_HTML); |
| + } |
| + } |
| + |
| + // Logo images of all scales. |
| + html_source->AddResourcePath("logo-small.png", IDR_PRODUCT_LOGO_32); |
| + html_source->AddResourcePath("logo-small2x.png", IDR_PRODUCT_LOGO_64); |
| + html_source->AddResourcePath("logo-large.png", IDR_PRODUCT_LOGO_64); |
| + html_source->AddResourcePath("logo-large2x.png", IDR_PRODUCT_LOGO_128); |
| + |
| + content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); |
| +} |
| + |
| +WelcomeWin10UI::~WelcomeWin10UI() {} |