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

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

Issue 2804823002: Revamp the Incognito NTP on Desktop (Closed)
Patch Set: Font sizes 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 new_tab_incognito_html_ = nullptr; 273 new_tab_incognito_html_ = nullptr;
269 new_tab_html_ = nullptr; 274 new_tab_html_ = nullptr;
270 new_tab_incognito_css_ = nullptr; 275 new_tab_incognito_css_ = nullptr;
271 new_tab_css_ = nullptr; 276 new_tab_css_ = nullptr;
272 } 277 }
273 278
274 void NTPResourceCache::CreateNewTabIncognitoHTML() { 279 void NTPResourceCache::CreateNewTabIncognitoHTML() {
275 base::DictionaryValue localized_strings; 280 base::DictionaryValue localized_strings;
276 localized_strings.SetString("title", 281 localized_strings.SetString("title",
277 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); 282 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE));
283
278 int new_tab_description_ids = IDS_NEW_TAB_OTR_DESCRIPTION; 284 int new_tab_description_ids = IDS_NEW_TAB_OTR_DESCRIPTION;
279 int new_tab_heading_ids = IDS_NEW_TAB_OTR_HEADING; 285 int new_tab_heading_ids = IDS_NEW_TAB_OTR_HEADING;
280 int new_tab_link_ids = IDS_NEW_TAB_OTR_LEARN_MORE_LINK; 286 int new_tab_link_ids = IDS_NEW_TAB_OTR_LEARN_MORE_LINK;
281 int new_tab_warning_ids = IDS_NEW_TAB_OTR_MESSAGE_WARNING; 287 int new_tab_warning_ids = IDS_NEW_TAB_OTR_MESSAGE_WARNING;
288 int new_tab_features_ids = 0; // not used
282 int new_tab_html_idr = IDR_INCOGNITO_TAB_HTML; 289 int new_tab_html_idr = IDR_INCOGNITO_TAB_HTML;
283 const char* new_tab_link = kLearnMoreIncognitoUrl; 290 const char* new_tab_link = kLearnMoreIncognitoUrl;
284 291
292 // The MD Incognito NTP page uses different strings.
293 if (IsMDIncognitoTabEnabled() && !profile_->IsGuestSession()) {
294 new_tab_description_ids = IDS_NEW_TAB_OTR_SUBTITLE;
295 new_tab_heading_ids = IDS_NEW_TAB_OTR_TITLE;
296 new_tab_warning_ids = IDS_NEW_TAB_OTR_VISIBLE;
297 new_tab_features_ids = IDS_NEW_TAB_OTR_NOT_SAVED;
298 new_tab_html_idr = IDR_MD_INCOGNITO_TAB_HTML;
299 }
300
285 if (profile_->IsGuestSession()) { 301 if (profile_->IsGuestSession()) {
286 localized_strings.SetString("guestTabDescription", 302 localized_strings.SetString("guestTabDescription",
287 l10n_util::GetStringUTF16(new_tab_description_ids)); 303 l10n_util::GetStringUTF16(new_tab_description_ids));
288 localized_strings.SetString("guestTabHeading", 304 localized_strings.SetString("guestTabHeading",
289 l10n_util::GetStringUTF16(new_tab_heading_ids)); 305 l10n_util::GetStringUTF16(new_tab_heading_ids));
290 } else { 306 } else {
291 localized_strings.SetString("incognitoTabDescription", 307 localized_strings.SetString("incognitoTabDescription",
292 l10n_util::GetStringUTF16(new_tab_description_ids)); 308 l10n_util::GetStringUTF16(new_tab_description_ids));
293 localized_strings.SetString("incognitoTabHeading", 309 localized_strings.SetString("incognitoTabHeading",
294 l10n_util::GetStringUTF16(new_tab_heading_ids)); 310 l10n_util::GetStringUTF16(new_tab_heading_ids));
311
312 DCHECK_EQ(IsMDIncognitoTabEnabled(), !!new_tab_features_ids);
313 if (IsMDIncognitoTabEnabled()) {
314 localized_strings.SetString(
315 "incognitoTabFeatures",
316 l10n_util::GetStringUTF16(new_tab_features_ids));
317 }
295 localized_strings.SetString("incognitoTabWarning", 318 localized_strings.SetString("incognitoTabWarning",
296 l10n_util::GetStringUTF16(new_tab_warning_ids)); 319 l10n_util::GetStringUTF16(new_tab_warning_ids));
297 } 320 }
298 321
299 localized_strings.SetString("learnMore", 322 localized_strings.SetString("learnMore",
300 l10n_util::GetStringUTF16(new_tab_link_ids)); 323 l10n_util::GetStringUTF16(new_tab_link_ids));
301 localized_strings.SetString("learnMoreLink", new_tab_link); 324 localized_strings.SetString("learnMoreLink", new_tab_link);
302 325
303 bool bookmark_bar_attached = 326 bool bookmark_bar_attached =
304 profile_->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar); 327 profile_->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar);
305 localized_strings.SetBoolean("bookmarkbarattached", bookmark_bar_attached); 328 localized_strings.SetString("bookmarkbarattached",
329 bookmark_bar_attached ? "true" : "false");
306 330
307 const ui::ThemeProvider& tp = 331 const ui::ThemeProvider& tp =
308 ThemeService::GetThemeProviderForProfile(profile_); 332 ThemeService::GetThemeProviderForProfile(profile_);
309 localized_strings.SetBoolean("hasCustomBackground", 333 localized_strings.SetString(
310 tp.HasCustomImage(IDR_THEME_NTP_BACKGROUND)); 334 "hasCustomBackground",
335 tp.HasCustomImage(IDR_THEME_NTP_BACKGROUND) ? "true" : "false");
311 336
312 const std::string& app_locale = g_browser_process->GetApplicationLocale(); 337 const std::string& app_locale = g_browser_process->GetApplicationLocale();
313 webui::SetLoadTimeDataDefaults(app_locale, &localized_strings); 338 webui::SetLoadTimeDataDefaults(app_locale, &localized_strings);
314 339
315 static const base::StringPiece incognito_tab_html( 340 static const base::StringPiece incognito_tab_html(
316 ResourceBundle::GetSharedInstance().GetRawDataResource( 341 ResourceBundle::GetSharedInstance().GetRawDataResource(
317 new_tab_html_idr)); 342 new_tab_html_idr));
318 343
319 std::string full_html = webui::GetI18nTemplateHtml( 344 std::string full_html = webui::GetI18nTemplateHtml(
320 incognito_tab_html, &localized_strings); 345 incognito_tab_html, &localized_strings);
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 // Get our template. 609 // Get our template.
585 static const base::StringPiece new_tab_theme_css( 610 static const base::StringPiece new_tab_theme_css(
586 ResourceBundle::GetSharedInstance().GetRawDataResource( 611 ResourceBundle::GetSharedInstance().GetRawDataResource(
587 IDR_NEW_TAB_4_THEME_CSS)); 612 IDR_NEW_TAB_4_THEME_CSS));
588 613
589 // Create the string from our template and the replacements. 614 // Create the string from our template and the replacements.
590 std::string css_string = 615 std::string css_string =
591 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); 616 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions);
592 new_tab_css_ = base::RefCountedString::TakeString(&css_string); 617 new_tab_css_ = base::RefCountedString::TakeString(&css_string);
593 } 618 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698