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 |
| 34 // the value of |is_first_run|. |
| 35 void AddLocalizedStrings(content::WebUIDataSource* html_source, |
| 36 bool is_first_run) { |
| 37 // Only show the "Welcome to Chrome" text on first run. |
| 38 int welcome_header_id = is_first_run |
| 39 ? IDS_WIN10_WELCOME_HEADER |
| 40 : IDS_WIN10_WELCOME_HEADER_AFTER_FIRST_RUN; |
| 41 html_source->AddLocalizedString("headerText", welcome_header_id); |
| 42 |
| 43 html_source->AddLocalizedString("continueText", IDS_WIN10_WELCOME_CONTINUE); |
| 44 |
| 45 // Default browser strings. |
| 46 html_source->AddLocalizedString("defaultBrowserSubheaderText", |
| 47 IDS_WIN10_WELCOME_MAKE_DEFAULT_SUBHEADING); |
| 48 html_source->AddLocalizedString("openSettingsText", |
| 49 IDS_WIN10_WELCOME_OPEN_SETTINGS); |
| 50 html_source->AddLocalizedString("clickEdgeText", |
| 51 IDS_WIN10_WELCOME_CLICK_EDGE); |
| 52 html_source->AddLocalizedString("clickSelectChrome", |
| 53 IDS_WIN10_WELCOME_SELECT); |
| 54 html_source->AddLocalizedString("webBrowserLabel", |
| 55 IDS_WIN10_WELCOME_BROWSER_LABEL); |
| 56 html_source->AddLocalizedString("microsoftEdgeLabel", |
| 57 IDS_WIN10_WELCOME_EDGE_LABEL); |
| 58 |
| 59 // Taskbar pin strings. |
| 60 html_source->AddLocalizedString("pinSubheaderText", |
| 61 IDS_WIN10_WELCOME_PIN_SUBHEADING); |
| 62 html_source->AddLocalizedString("rightClickText", |
| 63 IDS_WIN10_WELCOME_RIGHT_CLICK_TASKBAR); |
| 64 html_source->AddLocalizedString("pinInstructionText", |
| 65 IDS_WIN10_WELCOME_PIN_INSTRUCTION); |
| 66 html_source->AddLocalizedString("pinToTaskbarLabel", |
| 67 IDS_WIN10_WELCOME_PIN_LABEL); |
| 68 } |
| 69 |
| 70 } // namespace |
| 71 |
| 72 WelcomeWin10UI::WelcomeWin10UI(content::WebUI* web_ui, const GURL& url) |
| 73 : content::WebUIController(web_ui) { |
| 74 static const char kCssFilePath[] = "welcome.css"; |
| 75 static const char kJsFilePath[] = "welcome.js"; |
| 76 |
| 77 web_ui->AddMessageHandler(new WelcomeWin10Handler(web_ui)); |
| 78 |
| 79 content::WebUIDataSource* html_source = |
| 80 content::WebUIDataSource::Create(url.host()); |
| 81 |
| 82 // Determine which variation to show. |
| 83 bool is_first_run = !UrlContainsKeyValueInQuery(url, "text", "faster"); |
| 84 bool is_inline_style = UrlContainsKeyValueInQuery(url, "style", "inline"); |
| 85 |
| 86 AddLocalizedStrings(html_source, is_first_run); |
| 87 |
| 88 if (is_inline_style) { |
| 89 html_source->AddResourcePath(kCssFilePath, IDR_WELCOME_WIN10_INLINE_CSS); |
| 90 html_source->AddResourcePath(kJsFilePath, IDR_WELCOME_WIN10_INLINE_JS); |
| 91 html_source->SetDefaultResource(IDR_WELCOME_WIN10_INLINE_HTML); |
| 92 } else { |
| 93 html_source->AddResourcePath(kCssFilePath, IDR_WELCOME_WIN10_SECTIONED_CSS); |
| 94 html_source->AddResourcePath(kJsFilePath, IDR_WELCOME_WIN10_SECTIONED_JS); |
| 95 html_source->SetDefaultResource(IDR_WELCOME_WIN10_SECTIONED_HTML); |
| 96 } |
| 97 |
| 98 // Logo images of all scales. |
| 99 html_source->AddResourcePath("logo-small.png", IDR_PRODUCT_LOGO_32); |
| 100 html_source->AddResourcePath("logo-small2x.png", IDR_PRODUCT_LOGO_64); |
| 101 html_source->AddResourcePath("logo-large.png", IDR_PRODUCT_LOGO_64); |
| 102 html_source->AddResourcePath("logo-large2x.png", IDR_PRODUCT_LOGO_128); |
| 103 |
| 104 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); |
| 105 } |
| 106 |
| 107 WelcomeWin10UI::~WelcomeWin10UI() {} |
OLD | NEW |