Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1055)

Side by Side Diff: chrome/browser/ui/webui/welcome_win10_ui.cc

Issue 2449853008: Determine the Win10-specific Welcome page variant to display (Closed)
Patch Set: More nits Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/webui/welcome_win10_handler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // TODO(pmonette): Remove these checks when they are no longer needed
39 // (crbug.com/658918).
40 if (UrlContainsKeyValueInQuery(url, "style", "inline"))
41 return true;
42 if (UrlContainsKeyValueInQuery(url, "style", "sectioned"))
43 return false;
44
45 return base::FeatureList::IsEnabled(features::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
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 = ShouldShowInlineStyleVariant(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;
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/welcome_win10_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698