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

Side by Side Diff: chrome/browser/ui/webui/ntp/ntp_resource_cache.cc

Issue 2804823002: Revamp the Incognito NTP on Desktop (Closed)
Patch Set: Fixed histograms.xml Created 3 years, 8 months 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/ntp/ntp_resource_cache.h" 5 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/feature_list.h"
11 #include "base/memory/ref_counted_memory.h" 11 #include "base/memory/ref_counted_memory.h"
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/chrome_notification_types.h" 19 #include "chrome/browser/chrome_notification_types.h"
20 #include "chrome/browser/extensions/extension_util.h" 20 #include "chrome/browser/extensions/extension_util.h"
21 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/search/search.h" 22 #include "chrome/browser/search/search.h"
23 #include "chrome/browser/signin/signin_manager_factory.h" 23 #include "chrome/browser/signin/signin_manager_factory.h"
24 #include "chrome/browser/sync/profile_sync_service_factory.h" 24 #include "chrome/browser/sync/profile_sync_service_factory.h"
25 #include "chrome/browser/themes/theme_properties.h" 25 #include "chrome/browser/themes/theme_properties.h"
26 #include "chrome/browser/themes/theme_service.h" 26 #include "chrome/browser/themes/theme_service.h"
27 #include "chrome/browser/themes/theme_service_factory.h" 27 #include "chrome/browser/themes/theme_service_factory.h"
28 #include "chrome/browser/ui/app_list/app_list_util.h" 28 #include "chrome/browser/ui/app_list/app_list_util.h"
29 #include "chrome/browser/ui/apps/app_info_dialog.h" 29 #include "chrome/browser/ui/apps/app_info_dialog.h"
30 #include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h" 30 #include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h"
31 #include "chrome/browser/ui/sync/sync_promo_ui.h" 31 #include "chrome/browser/ui/sync/sync_promo_ui.h"
32 #include "chrome/browser/ui/webui/app_launcher_login_handler.h" 32 #include "chrome/browser/ui/webui/app_launcher_login_handler.h"
33 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" 33 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
34 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 34 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
35 #include "chrome/common/chrome_features.h"
35 #include "chrome/common/chrome_switches.h" 36 #include "chrome/common/chrome_switches.h"
36 #include "chrome/common/features.h" 37 #include "chrome/common/features.h"
37 #include "chrome/common/pref_names.h" 38 #include "chrome/common/pref_names.h"
38 #include "chrome/common/url_constants.h" 39 #include "chrome/common/url_constants.h"
39 #include "chrome/grit/browser_resources.h" 40 #include "chrome/grit/browser_resources.h"
40 #include "chrome/grit/chromium_strings.h" 41 #include "chrome/grit/chromium_strings.h"
41 #include "chrome/grit/generated_resources.h" 42 #include "chrome/grit/generated_resources.h"
42 #include "chrome/grit/locale_settings.h" 43 #include "chrome/grit/locale_settings.h"
43 #include "chrome/grit/theme_resources.h" 44 #include "chrome/grit/theme_resources.h"
44 #include "components/bookmarks/common/bookmark_pref_names.h" 45 #include "components/bookmarks/common/bookmark_pref_names.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 134
134 // How the background image on the new tab page should be tiled (see tiling 135 // How the background image on the new tab page should be tiled (see tiling
135 // masks in theme_service.h). 136 // masks in theme_service.h).
136 std::string GetNewTabBackgroundTilingCSS( 137 std::string GetNewTabBackgroundTilingCSS(
137 const ui::ThemeProvider& theme_provider) { 138 const ui::ThemeProvider& theme_provider) {
138 int repeat_mode = 139 int repeat_mode =
139 theme_provider.GetDisplayProperty(ThemeProperties::NTP_BACKGROUND_TILING); 140 theme_provider.GetDisplayProperty(ThemeProperties::NTP_BACKGROUND_TILING);
140 return ThemeProperties::TilingToString(repeat_mode); 141 return ThemeProperties::TilingToString(repeat_mode);
141 } 142 }
142 143
144 bool IsMDIncognitoTabEnabled() {
145 return base::FeatureList::IsEnabled(features::kMaterialDesignIncognitoNTP);
146 }
147
143 } // namespace 148 } // namespace
144 149
145 NTPResourceCache::NTPResourceCache(Profile* profile) 150 NTPResourceCache::NTPResourceCache(Profile* profile)
146 : profile_(profile), is_swipe_tracking_from_scroll_events_enabled_(false), 151 : profile_(profile), is_swipe_tracking_from_scroll_events_enabled_(false),
147 should_show_apps_page_(NewTabUI::ShouldShowApps()), 152 should_show_apps_page_(NewTabUI::ShouldShowApps()),
148 should_show_other_devices_menu_(true) { 153 should_show_other_devices_menu_(true) {
149 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 154 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
150 content::Source<ThemeService>( 155 content::Source<ThemeService>(
151 ThemeServiceFactory::GetForProfile(profile))); 156 ThemeServiceFactory::GetForProfile(profile)));
152 157
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 } 277 }
273 278
274 void NTPResourceCache::CreateNewTabIncognitoHTML() { 279 void NTPResourceCache::CreateNewTabIncognitoHTML() {
275 ui::TemplateReplacements replacements; 280 ui::TemplateReplacements replacements;
276 // Note: there's specific rules in CSS that look for this attribute's content 281 // Note: there's specific rules in CSS that look for this attribute's content
277 // being equal to "true" as a string. 282 // being equal to "true" as a string.
278 replacements["bookmarkbarattached"] = 283 replacements["bookmarkbarattached"] =
279 profile_->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar) 284 profile_->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar)
280 ? "true" 285 ? "true"
281 : "false"; 286 : "false";
282 replacements["incognitoTabDescription"] = 287
283 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_DESCRIPTION); 288 if (IsMDIncognitoTabEnabled()) {
Dan Beam 2017/04/20 18:27:51 nit: because only CreateNewTabIncognitoHTML() uses
msramek 2017/04/21 12:20:36 Done.
284 replacements["incognitoTabHeading"] = 289 replacements["incognitoTabDescription"] =
285 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_HEADING); 290 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_SUBTITLE);
286 replacements["incognitoTabWarning"] = 291 replacements["incognitoTabHeading"] =
287 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_MESSAGE_WARNING); 292 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_TITLE);
288 replacements["learnMore"] = 293 replacements["incognitoTabWarning"] =
289 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_LEARN_MORE_LINK); 294 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_VISIBLE);
295 replacements["learnMore"] =
296 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_LEARN_MORE_LINK);
297 replacements["incognitoTabFeatures"] =
298 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_NOT_SAVED);
299 } else {
300 replacements["incognitoTabDescription"] =
301 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_DESCRIPTION);
302 replacements["incognitoTabHeading"] =
303 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_HEADING);
304 replacements["incognitoTabWarning"] =
305 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_MESSAGE_WARNING);
306 replacements["learnMore"] =
307 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_LEARN_MORE_LINK);
308 }
290 replacements["learnMoreLink"] = kLearnMoreIncognitoUrl; 309 replacements["learnMoreLink"] = kLearnMoreIncognitoUrl;
291 replacements["title"] = l10n_util::GetStringUTF8(IDS_NEW_TAB_TITLE); 310 replacements["title"] = l10n_util::GetStringUTF8(IDS_NEW_TAB_TITLE);
292 311
293 const ui::ThemeProvider& tp = 312 const ui::ThemeProvider& tp =
294 ThemeService::GetThemeProviderForProfile(profile_); 313 ThemeService::GetThemeProviderForProfile(profile_);
295 replacements["hasCustomBackground"] = 314 replacements["hasCustomBackground"] =
296 tp.HasCustomImage(IDR_THEME_NTP_BACKGROUND) ? "true" : "false"; 315 tp.HasCustomImage(IDR_THEME_NTP_BACKGROUND) ? "true" : "false";
297 316
298 const std::string& app_locale = g_browser_process->GetApplicationLocale(); 317 const std::string& app_locale = g_browser_process->GetApplicationLocale();
299 webui::SetLoadTimeDataDefaults(app_locale, &replacements); 318 webui::SetLoadTimeDataDefaults(app_locale, &replacements);
300 319
301 static const base::StringPiece incognito_tab_html( 320 static const base::StringPiece incognito_tab_html(
302 ResourceBundle::GetSharedInstance().GetRawDataResource( 321 ResourceBundle::GetSharedInstance().GetRawDataResource(
303 IDR_INCOGNITO_TAB_HTML)); 322 IsMDIncognitoTabEnabled() ? IDR_MD_INCOGNITO_TAB_HTML
323 : IDR_INCOGNITO_TAB_HTML));
304 324
305 std::string full_html = 325 std::string full_html =
306 ui::ReplaceTemplateExpressions(incognito_tab_html, replacements); 326 ui::ReplaceTemplateExpressions(incognito_tab_html, replacements);
307 327
308 new_tab_incognito_html_ = base::RefCountedString::TakeString(&full_html); 328 new_tab_incognito_html_ = base::RefCountedString::TakeString(&full_html);
309 } 329 }
310 330
311 void NTPResourceCache::CreateNewTabGuestHTML() { 331 void NTPResourceCache::CreateNewTabGuestHTML() {
312 base::DictionaryValue localized_strings; 332 base::DictionaryValue localized_strings;
313 localized_strings.SetString("title", 333 localized_strings.SetString("title",
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 // Get our template. 600 // Get our template.
581 static const base::StringPiece new_tab_theme_css( 601 static const base::StringPiece new_tab_theme_css(
582 ResourceBundle::GetSharedInstance().GetRawDataResource( 602 ResourceBundle::GetSharedInstance().GetRawDataResource(
583 IDR_NEW_TAB_4_THEME_CSS)); 603 IDR_NEW_TAB_4_THEME_CSS));
584 604
585 // Create the string from our template and the replacements. 605 // Create the string from our template and the replacements.
586 std::string css_string = 606 std::string css_string =
587 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); 607 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions);
588 new_tab_css_ = base::RefCountedString::TakeString(&css_string); 608 new_tab_css_ = base::RefCountedString::TakeString(&css_string);
589 } 609 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698