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