| OLD | NEW |
| 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 266 |
| 266 // TODO(dbeam): why must Invalidate() and OnPreferenceChanged() both exist? | 267 // TODO(dbeam): why must Invalidate() and OnPreferenceChanged() both exist? |
| 267 void NTPResourceCache::Invalidate() { | 268 void NTPResourceCache::Invalidate() { |
| 268 new_tab_incognito_html_ = nullptr; | 269 new_tab_incognito_html_ = nullptr; |
| 269 new_tab_html_ = nullptr; | 270 new_tab_html_ = nullptr; |
| 270 new_tab_incognito_css_ = nullptr; | 271 new_tab_incognito_css_ = nullptr; |
| 271 new_tab_css_ = nullptr; | 272 new_tab_css_ = nullptr; |
| 272 } | 273 } |
| 273 | 274 |
| 274 void NTPResourceCache::CreateNewTabIncognitoHTML() { | 275 void NTPResourceCache::CreateNewTabIncognitoHTML() { |
| 276 const bool is_md_incognito_ntp_enabled = |
| 277 base::FeatureList::IsEnabled(features::kMaterialDesignIncognitoNTP); |
| 278 |
| 275 ui::TemplateReplacements replacements; | 279 ui::TemplateReplacements replacements; |
| 276 // Note: there's specific rules in CSS that look for this attribute's content | 280 // Note: there's specific rules in CSS that look for this attribute's content |
| 277 // being equal to "true" as a string. | 281 // being equal to "true" as a string. |
| 278 replacements["bookmarkbarattached"] = | 282 replacements["bookmarkbarattached"] = |
| 279 profile_->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar) | 283 profile_->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar) |
| 280 ? "true" | 284 ? "true" |
| 281 : "false"; | 285 : "false"; |
| 282 replacements["incognitoTabDescription"] = | 286 |
| 283 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_DESCRIPTION); | 287 if (is_md_incognito_ntp_enabled) { |
| 284 replacements["incognitoTabHeading"] = | 288 replacements["incognitoTabDescription"] = |
| 285 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_HEADING); | 289 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_SUBTITLE); |
| 286 replacements["incognitoTabWarning"] = | 290 replacements["incognitoTabHeading"] = |
| 287 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_MESSAGE_WARNING); | 291 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_TITLE); |
| 288 replacements["learnMore"] = | 292 replacements["incognitoTabWarning"] = |
| 289 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_LEARN_MORE_LINK); | 293 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_VISIBLE); |
| 294 replacements["learnMore"] = |
| 295 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_LEARN_MORE_LINK); |
| 296 replacements["incognitoTabFeatures"] = |
| 297 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_NOT_SAVED); |
| 298 } else { |
| 299 replacements["incognitoTabDescription"] = |
| 300 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_DESCRIPTION); |
| 301 replacements["incognitoTabHeading"] = |
| 302 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_HEADING); |
| 303 replacements["incognitoTabWarning"] = |
| 304 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_MESSAGE_WARNING); |
| 305 replacements["learnMore"] = |
| 306 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_LEARN_MORE_LINK); |
| 307 } |
| 290 replacements["learnMoreLink"] = kLearnMoreIncognitoUrl; | 308 replacements["learnMoreLink"] = kLearnMoreIncognitoUrl; |
| 291 replacements["title"] = l10n_util::GetStringUTF8(IDS_NEW_TAB_TITLE); | 309 replacements["title"] = l10n_util::GetStringUTF8(IDS_NEW_TAB_TITLE); |
| 292 | 310 |
| 293 const ui::ThemeProvider& tp = | 311 const ui::ThemeProvider& tp = |
| 294 ThemeService::GetThemeProviderForProfile(profile_); | 312 ThemeService::GetThemeProviderForProfile(profile_); |
| 295 replacements["hasCustomBackground"] = | 313 replacements["hasCustomBackground"] = |
| 296 tp.HasCustomImage(IDR_THEME_NTP_BACKGROUND) ? "true" : "false"; | 314 tp.HasCustomImage(IDR_THEME_NTP_BACKGROUND) ? "true" : "false"; |
| 297 | 315 |
| 298 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 316 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
| 299 webui::SetLoadTimeDataDefaults(app_locale, &replacements); | 317 webui::SetLoadTimeDataDefaults(app_locale, &replacements); |
| 300 | 318 |
| 301 static const base::StringPiece incognito_tab_html( | 319 static const base::StringPiece incognito_tab_html( |
| 302 ResourceBundle::GetSharedInstance().GetRawDataResource( | 320 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 303 IDR_INCOGNITO_TAB_HTML)); | 321 is_md_incognito_ntp_enabled ? IDR_MD_INCOGNITO_TAB_HTML |
| 322 : IDR_INCOGNITO_TAB_HTML)); |
| 304 | 323 |
| 305 std::string full_html = | 324 std::string full_html = |
| 306 ui::ReplaceTemplateExpressions(incognito_tab_html, replacements); | 325 ui::ReplaceTemplateExpressions(incognito_tab_html, replacements); |
| 307 | 326 |
| 308 new_tab_incognito_html_ = base::RefCountedString::TakeString(&full_html); | 327 new_tab_incognito_html_ = base::RefCountedString::TakeString(&full_html); |
| 309 } | 328 } |
| 310 | 329 |
| 311 void NTPResourceCache::CreateNewTabGuestHTML() { | 330 void NTPResourceCache::CreateNewTabGuestHTML() { |
| 312 base::DictionaryValue localized_strings; | 331 base::DictionaryValue localized_strings; |
| 313 localized_strings.SetString("title", | 332 localized_strings.SetString("title", |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 // Get our template. | 599 // Get our template. |
| 581 static const base::StringPiece new_tab_theme_css( | 600 static const base::StringPiece new_tab_theme_css( |
| 582 ResourceBundle::GetSharedInstance().GetRawDataResource( | 601 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 583 IDR_NEW_TAB_4_THEME_CSS)); | 602 IDR_NEW_TAB_4_THEME_CSS)); |
| 584 | 603 |
| 585 // Create the string from our template and the replacements. | 604 // Create the string from our template and the replacements. |
| 586 std::string css_string = | 605 std::string css_string = |
| 587 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); | 606 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); |
| 588 new_tab_css_ = base::RefCountedString::TakeString(&css_string); | 607 new_tab_css_ = base::RefCountedString::TakeString(&css_string); |
| 589 } | 608 } |
| OLD | NEW |