Chromium Code Reviews| 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/command_line.h" |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 | 265 |
| 266 // TODO(dbeam): why must Invalidate() and OnPreferenceChanged() both exist? | 266 // TODO(dbeam): why must Invalidate() and OnPreferenceChanged() both exist? |
| 267 void NTPResourceCache::Invalidate() { | 267 void NTPResourceCache::Invalidate() { |
| 268 new_tab_incognito_html_ = nullptr; | 268 new_tab_incognito_html_ = nullptr; |
| 269 new_tab_html_ = nullptr; | 269 new_tab_html_ = nullptr; |
| 270 new_tab_incognito_css_ = nullptr; | 270 new_tab_incognito_css_ = nullptr; |
| 271 new_tab_css_ = nullptr; | 271 new_tab_css_ = nullptr; |
| 272 } | 272 } |
| 273 | 273 |
| 274 void NTPResourceCache::CreateNewTabIncognitoHTML() { | 274 void NTPResourceCache::CreateNewTabIncognitoHTML() { |
| 275 base::DictionaryValue localized_strings; | 275 ui::TemplateReplacements replacements; |
| 276 localized_strings.SetString("title", | 276 replacements["bookmarkbarattached"] = |
| 277 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); | 277 profile_->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar) |
| 278 int new_tab_description_ids = IDS_NEW_TAB_OTR_DESCRIPTION; | 278 ? "true" |
| 279 int new_tab_heading_ids = IDS_NEW_TAB_OTR_HEADING; | 279 : "false"; |
|
dschuyler
2017/04/19 01:37:30
Can this get a comment noting that this is a worka
Dan Beam
2017/04/20 00:10:53
Done.
| |
| 280 int new_tab_link_ids = IDS_NEW_TAB_OTR_LEARN_MORE_LINK; | 280 replacements["incognitoTabDescription"] = |
| 281 int new_tab_warning_ids = IDS_NEW_TAB_OTR_MESSAGE_WARNING; | 281 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_DESCRIPTION); |
| 282 int new_tab_html_idr = IDR_INCOGNITO_TAB_HTML; | 282 replacements["incognitoTabHeading"] = |
| 283 const char* new_tab_link = kLearnMoreIncognitoUrl; | 283 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_HEADING); |
| 284 | 284 replacements["incognitoTabWarning"] = |
| 285 if (profile_->IsGuestSession()) { | 285 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_MESSAGE_WARNING); |
| 286 localized_strings.SetString("guestTabDescription", | 286 replacements["learnMore"] = |
| 287 l10n_util::GetStringUTF16(new_tab_description_ids)); | 287 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_LEARN_MORE_LINK); |
| 288 localized_strings.SetString("guestTabHeading", | 288 replacements["learnMoreLink"] = kLearnMoreIncognitoUrl; |
| 289 l10n_util::GetStringUTF16(new_tab_heading_ids)); | 289 replacements["title"] = l10n_util::GetStringUTF8(IDS_NEW_TAB_TITLE); |
| 290 } else { | |
| 291 localized_strings.SetString("incognitoTabDescription", | |
| 292 l10n_util::GetStringUTF16(new_tab_description_ids)); | |
| 293 localized_strings.SetString("incognitoTabHeading", | |
| 294 l10n_util::GetStringUTF16(new_tab_heading_ids)); | |
| 295 localized_strings.SetString("incognitoTabWarning", | |
| 296 l10n_util::GetStringUTF16(new_tab_warning_ids)); | |
| 297 } | |
| 298 | |
| 299 localized_strings.SetString("learnMore", | |
| 300 l10n_util::GetStringUTF16(new_tab_link_ids)); | |
| 301 localized_strings.SetString("learnMoreLink", new_tab_link); | |
| 302 | |
| 303 bool bookmark_bar_attached = | |
| 304 profile_->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar); | |
| 305 localized_strings.SetBoolean("bookmarkbarattached", bookmark_bar_attached); | |
| 306 | 290 |
| 307 const ui::ThemeProvider& tp = | 291 const ui::ThemeProvider& tp = |
| 308 ThemeService::GetThemeProviderForProfile(profile_); | 292 ThemeService::GetThemeProviderForProfile(profile_); |
| 309 localized_strings.SetBoolean("hasCustomBackground", | 293 replacements["hasCustomBackground"] = |
| 310 tp.HasCustomImage(IDR_THEME_NTP_BACKGROUND)); | 294 tp.HasCustomImage(IDR_THEME_NTP_BACKGROUND) ? "true" : "false"; |
| 311 | 295 |
| 312 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 296 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
| 313 webui::SetLoadTimeDataDefaults(app_locale, &localized_strings); | 297 webui::SetLoadTimeDataDefaults(app_locale, &replacements); |
| 314 | 298 |
| 315 static const base::StringPiece incognito_tab_html( | 299 static const base::StringPiece incognito_tab_html( |
| 316 ResourceBundle::GetSharedInstance().GetRawDataResource( | 300 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 317 new_tab_html_idr)); | 301 IDR_INCOGNITO_TAB_HTML)); |
| 318 | 302 |
| 319 std::string full_html = webui::GetI18nTemplateHtml( | 303 std::string full_html = |
| 320 incognito_tab_html, &localized_strings); | 304 ui::ReplaceTemplateExpressions(incognito_tab_html, replacements); |
| 321 | 305 |
| 322 new_tab_incognito_html_ = base::RefCountedString::TakeString(&full_html); | 306 new_tab_incognito_html_ = base::RefCountedString::TakeString(&full_html); |
| 323 } | 307 } |
| 324 | 308 |
| 325 void NTPResourceCache::CreateNewTabGuestHTML() { | 309 void NTPResourceCache::CreateNewTabGuestHTML() { |
| 326 base::DictionaryValue localized_strings; | 310 base::DictionaryValue localized_strings; |
| 327 localized_strings.SetString("title", | 311 localized_strings.SetString("title", |
| 328 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); | 312 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); |
| 329 const char* guest_tab_link = kLearnMoreGuestSessionUrl; | 313 const char* guest_tab_link = kLearnMoreGuestSessionUrl; |
| 330 int guest_tab_ids = IDR_GUEST_TAB_HTML; | 314 int guest_tab_ids = IDR_GUEST_TAB_HTML; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 new_tab_guest_html_ = base::RefCountedString::TakeString(&full_html); | 359 new_tab_guest_html_ = base::RefCountedString::TakeString(&full_html); |
| 376 } | 360 } |
| 377 | 361 |
| 378 void NTPResourceCache::CreateNewTabHTML() { | 362 void NTPResourceCache::CreateNewTabHTML() { |
| 379 // TODO(estade): these strings should be defined in their relevant handlers | 363 // TODO(estade): these strings should be defined in their relevant handlers |
| 380 // (in GetLocalizedValues) and should have more legible names. | 364 // (in GetLocalizedValues) and should have more legible names. |
| 381 // Show the profile name in the title and most visited labels if the current | 365 // Show the profile name in the title and most visited labels if the current |
| 382 // profile is not the default. | 366 // profile is not the default. |
| 383 PrefService* prefs = profile_->GetPrefs(); | 367 PrefService* prefs = profile_->GetPrefs(); |
| 384 base::DictionaryValue load_time_data; | 368 base::DictionaryValue load_time_data; |
| 385 load_time_data.SetBoolean("bookmarkbarattached", | 369 load_time_data.SetString( |
| 386 prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar)); | 370 "bookmarkbarattached", |
| 371 prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar) ? "true" : "false"); | |
| 387 load_time_data.SetBoolean("showAppLauncherPromo", | 372 load_time_data.SetBoolean("showAppLauncherPromo", |
| 388 ShouldShowAppLauncherPromo()); | 373 ShouldShowAppLauncherPromo()); |
| 389 load_time_data.SetString("title", | 374 load_time_data.SetString("title", |
| 390 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); | 375 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); |
| 391 load_time_data.SetString("webStoreTitle", | 376 load_time_data.SetString("webStoreTitle", |
| 392 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE)); | 377 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE)); |
| 393 load_time_data.SetString("webStoreTitleShort", | 378 load_time_data.SetString("webStoreTitleShort", |
| 394 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE_SHORT)); | 379 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE_SHORT)); |
| 395 load_time_data.SetString("attributionintro", | 380 load_time_data.SetString("attributionintro", |
| 396 l10n_util::GetStringUTF16(IDS_NEW_TAB_ATTRIBUTION_INTRO)); | 381 l10n_util::GetStringUTF16(IDS_NEW_TAB_ATTRIBUTION_INTRO)); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 584 // Get our template. | 569 // Get our template. |
| 585 static const base::StringPiece new_tab_theme_css( | 570 static const base::StringPiece new_tab_theme_css( |
| 586 ResourceBundle::GetSharedInstance().GetRawDataResource( | 571 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 587 IDR_NEW_TAB_4_THEME_CSS)); | 572 IDR_NEW_TAB_4_THEME_CSS)); |
| 588 | 573 |
| 589 // Create the string from our template and the replacements. | 574 // Create the string from our template and the replacements. |
| 590 std::string css_string = | 575 std::string css_string = |
| 591 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); | 576 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); |
| 592 new_tab_css_ = base::RefCountedString::TakeString(&css_string); | 577 new_tab_css_ = base::RefCountedString::TakeString(&css_string); |
| 593 } | 578 } |
| OLD | NEW |