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

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

Issue 2826643002: Convert Incognito New Tab Page from i18n-* (JS) to $i18n{} (C++) (Closed)
Patch Set: todo 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/command_line.h"
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Note: there's specific rules in CSS that look for this attribute's content
277 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); 277 // being equal to "true" as a string.
278 int new_tab_description_ids = IDS_NEW_TAB_OTR_DESCRIPTION; 278 replacements["bookmarkbarattached"] =
279 int new_tab_heading_ids = IDS_NEW_TAB_OTR_HEADING; 279 profile_->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar)
280 int new_tab_link_ids = IDS_NEW_TAB_OTR_LEARN_MORE_LINK; 280 ? "true"
281 int new_tab_warning_ids = IDS_NEW_TAB_OTR_MESSAGE_WARNING; 281 : "false";
282 int new_tab_html_idr = IDR_INCOGNITO_TAB_HTML; 282 replacements["incognitoTabDescription"] =
283 const char* new_tab_link = kLearnMoreIncognitoUrl; 283 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_DESCRIPTION);
284 284 replacements["incognitoTabHeading"] =
285 if (profile_->IsGuestSession()) { 285 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_HEADING);
286 localized_strings.SetString("guestTabDescription", 286 replacements["incognitoTabWarning"] =
287 l10n_util::GetStringUTF16(new_tab_description_ids)); 287 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_MESSAGE_WARNING);
288 localized_strings.SetString("guestTabHeading", 288 replacements["learnMore"] =
289 l10n_util::GetStringUTF16(new_tab_heading_ids)); 289 l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_LEARN_MORE_LINK);
290 } else { 290 replacements["learnMoreLink"] = kLearnMoreIncognitoUrl;
291 localized_strings.SetString("incognitoTabDescription", 291 replacements["title"] = l10n_util::GetStringUTF8(IDS_NEW_TAB_TITLE);
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 292
307 const ui::ThemeProvider& tp = 293 const ui::ThemeProvider& tp =
308 ThemeService::GetThemeProviderForProfile(profile_); 294 ThemeService::GetThemeProviderForProfile(profile_);
309 localized_strings.SetBoolean("hasCustomBackground", 295 replacements["hasCustomBackground"] =
310 tp.HasCustomImage(IDR_THEME_NTP_BACKGROUND)); 296 tp.HasCustomImage(IDR_THEME_NTP_BACKGROUND) ? "true" : "false";
311 297
312 const std::string& app_locale = g_browser_process->GetApplicationLocale(); 298 const std::string& app_locale = g_browser_process->GetApplicationLocale();
313 webui::SetLoadTimeDataDefaults(app_locale, &localized_strings); 299 webui::SetLoadTimeDataDefaults(app_locale, &replacements);
314 300
315 static const base::StringPiece incognito_tab_html( 301 static const base::StringPiece incognito_tab_html(
316 ResourceBundle::GetSharedInstance().GetRawDataResource( 302 ResourceBundle::GetSharedInstance().GetRawDataResource(
317 new_tab_html_idr)); 303 IDR_INCOGNITO_TAB_HTML));
318 304
319 std::string full_html = webui::GetI18nTemplateHtml( 305 std::string full_html =
320 incognito_tab_html, &localized_strings); 306 ui::ReplaceTemplateExpressions(incognito_tab_html, replacements);
321 307
322 new_tab_incognito_html_ = base::RefCountedString::TakeString(&full_html); 308 new_tab_incognito_html_ = base::RefCountedString::TakeString(&full_html);
323 } 309 }
324 310
325 void NTPResourceCache::CreateNewTabGuestHTML() { 311 void NTPResourceCache::CreateNewTabGuestHTML() {
326 base::DictionaryValue localized_strings; 312 base::DictionaryValue localized_strings;
327 localized_strings.SetString("title", 313 localized_strings.SetString("title",
328 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); 314 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE));
329 const char* guest_tab_link = kLearnMoreGuestSessionUrl; 315 const char* guest_tab_link = kLearnMoreGuestSessionUrl;
330 int guest_tab_ids = IDR_GUEST_TAB_HTML; 316 int guest_tab_ids = IDR_GUEST_TAB_HTML;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 new_tab_guest_html_ = base::RefCountedString::TakeString(&full_html); 370 new_tab_guest_html_ = base::RefCountedString::TakeString(&full_html);
385 } 371 }
386 372
387 void NTPResourceCache::CreateNewTabHTML() { 373 void NTPResourceCache::CreateNewTabHTML() {
388 // TODO(estade): these strings should be defined in their relevant handlers 374 // TODO(estade): these strings should be defined in their relevant handlers
389 // (in GetLocalizedValues) and should have more legible names. 375 // (in GetLocalizedValues) and should have more legible names.
390 // Show the profile name in the title and most visited labels if the current 376 // Show the profile name in the title and most visited labels if the current
391 // profile is not the default. 377 // profile is not the default.
392 PrefService* prefs = profile_->GetPrefs(); 378 PrefService* prefs = profile_->GetPrefs();
393 base::DictionaryValue load_time_data; 379 base::DictionaryValue load_time_data;
394 load_time_data.SetBoolean("bookmarkbarattached", 380 load_time_data.SetString(
395 prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar)); 381 "bookmarkbarattached",
382 prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar) ? "true" : "false");
396 load_time_data.SetBoolean("showAppLauncherPromo", 383 load_time_data.SetBoolean("showAppLauncherPromo",
397 ShouldShowAppLauncherPromo()); 384 ShouldShowAppLauncherPromo());
398 load_time_data.SetString("title", 385 load_time_data.SetString("title",
399 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); 386 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE));
400 load_time_data.SetString("webStoreTitle", 387 load_time_data.SetString("webStoreTitle",
401 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE)); 388 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE));
402 load_time_data.SetString("webStoreTitleShort", 389 load_time_data.SetString("webStoreTitleShort",
403 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE_SHORT)); 390 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE_SHORT));
404 load_time_data.SetString("attributionintro", 391 load_time_data.SetString("attributionintro",
405 l10n_util::GetStringUTF16(IDS_NEW_TAB_ATTRIBUTION_INTRO)); 392 l10n_util::GetStringUTF16(IDS_NEW_TAB_ATTRIBUTION_INTRO));
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 // Get our template. 580 // Get our template.
594 static const base::StringPiece new_tab_theme_css( 581 static const base::StringPiece new_tab_theme_css(
595 ResourceBundle::GetSharedInstance().GetRawDataResource( 582 ResourceBundle::GetSharedInstance().GetRawDataResource(
596 IDR_NEW_TAB_4_THEME_CSS)); 583 IDR_NEW_TAB_4_THEME_CSS));
597 584
598 // Create the string from our template and the replacements. 585 // Create the string from our template and the replacements.
599 std::string css_string = 586 std::string css_string =
600 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); 587 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions);
601 new_tab_css_ = base::RefCountedString::TakeString(&css_string); 588 new_tab_css_ = base::RefCountedString::TakeString(&css_string);
602 } 589 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/ntp4/incognito_tab.html ('k') | chrome/browser/ui/webui/theme_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698