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 "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/webui/welcome_win10_handler.h" |
| 11 #include "chrome/common/url_constants.h" |
| 12 #include "chrome/grit/browser_resources.h" |
| 13 #include "chrome/grit/chrome_unscaled_resources.h" |
| 14 #include "chrome/grit/chromium_strings.h" |
| 15 #include "chrome/grit/generated_resources.h" |
| 16 #include "chrome/grit/theme_resources.h" |
| 17 #include "content/public/browser/web_ui_data_source.h" |
| 18 #include "net/base/url_util.h" |
| 19 #include "ui/base/l10n/l10n_util.h" |
| 20 |
| 21 namespace { |
| 22 |
| 23 // Helper function to check the presence of a key/value inside the query in the |
| 24 // |url|. |
| 25 bool UrlContainsKeyValueInQuery(const GURL& url, |
| 26 const std::string& key, |
| 27 const std::string& expected_value) { |
| 28 std::string value; |
| 29 return net::GetValueForKeyInQuery(url, key, &value) && |
| 30 value == expected_value; |
| 31 } |
| 32 |
| 33 // Adds all the needed localized strings to |html_source|, depending on the |
| 34 // combination of |is_first_run| and |is_combined_variant|. |
| 35 void AddLocalizedStrings(content::WebUIDataSource* html_source, |
| 36 bool is_first_run, |
| 37 bool is_combined_variant) { |
| 38 // Only show the "Welcome to Chrome" text on first run. |
| 39 int welcome_header_id = is_first_run |
| 40 ? IDS_WIN10_WELCOME_HEADER |
| 41 : IDS_WIN10_WELCOME_HEADER_AFTER_FIRST_RUN; |
| 42 html_source->AddLocalizedString("headerText", welcome_header_id); |
| 43 |
| 44 html_source->AddLocalizedString("continueText", IDS_WIN10_WELCOME_CONTINUE); |
| 45 |
| 46 // Default browser strings. |
| 47 html_source->AddLocalizedString("defaultBrowserSubheaderText", |
| 48 IDS_WIN10_WELCOME_MAKE_DEFAULT_SUBHEADING); |
| 49 html_source->AddLocalizedString("openSettingsText", |
| 50 IDS_WIN10_WELCOME_OPEN_SETTINGS); |
| 51 html_source->AddLocalizedString("clickEdgeText", |
| 52 IDS_WIN10_WELCOME_CLICK_EDGE); |
| 53 html_source->AddLocalizedString("clickSelectChrome", |
| 54 IDS_WIN10_WELCOME_SELECT); |
| 55 html_source->AddLocalizedString("webBrowserLabel", |
| 56 IDS_WIN10_WELCOME_BROWSER_LABEL); |
| 57 html_source->AddLocalizedString("microsoftEdgeLabel", |
| 58 IDS_WIN10_WELCOME_EDGE_LABEL); |
| 59 |
| 60 // Taskbar pin strings. |
| 61 if (is_combined_variant) { |
| 62 html_source->AddLocalizedString("pinSubheaderText", |
| 63 IDS_WIN10_WELCOME_PIN_SUBHEADING); |
| 64 html_source->AddLocalizedString("rightClickText", |
| 65 IDS_WIN10_WELCOME_RIGHT_CLICK_TASKBAR); |
| 66 html_source->AddLocalizedString("pinInstructionText", |
| 67 IDS_WIN10_WELCOME_PIN_INSTRUCTION); |
| 68 html_source->AddLocalizedString("pinToTaskbarLabel", |
| 69 IDS_WIN10_WELCOME_PIN_LABEL); |
| 70 } |
| 71 } |
| 72 |
| 73 } // namespace |
| 74 |
| 75 WelcomeWin10UI::WelcomeWin10UI(content::WebUI* web_ui, const GURL& url) |
| 76 : content::WebUIController(web_ui) { |
| 77 static const char kCssFilePath[] = "welcome.css"; |
| 78 |
| 79 web_ui->AddMessageHandler(new WelcomeWin10Handler(web_ui)); |
| 80 |
| 81 content::WebUIDataSource* html_source = |
| 82 content::WebUIDataSource::Create(url.host()); |
| 83 |
| 84 // Determine which variation to show. |
| 85 bool is_first_run = !UrlContainsKeyValueInQuery(url, "text", "faster"); |
| 86 bool is_combined_variant = |
| 87 UrlContainsKeyValueInQuery(url, "variant", "combined"); |
| 88 bool is_inline_style = UrlContainsKeyValueInQuery(url, "style", "inline"); |
| 89 |
| 90 AddLocalizedStrings(html_source, is_first_run, is_combined_variant); |
| 91 |
| 92 // Include localization strings file. |
| 93 html_source->SetJsonPath("strings.js"); |
| 94 |
| 95 // Javascript files |
| 96 html_source->AddResourcePath("welcome-win10.js", IDR_WELCOME_WIN10_JS); |
| 97 html_source->AddResourcePath("default-browser.js", |
| 98 IDR_WELCOME_WIN10_DEFAULT_BROWSER_JS); |
| 99 if (is_combined_variant) { |
| 100 html_source->AddResourcePath("taskbar-pin.js", |
| 101 IDR_WELCOME_WIN10_TASKBAR_PIN_JS); |
| 102 html_source->AddResourcePath("toggle-section.js", |
| 103 IDR_WELCOME_WIN10_TOGGLE_SECTION_JS); |
| 104 if (!is_inline_style) |
| 105 html_source->AddResourcePath("toggle-screenshot.js", |
| 106 IDR_WELCOME_WIN10_TOGGLE_SCREENSHOT_JS); |
| 107 } |
| 108 |
| 109 // CSS and HTML files. |
| 110 if (is_inline_style) { |
| 111 html_source->AddResourcePath(kCssFilePath, IDR_WELCOME_WIN10_INLINE_CSS); |
| 112 if (is_combined_variant) { |
| 113 html_source->SetDefaultResource(IDR_WELCOME_WIN10_INLINE_COMBINED_HTML); |
| 114 } else { |
| 115 html_source->SetDefaultResource(IDR_WELCOME_WIN10_INLINE_DEFAULT_HTML); |
| 116 } |
| 117 } else { |
| 118 html_source->AddResourcePath(kCssFilePath, IDR_WELCOME_WIN10_SECTIONED_CSS); |
| 119 if (is_combined_variant) { |
| 120 html_source->SetDefaultResource( |
| 121 IDR_WELCOME_WIN10_SECTIONED_COMBINED_HTML); |
| 122 } else { |
| 123 html_source->SetDefaultResource(IDR_WELCOME_WIN10_SECTIONED_DEFAULT_HTML); |
| 124 } |
| 125 } |
| 126 |
| 127 // Logo images of all scales. |
| 128 html_source->AddResourcePath("logo-small.png", IDR_PRODUCT_LOGO_32); |
| 129 html_source->AddResourcePath("logo-small2x.png", IDR_PRODUCT_LOGO_64); |
| 130 html_source->AddResourcePath("logo-large.png", IDR_PRODUCT_LOGO_64); |
| 131 html_source->AddResourcePath("logo-large2x.png", IDR_PRODUCT_LOGO_128); |
| 132 |
| 133 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); |
| 134 } |
| 135 |
| 136 WelcomeWin10UI::~WelcomeWin10UI() {} |
OLD | NEW |