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

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

Issue 10141005: switch ntp to jstemplate v2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update test Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 301
302 new_tab_incognito_html_ = base::RefCountedString::TakeString(&full_html); 302 new_tab_incognito_html_ = base::RefCountedString::TakeString(&full_html);
303 } 303 }
304 304
305 void NTPResourceCache::CreateNewTabHTML() { 305 void NTPResourceCache::CreateNewTabHTML() {
306 // TODO(estade): these strings should be defined in their relevant handlers 306 // TODO(estade): these strings should be defined in their relevant handlers
307 // (in GetLocalizedValues) and should have more legible names. 307 // (in GetLocalizedValues) and should have more legible names.
308 // Show the profile name in the title and most visited labels if the current 308 // Show the profile name in the title and most visited labels if the current
309 // profile is not the default. 309 // profile is not the default.
310 PrefService* prefs = profile_->GetPrefs(); 310 PrefService* prefs = profile_->GetPrefs();
311 DictionaryValue localized_strings; 311 DictionaryValue load_time_data;
312 localized_strings.SetString("bookmarkbarattached", 312 load_time_data.SetString("bookmarkbarattached",
313 prefs->GetBoolean(prefs::kShowBookmarkBar) ? "true" : "false"); 313 prefs->GetBoolean(prefs::kShowBookmarkBar) ? "true" : "false");
314 localized_strings.SetString("hasattribution", 314 load_time_data.SetString("hasattribution",
315 ThemeServiceFactory::GetForProfile(profile_)->HasCustomImage( 315 ThemeServiceFactory::GetForProfile(profile_)->HasCustomImage(
316 IDR_THEME_NTP_ATTRIBUTION) ? 316 IDR_THEME_NTP_ATTRIBUTION) ?
317 "true" : "false"); 317 "true" : "false");
Dan Beam 2012/04/25 23:13:12 shouldn't these be booleans now?
Evan Stade 2012/04/26 00:44:56 doesn't really matter in this case as it's just sh
318 localized_strings.SetString("title", 318 load_time_data.SetString("title",
319 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); 319 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE));
320 localized_strings.SetString("mostvisited", 320 load_time_data.SetString("mostvisited",
321 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED)); 321 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED));
322 localized_strings.SetString("suggestions", 322 load_time_data.SetString("suggestions",
323 l10n_util::GetStringUTF16(IDS_NEW_TAB_SUGGESTIONS)); 323 l10n_util::GetStringUTF16(IDS_NEW_TAB_SUGGESTIONS));
324 localized_strings.SetString("restoreThumbnailsShort", 324 load_time_data.SetString("restoreThumbnailsShort",
325 l10n_util::GetStringUTF16(IDS_NEW_TAB_RESTORE_THUMBNAILS_SHORT_LINK)); 325 l10n_util::GetStringUTF16(IDS_NEW_TAB_RESTORE_THUMBNAILS_SHORT_LINK));
326 localized_strings.SetString("recentlyclosed", 326 load_time_data.SetString("recentlyclosed",
327 l10n_util::GetStringUTF16(IDS_NEW_TAB_RECENTLY_CLOSED)); 327 l10n_util::GetStringUTF16(IDS_NEW_TAB_RECENTLY_CLOSED));
328 localized_strings.SetString("webStoreTitle", 328 load_time_data.SetString("webStoreTitle",
329 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE)); 329 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE));
330 localized_strings.SetString("webStoreTitleShort", 330 load_time_data.SetString("webStoreTitleShort",
331 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE_SHORT)); 331 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE_SHORT));
332 localized_strings.SetString("closedwindowsingle", 332 load_time_data.SetString("closedwindowsingle",
333 l10n_util::GetStringUTF16(IDS_NEW_TAB_RECENTLY_CLOSED_WINDOW_SINGLE)); 333 l10n_util::GetStringUTF16(IDS_NEW_TAB_RECENTLY_CLOSED_WINDOW_SINGLE));
334 localized_strings.SetString("closedwindowmultiple", 334 load_time_data.SetString("closedwindowmultiple",
335 l10n_util::GetStringUTF16(IDS_NEW_TAB_RECENTLY_CLOSED_WINDOW_MULTIPLE)); 335 l10n_util::GetStringUTF16(IDS_NEW_TAB_RECENTLY_CLOSED_WINDOW_MULTIPLE));
336 localized_strings.SetString("attributionintro", 336 load_time_data.SetString("attributionintro",
337 l10n_util::GetStringUTF16(IDS_NEW_TAB_ATTRIBUTION_INTRO)); 337 l10n_util::GetStringUTF16(IDS_NEW_TAB_ATTRIBUTION_INTRO));
338 localized_strings.SetString("thumbnailremovednotification", 338 load_time_data.SetString("thumbnailremovednotification",
339 l10n_util::GetStringUTF16(IDS_NEW_TAB_THUMBNAIL_REMOVED_NOTIFICATION)); 339 l10n_util::GetStringUTF16(IDS_NEW_TAB_THUMBNAIL_REMOVED_NOTIFICATION));
340 localized_strings.SetString("undothumbnailremove", 340 load_time_data.SetString("undothumbnailremove",
341 l10n_util::GetStringUTF16(IDS_NEW_TAB_UNDO_THUMBNAIL_REMOVE)); 341 l10n_util::GetStringUTF16(IDS_NEW_TAB_UNDO_THUMBNAIL_REMOVE));
342 localized_strings.SetString("removethumbnailtooltip", 342 load_time_data.SetString("removethumbnailtooltip",
343 l10n_util::GetStringUTF16(IDS_NEW_TAB_REMOVE_THUMBNAIL_TOOLTIP)); 343 l10n_util::GetStringUTF16(IDS_NEW_TAB_REMOVE_THUMBNAIL_TOOLTIP));
344 localized_strings.SetString("appuninstall", 344 load_time_data.SetString("appuninstall",
345 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); 345 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL));
346 localized_strings.SetString("appoptions", 346 load_time_data.SetString("appoptions",
347 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_OPTIONS)); 347 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_OPTIONS));
348 localized_strings.SetString("appdisablenotifications", 348 load_time_data.SetString("appdisablenotifications",
349 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_DISABLE_NOTIFICATIONS)); 349 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_DISABLE_NOTIFICATIONS));
350 localized_strings.SetString("appcreateshortcut", 350 load_time_data.SetString("appcreateshortcut",
351 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_CREATE_SHORTCUT)); 351 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_CREATE_SHORTCUT));
352 localized_strings.SetString("appDefaultPageName", 352 load_time_data.SetString("appDefaultPageName",
353 l10n_util::GetStringUTF16(IDS_APP_DEFAULT_PAGE_NAME)); 353 l10n_util::GetStringUTF16(IDS_APP_DEFAULT_PAGE_NAME));
354 localized_strings.SetString("applaunchtypepinned", 354 load_time_data.SetString("applaunchtypepinned",
355 l10n_util::GetStringUTF16(IDS_APP_CONTEXT_MENU_OPEN_PINNED)); 355 l10n_util::GetStringUTF16(IDS_APP_CONTEXT_MENU_OPEN_PINNED));
356 localized_strings.SetString("applaunchtyperegular", 356 load_time_data.SetString("applaunchtyperegular",
357 l10n_util::GetStringUTF16(IDS_APP_CONTEXT_MENU_OPEN_REGULAR)); 357 l10n_util::GetStringUTF16(IDS_APP_CONTEXT_MENU_OPEN_REGULAR));
358 localized_strings.SetString("applaunchtypewindow", 358 load_time_data.SetString("applaunchtypewindow",
359 l10n_util::GetStringUTF16(IDS_APP_CONTEXT_MENU_OPEN_WINDOW)); 359 l10n_util::GetStringUTF16(IDS_APP_CONTEXT_MENU_OPEN_WINDOW));
360 localized_strings.SetString("applaunchtypefullscreen", 360 load_time_data.SetString("applaunchtypefullscreen",
361 l10n_util::GetStringUTF16(IDS_APP_CONTEXT_MENU_OPEN_FULLSCREEN)); 361 l10n_util::GetStringUTF16(IDS_APP_CONTEXT_MENU_OPEN_FULLSCREEN));
362 localized_strings.SetString("syncpromotext", 362 load_time_data.SetString("syncpromotext",
363 l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL)); 363 l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL));
364 localized_strings.SetString("syncLinkText", 364 load_time_data.SetString("syncLinkText",
365 l10n_util::GetStringUTF16(IDS_SYNC_ADVANCED_OPTIONS)); 365 l10n_util::GetStringUTF16(IDS_SYNC_ADVANCED_OPTIONS));
366 localized_strings.SetString("otherSessions", 366 load_time_data.SetString("otherSessions",
367 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_LABEL)); 367 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_LABEL));
368 localized_strings.SetString("otherSessionsEmpty", 368 load_time_data.SetString("otherSessionsEmpty",
369 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_EMPTY)); 369 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_EMPTY));
370 localized_strings.SetString("otherSessionsLearnMoreUrl", 370 load_time_data.SetString("otherSessionsLearnMoreUrl",
371 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_LEARN_MORE_URL)); 371 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_LEARN_MORE_URL));
372 localized_strings.SetString("learnMore", 372 load_time_data.SetString("learnMore",
373 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); 373 l10n_util::GetStringUTF16(IDS_LEARN_MORE));
374 localized_strings.SetString("webStoreLink", 374 load_time_data.SetString("webStoreLink",
375 GetUrlWithLang(GURL(extension_urls::GetWebstoreLaunchURL()))); 375 GetUrlWithLang(GURL(extension_urls::GetWebstoreLaunchURL())));
376 localized_strings.SetBoolean("isWebStoreExperimentEnabled", 376 load_time_data.SetBoolean("isWebStoreExperimentEnabled",
377 NewTabUI::ShouldShowWebStoreFooterLink()); 377 NewTabUI::ShouldShowWebStoreFooterLink());
378 localized_strings.SetBoolean("appInstallHintEnabled", 378 load_time_data.SetBoolean("appInstallHintEnabled",
379 NewTabUI::ShouldShowAppInstallHint()); 379 NewTabUI::ShouldShowAppInstallHint());
380 localized_strings.SetString("appInstallHintText", 380 load_time_data.SetString("appInstallHintText",
381 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_INSTALL_HINT_LABEL)); 381 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_INSTALL_HINT_LABEL));
382 localized_strings.SetBoolean("isSuggestionsPageEnabled", 382 load_time_data.SetBoolean("isSuggestionsPageEnabled",
383 NewTabUI::IsSuggestionsPageEnabled()); 383 NewTabUI::IsSuggestionsPageEnabled());
384 localized_strings.SetBoolean("showApps", NewTabUI::ShouldShowApps()); 384 load_time_data.SetBoolean("showApps", NewTabUI::ShouldShowApps());
385 localized_strings.SetString("hideSessionMenuItemText", 385 load_time_data.SetString("hideSessionMenuItemText",
386 l10n_util::GetStringUTF16(IDS_POLICY_HIDE)); 386 l10n_util::GetStringUTF16(IDS_POLICY_HIDE));
387 load_time_data.SetString("learn_more",
388 l10n_util::GetStringUTF16(IDS_LEARN_MORE));
387 389
388 // On Mac OS X 10.7+, horizontal scrolling can be treated as a back or 390 // On Mac OS X 10.7+, horizontal scrolling can be treated as a back or
389 // forward gesture. Pass through a flag that indicates whether or not that 391 // forward gesture. Pass through a flag that indicates whether or not that
390 // feature is enabled. 392 // feature is enabled.
391 localized_strings.SetBoolean("isSwipeTrackingFromScrollEventsEnabled", 393 load_time_data.SetBoolean("isSwipeTrackingFromScrollEventsEnabled",
Dan Beam 2012/04/25 23:13:12 fix indent, additionally you could #if #def out th
Evan Stade 2012/04/26 00:44:56 nope, it is required.
392 is_swipe_tracking_from_scroll_events_enabled_); 394 is_swipe_tracking_from_scroll_events_enabled_);
393 395
394 #if defined(OS_CHROMEOS) 396 #if defined(OS_CHROMEOS)
395 localized_strings.SetString("expandMenu", 397 load_time_data.SetString("expandMenu",
396 l10n_util::GetStringUTF16(IDS_NEW_TAB_CLOSE_MENU_EXPAND)); 398 l10n_util::GetStringUTF16(IDS_NEW_TAB_CLOSE_MENU_EXPAND));
397 #endif 399 #endif
398 400
399 NewTabPageHandler::GetLocalizedValues(profile_, &localized_strings); 401 NewTabPageHandler::GetLocalizedValues(profile_, &load_time_data);
400 NTPLoginHandler::GetLocalizedValues(profile_, &localized_strings); 402 NTPLoginHandler::GetLocalizedValues(profile_, &load_time_data);
401 403
402 // Don't initiate the sync related message passing with the page if the sync 404 // Don't initiate the sync related message passing with the page if the sync
403 // code is not present. 405 // code is not present.
404 if (ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_)) 406 if (ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_))
405 localized_strings.SetString("syncispresent", "true"); 407 load_time_data.SetString("syncispresent", "true");
406 else 408 else
407 localized_strings.SetString("syncispresent", "false"); 409 load_time_data.SetString("syncispresent", "false");
Dan Beam 2012/04/25 23:13:12 shouldn't this be a boolean now, as well?
Evan Stade 2012/04/26 00:44:56 apparently not used any more.
408 410
409 ChromeURLDataManager::DataSource::SetFontAndTextDirection(&localized_strings); 411 ChromeURLDataManager::DataSource::SetFontAndTextDirection(&load_time_data);
410 412
411 // Control fade and resize animations. 413 // Control fade and resize animations.
412 std::string anim = 414 std::string anim =
413 ui::Animation::ShouldRenderRichAnimation() ? "true" : "false"; 415 ui::Animation::ShouldRenderRichAnimation() ? "true" : "false";
414 localized_strings.SetString("anim", anim); 416 load_time_data.SetString("anim", anim);
415 417
416 int alignment; 418 int alignment;
417 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); 419 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_);
418 tp->GetDisplayProperty(ThemeService::NTP_BACKGROUND_ALIGNMENT, &alignment); 420 tp->GetDisplayProperty(ThemeService::NTP_BACKGROUND_ALIGNMENT, &alignment);
419 localized_strings.SetString("themegravity", 421 load_time_data.SetString("themegravity",
420 (alignment & ThemeService::ALIGN_RIGHT) ? "right" : ""); 422 (alignment & ThemeService::ALIGN_RIGHT) ? "right" : "");
421 423
422 #if defined(ENABLE_PROMO_RESOURCE_SERVICE) 424 #if defined(ENABLE_PROMO_RESOURCE_SERVICE)
423 // If the user has preferences for a start and end time for a promo from 425 // If the user has preferences for a start and end time for a promo from
424 // the server, and this promo string exists, set the localized string. 426 // the server, and this promo string exists, set the localized string.
425 if (PromoResourceService::CanShowNotificationPromo(profile_)) { 427 if (PromoResourceService::CanShowNotificationPromo(profile_)) {
426 localized_strings.SetString("serverpromo", 428 load_time_data.SetString("serverpromo",
427 prefs->GetString(prefs::kNtpPromoLine)); 429 prefs->GetString(prefs::kNtpPromoLine));
428 } 430 }
429 431
430 // If the user has preferences for a start and end time for a custom logo, 432 // If the user has preferences for a start and end time for a custom logo,
431 // and the time now is between these two times, show the custom logo. 433 // and the time now is between these two times, show the custom logo.
432 if (prefs->FindPreference(prefs::kNtpCustomLogoStart) && 434 if (prefs->FindPreference(prefs::kNtpCustomLogoStart) &&
433 prefs->FindPreference(prefs::kNtpCustomLogoEnd)) { 435 prefs->FindPreference(prefs::kNtpCustomLogoEnd)) {
434 localized_strings.SetString("customlogo", 436 load_time_data.SetString("customlogo",
435 InDateRange(prefs->GetDouble(prefs::kNtpCustomLogoStart), 437 InDateRange(prefs->GetDouble(prefs::kNtpCustomLogoStart),
436 prefs->GetDouble(prefs::kNtpCustomLogoEnd)) ? 438 prefs->GetDouble(prefs::kNtpCustomLogoEnd)) ?
437 "true" : "false"); 439 "true" : "false");
438 } else { 440 } else {
439 localized_strings.SetString("customlogo", "false"); 441 load_time_data.SetString("customlogo", "false");
440 } 442 }
441 #else 443 #else
442 localized_strings.SetString("customlogo", "false"); 444 load_time_data.SetString("customlogo", "false");
443 #endif 445 #endif
Dan Beam 2012/04/25 23:13:12 same question wrt type (boolean vs. string)
Evan Stade 2012/04/26 00:44:56 Done.
444 446
445 // Determine whether to show the menu for accessing tabs on other devices. 447 // Determine whether to show the menu for accessing tabs on other devices.
446 bool show_other_sessions_menu = !CommandLine::ForCurrentProcess()->HasSwitch( 448 bool show_other_sessions_menu = !CommandLine::ForCurrentProcess()->HasSwitch(
447 switches::kDisableNTPOtherSessionsMenu); 449 switches::kDisableNTPOtherSessionsMenu);
448 localized_strings.SetBoolean("showOtherSessionsMenu", 450 load_time_data.SetBoolean("showOtherSessionsMenu",
449 show_other_sessions_menu); 451 show_other_sessions_menu);
450 localized_strings.SetBoolean("isUserSignedIn", 452 load_time_data.SetBoolean("isUserSignedIn",
451 !prefs->GetString(prefs::kGoogleServicesUsername).empty()); 453 !prefs->GetString(prefs::kGoogleServicesUsername).empty());
452 454
453 // Load the new tab page appropriate for this build 455 // Load the new tab page appropriate for this build
454 std::string full_html;
455 base::StringPiece new_tab_html(ResourceBundle::GetSharedInstance(). 456 base::StringPiece new_tab_html(ResourceBundle::GetSharedInstance().
456 GetRawDataResource(IDR_NEW_TAB_4_HTML)); 457 GetRawDataResource(IDR_NEW_TAB_4_HTML));
457 full_html = jstemplate_builder::GetI18nTemplateHtml(new_tab_html, 458 jstemplate_builder::UseVersion2 version2;
458 &localized_strings); 459 std::string full_html =
460 jstemplate_builder::GetI18nTemplateHtml(new_tab_html, &load_time_data);
459 new_tab_html_ = base::RefCountedString::TakeString(&full_html); 461 new_tab_html_ = base::RefCountedString::TakeString(&full_html);
460 } 462 }
461 463
462 void NTPResourceCache::CreateNewTabIncognitoCSS() { 464 void NTPResourceCache::CreateNewTabIncognitoCSS() {
463 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); 465 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_);
464 DCHECK(tp); 466 DCHECK(tp);
465 467
466 // Get our theme colors 468 // Get our theme colors
467 SkColor color_background = 469 SkColor color_background =
468 GetThemeColor(tp, ThemeService::COLOR_NTP_BACKGROUND); 470 GetThemeColor(tp, ThemeService::COLOR_NTP_BACKGROUND);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 // Get our template. 580 // Get our template.
579 static const base::StringPiece new_tab_theme_css( 581 static const base::StringPiece new_tab_theme_css(
580 ResourceBundle::GetSharedInstance().GetRawDataResource( 582 ResourceBundle::GetSharedInstance().GetRawDataResource(
581 IDR_NEW_TAB_4_THEME_CSS)); 583 IDR_NEW_TAB_4_THEME_CSS));
582 584
583 // Create the string from our template and the replacements. 585 // Create the string from our template and the replacements.
584 std::string css_string; 586 std::string css_string;
585 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); 587 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL);
586 new_tab_css_ = base::RefCountedString::TakeString(&css_string); 588 new_tab_css_ = base::RefCountedString::TakeString(&css_string);
587 } 589 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698