| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/welcome_win10_ui.h" | 5 #include "chrome/browser/ui/webui/welcome_win10_ui.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/feature_list.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/ui/startup/startup_features.h" |
| 10 #include "chrome/browser/ui/webui/welcome_win10_handler.h" | 12 #include "chrome/browser/ui/webui/welcome_win10_handler.h" |
| 11 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
| 12 #include "chrome/grit/browser_resources.h" | 14 #include "chrome/grit/browser_resources.h" |
| 13 #include "chrome/grit/chrome_unscaled_resources.h" | 15 #include "chrome/grit/chrome_unscaled_resources.h" |
| 14 #include "chrome/grit/chromium_strings.h" | 16 #include "chrome/grit/chromium_strings.h" |
| 15 #include "chrome/grit/generated_resources.h" | 17 #include "chrome/grit/generated_resources.h" |
| 16 #include "chrome/grit/theme_resources.h" | 18 #include "chrome/grit/theme_resources.h" |
| 17 #include "content/public/browser/web_ui_data_source.h" | 19 #include "content/public/browser/web_ui_data_source.h" |
| 18 #include "net/base/url_util.h" | 20 #include "net/base/url_util.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 21 | 23 |
| 22 namespace { | 24 namespace { |
| 23 | 25 |
| 24 // Helper function to check the presence of a key/value inside the query in the | 26 // Helper function to check the presence of a key/value inside the query in the |
| 25 // |url|. | 27 // |url|. |
| 26 bool UrlContainsKeyValueInQuery(const GURL& url, | 28 bool UrlContainsKeyValueInQuery(const GURL& url, |
| 27 const std::string& key, | 29 const std::string& key, |
| 28 const std::string& expected_value) { | 30 const std::string& expected_value) { |
| 29 std::string value; | 31 std::string value; |
| 30 return net::GetValueForKeyInQuery(url, key, &value) && | 32 return net::GetValueForKeyInQuery(url, key, &value) && |
| 31 value == expected_value; | 33 value == expected_value; |
| 32 } | 34 } |
| 33 | 35 |
| 36 bool ShouldShowInlineStyleVariant(const GURL& url) { |
| 37 // Can be overridden via a query. |
| 38 if (UrlContainsKeyValueInQuery(url, "style", "inline")) |
| 39 return true; |
| 40 if (UrlContainsKeyValueInQuery(url, "style", "sectioned")) |
| 41 return false; |
| 42 |
| 43 return base::FeatureList::IsEnabled(features::kWelcomeWin10InlineStyle); |
| 44 } |
| 45 |
| 34 // Adds all the needed localized strings to |html_source|, depending on | 46 // Adds all the needed localized strings to |html_source|, depending on |
| 35 // the value of |is_first_run|. | 47 // the value of |is_first_run|. |
| 36 void AddLocalizedStrings(content::WebUIDataSource* html_source, | 48 void AddLocalizedStrings(content::WebUIDataSource* html_source, |
| 37 bool is_first_run) { | 49 bool is_first_run) { |
| 38 // Only show the "Welcome to Chrome" text on first run. | 50 // Only show the "Welcome to Chrome" text on first run. |
| 39 int welcome_header_id = is_first_run | 51 int welcome_header_id = is_first_run |
| 40 ? IDS_WIN10_WELCOME_HEADER | 52 ? IDS_WIN10_WELCOME_HEADER |
| 41 : IDS_WIN10_WELCOME_HEADER_AFTER_FIRST_RUN; | 53 : IDS_WIN10_WELCOME_HEADER_AFTER_FIRST_RUN; |
| 42 html_source->AddLocalizedString("headerText", welcome_header_id); | 54 html_source->AddLocalizedString("headerText", welcome_header_id); |
| 43 | 55 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 static const char kCssFilePath[] = "welcome.css"; | 87 static const char kCssFilePath[] = "welcome.css"; |
| 76 static const char kJsFilePath[] = "welcome.js"; | 88 static const char kJsFilePath[] = "welcome.js"; |
| 77 | 89 |
| 78 web_ui->AddMessageHandler(new WelcomeWin10Handler()); | 90 web_ui->AddMessageHandler(new WelcomeWin10Handler()); |
| 79 | 91 |
| 80 content::WebUIDataSource* html_source = | 92 content::WebUIDataSource* html_source = |
| 81 content::WebUIDataSource::Create(url.host()); | 93 content::WebUIDataSource::Create(url.host()); |
| 82 | 94 |
| 83 // Determine which variation to show. | 95 // Determine which variation to show. |
| 84 bool is_first_run = !UrlContainsKeyValueInQuery(url, "text", "faster"); | 96 bool is_first_run = !UrlContainsKeyValueInQuery(url, "text", "faster"); |
| 85 bool is_inline_style = UrlContainsKeyValueInQuery(url, "style", "inline"); | 97 bool is_inline_style = ShouldShowInlineStyleVariant(url); |
| 86 | 98 |
| 87 AddLocalizedStrings(html_source, is_first_run); | 99 AddLocalizedStrings(html_source, is_first_run); |
| 88 | 100 |
| 89 if (is_inline_style) { | 101 if (is_inline_style) { |
| 90 html_source->AddResourcePath(kCssFilePath, IDR_WELCOME_WIN10_INLINE_CSS); | 102 html_source->AddResourcePath(kCssFilePath, IDR_WELCOME_WIN10_INLINE_CSS); |
| 91 html_source->AddResourcePath(kJsFilePath, IDR_WELCOME_WIN10_INLINE_JS); | 103 html_source->AddResourcePath(kJsFilePath, IDR_WELCOME_WIN10_INLINE_JS); |
| 92 html_source->SetDefaultResource(IDR_WELCOME_WIN10_INLINE_HTML); | 104 html_source->SetDefaultResource(IDR_WELCOME_WIN10_INLINE_HTML); |
| 93 } else { | 105 } else { |
| 94 html_source->AddResourcePath(kCssFilePath, IDR_WELCOME_WIN10_SECTIONED_CSS); | 106 html_source->AddResourcePath(kCssFilePath, IDR_WELCOME_WIN10_SECTIONED_CSS); |
| 95 html_source->AddResourcePath(kJsFilePath, IDR_WELCOME_WIN10_SECTIONED_JS); | 107 html_source->AddResourcePath(kJsFilePath, IDR_WELCOME_WIN10_SECTIONED_JS); |
| 96 html_source->SetDefaultResource(IDR_WELCOME_WIN10_SECTIONED_HTML); | 108 html_source->SetDefaultResource(IDR_WELCOME_WIN10_SECTIONED_HTML); |
| 97 } | 109 } |
| 98 | 110 |
| 99 // Logo images of all scales. | 111 // Logo images of all scales. |
| 100 html_source->AddResourcePath("logo-small.png", IDR_PRODUCT_LOGO_32); | 112 html_source->AddResourcePath("logo-small.png", IDR_PRODUCT_LOGO_32); |
| 101 html_source->AddResourcePath("logo-small2x.png", IDR_PRODUCT_LOGO_64); | 113 html_source->AddResourcePath("logo-small2x.png", IDR_PRODUCT_LOGO_64); |
| 102 html_source->AddResourcePath("logo-large.png", IDR_PRODUCT_LOGO_64); | 114 html_source->AddResourcePath("logo-large.png", IDR_PRODUCT_LOGO_64); |
| 103 html_source->AddResourcePath("logo-large2x.png", IDR_PRODUCT_LOGO_128); | 115 html_source->AddResourcePath("logo-large2x.png", IDR_PRODUCT_LOGO_128); |
| 104 | 116 |
| 105 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); | 117 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); |
| 106 } | 118 } |
| 107 | 119 |
| 108 WelcomeWin10UI::~WelcomeWin10UI() = default; | 120 WelcomeWin10UI::~WelcomeWin10UI() = default; |
| OLD | NEW |