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 #include "url/gurl.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 // Adds all the needed localized strings to |html_source|, depending on |
| 35 // the value of |is_first_run|. |
| 36 void AddLocalizedStrings(content::WebUIDataSource* html_source, |
| 37 bool is_first_run) { |
| 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 html_source->AddLocalizedString("pinSubheaderText", |
| 62 IDS_WIN10_WELCOME_PIN_SUBHEADING); |
| 63 html_source->AddLocalizedString("rightClickText", |
| 64 IDS_WIN10_WELCOME_RIGHT_CLICK_TASKBAR); |
| 65 html_source->AddLocalizedString("pinInstructionText", |
| 66 IDS_WIN10_WELCOME_PIN_INSTRUCTION); |
| 67 html_source->AddLocalizedString("pinToTaskbarLabel", |
| 68 IDS_WIN10_WELCOME_PIN_LABEL); |
| 69 } |
| 70 |
| 71 } // namespace |
| 72 |
| 73 WelcomeWin10UI::WelcomeWin10UI(content::WebUI* web_ui, const GURL& url) |
| 74 : content::WebUIController(web_ui) { |
| 75 static const char kCssFilePath[] = "welcome.css"; |
| 76 static const char kJsFilePath[] = "welcome.js"; |
| 77 |
| 78 web_ui->AddMessageHandler(new WelcomeWin10Handler()); |
| 79 |
| 80 content::WebUIDataSource* html_source = |
| 81 content::WebUIDataSource::Create(url.host()); |
| 82 |
| 83 // Determine which variation to show. |
| 84 bool is_first_run = !UrlContainsKeyValueInQuery(url, "text", "faster"); |
| 85 bool is_inline_style = UrlContainsKeyValueInQuery(url, "style", "inline"); |
| 86 |
| 87 AddLocalizedStrings(html_source, is_first_run); |
| 88 |
| 89 if (is_inline_style) { |
| 90 html_source->AddResourcePath(kCssFilePath, IDR_WELCOME_WIN10_INLINE_CSS); |
| 91 html_source->AddResourcePath(kJsFilePath, IDR_WELCOME_WIN10_INLINE_JS); |
| 92 html_source->SetDefaultResource(IDR_WELCOME_WIN10_INLINE_HTML); |
| 93 } else { |
| 94 html_source->AddResourcePath(kCssFilePath, IDR_WELCOME_WIN10_SECTIONED_CSS); |
| 95 html_source->AddResourcePath(kJsFilePath, IDR_WELCOME_WIN10_SECTIONED_JS); |
| 96 html_source->SetDefaultResource(IDR_WELCOME_WIN10_SECTIONED_HTML); |
| 97 } |
| 98 |
| 99 // Logo images of all scales. |
| 100 html_source->AddResourcePath("logo-small.png", IDR_PRODUCT_LOGO_32); |
| 101 html_source->AddResourcePath("logo-small2x.png", IDR_PRODUCT_LOGO_64); |
| 102 html_source->AddResourcePath("logo-large.png", IDR_PRODUCT_LOGO_64); |
| 103 html_source->AddResourcePath("logo-large2x.png", IDR_PRODUCT_LOGO_128); |
| 104 |
| 105 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); |
| 106 } |
| 107 |
| 108 WelcomeWin10UI::~WelcomeWin10UI() = default; |
OLD | NEW |