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

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: fix test once and for all Created 8 years, 7 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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 #endif 279 #endif
280 localized_strings.SetString("content", 280 localized_strings.SetString("content",
281 l10n_util::GetStringFUTF16(new_tab_message_ids, 281 l10n_util::GetStringFUTF16(new_tab_message_ids,
282 GetUrlWithLang(GURL(new_tab_link)))); 282 GetUrlWithLang(GURL(new_tab_link))));
283 localized_strings.SetString("extensionsmessage", 283 localized_strings.SetString("extensionsmessage",
284 l10n_util::GetStringFUTF16( 284 l10n_util::GetStringFUTF16(
285 IDS_NEW_TAB_INCOGNITO_EXTENSIONS_MESSAGE, 285 IDS_NEW_TAB_INCOGNITO_EXTENSIONS_MESSAGE,
286 ASCIIToUTF16(chrome::kChromeUIExtensionsURL))); 286 ASCIIToUTF16(chrome::kChromeUIExtensionsURL)));
287 bool bookmark_bar_attached = profile_->GetPrefs()->GetBoolean( 287 bool bookmark_bar_attached = profile_->GetPrefs()->GetBoolean(
288 prefs::kShowBookmarkBar); 288 prefs::kShowBookmarkBar);
289 localized_strings.SetString("bookmarkbarattached", 289 localized_strings.SetBoolean("bookmarkbarattached", bookmark_bar_attached);
290 bookmark_bar_attached ? "true" : "false");
291 290
292 ChromeURLDataManager::DataSource::SetFontAndTextDirection(&localized_strings); 291 ChromeURLDataManager::DataSource::SetFontAndTextDirection(&localized_strings);
293 292
294 static const base::StringPiece incognito_tab_html( 293 static const base::StringPiece incognito_tab_html(
295 ResourceBundle::GetSharedInstance().GetRawDataResource( 294 ResourceBundle::GetSharedInstance().GetRawDataResource(
296 new_tab_html_idr)); 295 new_tab_html_idr));
297 296
298 std::string full_html = jstemplate_builder::GetI18nTemplateHtml( 297 std::string full_html = jstemplate_builder::GetI18nTemplateHtml(
299 incognito_tab_html, &localized_strings); 298 incognito_tab_html, &localized_strings);
300 299
301 new_tab_incognito_html_ = base::RefCountedString::TakeString(&full_html); 300 new_tab_incognito_html_ = base::RefCountedString::TakeString(&full_html);
302 } 301 }
303 302
304 void NTPResourceCache::CreateNewTabHTML() { 303 void NTPResourceCache::CreateNewTabHTML() {
305 // TODO(estade): these strings should be defined in their relevant handlers 304 // TODO(estade): these strings should be defined in their relevant handlers
306 // (in GetLocalizedValues) and should have more legible names. 305 // (in GetLocalizedValues) and should have more legible names.
307 // Show the profile name in the title and most visited labels if the current 306 // Show the profile name in the title and most visited labels if the current
308 // profile is not the default. 307 // profile is not the default.
309 PrefService* prefs = profile_->GetPrefs(); 308 PrefService* prefs = profile_->GetPrefs();
310 DictionaryValue localized_strings; 309 DictionaryValue load_time_data;
311 localized_strings.SetString("bookmarkbarattached", 310 load_time_data.SetBoolean("bookmarkbarattached",
312 prefs->GetBoolean(prefs::kShowBookmarkBar) ? "true" : "false"); 311 prefs->GetBoolean(prefs::kShowBookmarkBar));
313 localized_strings.SetString("hasattribution", 312 load_time_data.SetBoolean("hasattribution",
314 ThemeServiceFactory::GetForProfile(profile_)->HasCustomImage( 313 ThemeServiceFactory::GetForProfile(profile_)->HasCustomImage(
315 IDR_THEME_NTP_ATTRIBUTION) ? 314 IDR_THEME_NTP_ATTRIBUTION));
316 "true" : "false"); 315 load_time_data.SetString("title",
317 localized_strings.SetString("title",
318 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); 316 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE));
319 localized_strings.SetString("mostvisited", 317 load_time_data.SetString("mostvisited",
320 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED)); 318 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED));
321 localized_strings.SetString("suggestions", 319 load_time_data.SetString("suggestions",
322 l10n_util::GetStringUTF16(IDS_NEW_TAB_SUGGESTIONS)); 320 l10n_util::GetStringUTF16(IDS_NEW_TAB_SUGGESTIONS));
323 localized_strings.SetString("restoreThumbnailsShort", 321 load_time_data.SetString("restoreThumbnailsShort",
324 l10n_util::GetStringUTF16(IDS_NEW_TAB_RESTORE_THUMBNAILS_SHORT_LINK)); 322 l10n_util::GetStringUTF16(IDS_NEW_TAB_RESTORE_THUMBNAILS_SHORT_LINK));
325 localized_strings.SetString("recentlyclosed", 323 load_time_data.SetString("recentlyclosed",
326 l10n_util::GetStringUTF16(IDS_NEW_TAB_RECENTLY_CLOSED)); 324 l10n_util::GetStringUTF16(IDS_NEW_TAB_RECENTLY_CLOSED));
327 localized_strings.SetString("webStoreTitle", 325 load_time_data.SetString("webStoreTitle",
328 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE)); 326 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE));
329 localized_strings.SetString("webStoreTitleShort", 327 load_time_data.SetString("webStoreTitleShort",
330 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE_SHORT)); 328 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE_SHORT));
331 localized_strings.SetString("closedwindowsingle", 329 load_time_data.SetString("closedwindowsingle",
332 l10n_util::GetStringUTF16(IDS_NEW_TAB_RECENTLY_CLOSED_WINDOW_SINGLE)); 330 l10n_util::GetStringUTF16(IDS_NEW_TAB_RECENTLY_CLOSED_WINDOW_SINGLE));
333 localized_strings.SetString("closedwindowmultiple", 331 load_time_data.SetString("closedwindowmultiple",
334 l10n_util::GetStringUTF16(IDS_NEW_TAB_RECENTLY_CLOSED_WINDOW_MULTIPLE)); 332 l10n_util::GetStringUTF16(IDS_NEW_TAB_RECENTLY_CLOSED_WINDOW_MULTIPLE));
335 localized_strings.SetString("attributionintro", 333 load_time_data.SetString("attributionintro",
336 l10n_util::GetStringUTF16(IDS_NEW_TAB_ATTRIBUTION_INTRO)); 334 l10n_util::GetStringUTF16(IDS_NEW_TAB_ATTRIBUTION_INTRO));
337 localized_strings.SetString("thumbnailremovednotification", 335 load_time_data.SetString("thumbnailremovednotification",
338 l10n_util::GetStringUTF16(IDS_NEW_TAB_THUMBNAIL_REMOVED_NOTIFICATION)); 336 l10n_util::GetStringUTF16(IDS_NEW_TAB_THUMBNAIL_REMOVED_NOTIFICATION));
339 localized_strings.SetString("undothumbnailremove", 337 load_time_data.SetString("undothumbnailremove",
340 l10n_util::GetStringUTF16(IDS_NEW_TAB_UNDO_THUMBNAIL_REMOVE)); 338 l10n_util::GetStringUTF16(IDS_NEW_TAB_UNDO_THUMBNAIL_REMOVE));
341 localized_strings.SetString("removethumbnailtooltip", 339 load_time_data.SetString("removethumbnailtooltip",
342 l10n_util::GetStringUTF16(IDS_NEW_TAB_REMOVE_THUMBNAIL_TOOLTIP)); 340 l10n_util::GetStringUTF16(IDS_NEW_TAB_REMOVE_THUMBNAIL_TOOLTIP));
343 localized_strings.SetString("appuninstall", 341 load_time_data.SetString("appuninstall",
344 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); 342 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL));
345 localized_strings.SetString("appoptions", 343 load_time_data.SetString("appoptions",
346 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_OPTIONS)); 344 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_OPTIONS));
347 localized_strings.SetString("appdisablenotifications", 345 load_time_data.SetString("appdisablenotifications",
348 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_DISABLE_NOTIFICATIONS)); 346 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_DISABLE_NOTIFICATIONS));
349 localized_strings.SetString("appcreateshortcut", 347 load_time_data.SetString("appcreateshortcut",
350 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_CREATE_SHORTCUT)); 348 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_CREATE_SHORTCUT));
351 localized_strings.SetString("appDefaultPageName", 349 load_time_data.SetString("appDefaultPageName",
352 l10n_util::GetStringUTF16(IDS_APP_DEFAULT_PAGE_NAME)); 350 l10n_util::GetStringUTF16(IDS_APP_DEFAULT_PAGE_NAME));
353 localized_strings.SetString("applaunchtypepinned", 351 load_time_data.SetString("applaunchtypepinned",
354 l10n_util::GetStringUTF16(IDS_APP_CONTEXT_MENU_OPEN_PINNED)); 352 l10n_util::GetStringUTF16(IDS_APP_CONTEXT_MENU_OPEN_PINNED));
355 localized_strings.SetString("applaunchtyperegular", 353 load_time_data.SetString("applaunchtyperegular",
356 l10n_util::GetStringUTF16(IDS_APP_CONTEXT_MENU_OPEN_REGULAR)); 354 l10n_util::GetStringUTF16(IDS_APP_CONTEXT_MENU_OPEN_REGULAR));
357 localized_strings.SetString("applaunchtypewindow", 355 load_time_data.SetString("applaunchtypewindow",
358 l10n_util::GetStringUTF16(IDS_APP_CONTEXT_MENU_OPEN_WINDOW)); 356 l10n_util::GetStringUTF16(IDS_APP_CONTEXT_MENU_OPEN_WINDOW));
359 localized_strings.SetString("applaunchtypefullscreen", 357 load_time_data.SetString("applaunchtypefullscreen",
360 l10n_util::GetStringUTF16(IDS_APP_CONTEXT_MENU_OPEN_FULLSCREEN)); 358 l10n_util::GetStringUTF16(IDS_APP_CONTEXT_MENU_OPEN_FULLSCREEN));
361 localized_strings.SetString("syncpromotext", 359 load_time_data.SetString("syncpromotext",
362 l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL)); 360 l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL));
363 localized_strings.SetString("syncLinkText", 361 load_time_data.SetString("syncLinkText",
364 l10n_util::GetStringUTF16(IDS_SYNC_ADVANCED_OPTIONS)); 362 l10n_util::GetStringUTF16(IDS_SYNC_ADVANCED_OPTIONS));
365 localized_strings.SetString("otherSessions", 363 load_time_data.SetString("otherSessions",
366 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_LABEL)); 364 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_LABEL));
367 localized_strings.SetString("otherSessionsEmpty", 365 load_time_data.SetString("otherSessionsEmpty",
368 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_EMPTY)); 366 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_EMPTY));
369 localized_strings.SetString("otherSessionsLearnMoreUrl", 367 load_time_data.SetString("otherSessionsLearnMoreUrl",
370 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_LEARN_MORE_URL)); 368 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_LEARN_MORE_URL));
371 localized_strings.SetString("learnMore", 369 load_time_data.SetString("learnMore",
372 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); 370 l10n_util::GetStringUTF16(IDS_LEARN_MORE));
373 localized_strings.SetString("webStoreLink", 371 load_time_data.SetString("webStoreLink",
374 GetUrlWithLang(GURL(extension_urls::GetWebstoreLaunchURL()))); 372 GetUrlWithLang(GURL(extension_urls::GetWebstoreLaunchURL())));
375 localized_strings.SetBoolean("isWebStoreExperimentEnabled", 373 load_time_data.SetBoolean("isWebStoreExperimentEnabled",
376 NewTabUI::ShouldShowWebStoreFooterLink()); 374 NewTabUI::ShouldShowWebStoreFooterLink());
377 localized_strings.SetBoolean("appInstallHintEnabled", 375 load_time_data.SetBoolean("appInstallHintEnabled",
378 NewTabUI::ShouldShowAppInstallHint()); 376 NewTabUI::ShouldShowAppInstallHint());
379 localized_strings.SetString("appInstallHintText", 377 load_time_data.SetString("appInstallHintText",
380 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_INSTALL_HINT_LABEL)); 378 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_INSTALL_HINT_LABEL));
381 localized_strings.SetBoolean("isSuggestionsPageEnabled", 379 load_time_data.SetBoolean("isSuggestionsPageEnabled",
382 NewTabUI::IsSuggestionsPageEnabled()); 380 NewTabUI::IsSuggestionsPageEnabled());
383 localized_strings.SetBoolean("showApps", NewTabUI::ShouldShowApps()); 381 load_time_data.SetBoolean("showApps", NewTabUI::ShouldShowApps());
384 localized_strings.SetString("hideSessionMenuItemText", 382 load_time_data.SetString("hideSessionMenuItemText",
385 l10n_util::GetStringUTF16(IDS_POLICY_HIDE)); 383 l10n_util::GetStringUTF16(IDS_POLICY_HIDE));
384 load_time_data.SetString("learn_more",
385 l10n_util::GetStringUTF16(IDS_LEARN_MORE));
386 386
387 // On Mac OS X 10.7+, horizontal scrolling can be treated as a back or 387 // On Mac OS X 10.7+, horizontal scrolling can be treated as a back or
388 // forward gesture. Pass through a flag that indicates whether or not that 388 // forward gesture. Pass through a flag that indicates whether or not that
389 // feature is enabled. 389 // feature is enabled.
390 localized_strings.SetBoolean("isSwipeTrackingFromScrollEventsEnabled", 390 load_time_data.SetBoolean("isSwipeTrackingFromScrollEventsEnabled",
391 is_swipe_tracking_from_scroll_events_enabled_); 391 is_swipe_tracking_from_scroll_events_enabled_);
392 392
393 #if defined(OS_CHROMEOS) 393 #if defined(OS_CHROMEOS)
394 localized_strings.SetString("expandMenu", 394 load_time_data.SetString("expandMenu",
395 l10n_util::GetStringUTF16(IDS_NEW_TAB_CLOSE_MENU_EXPAND)); 395 l10n_util::GetStringUTF16(IDS_NEW_TAB_CLOSE_MENU_EXPAND));
396 #endif 396 #endif
397 397
398 NewTabPageHandler::GetLocalizedValues(profile_, &localized_strings); 398 NewTabPageHandler::GetLocalizedValues(profile_, &load_time_data);
399 NTPLoginHandler::GetLocalizedValues(profile_, &localized_strings); 399 NTPLoginHandler::GetLocalizedValues(profile_, &load_time_data);
400 400
401 // Don't initiate the sync related message passing with the page if the sync 401 ChromeURLDataManager::DataSource::SetFontAndTextDirection(&load_time_data);
402 // code is not present.
403 if (ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_))
404 localized_strings.SetString("syncispresent", "true");
405 else
406 localized_strings.SetString("syncispresent", "false");
407
408 ChromeURLDataManager::DataSource::SetFontAndTextDirection(&localized_strings);
409 402
410 // Control fade and resize animations. 403 // Control fade and resize animations.
411 std::string anim = 404 load_time_data.SetBoolean("anim", ui::Animation::ShouldRenderRichAnimation());
412 ui::Animation::ShouldRenderRichAnimation() ? "true" : "false";
413 localized_strings.SetString("anim", anim);
414 405
415 int alignment; 406 int alignment;
416 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); 407 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_);
417 tp->GetDisplayProperty(ThemeService::NTP_BACKGROUND_ALIGNMENT, &alignment); 408 tp->GetDisplayProperty(ThemeService::NTP_BACKGROUND_ALIGNMENT, &alignment);
418 localized_strings.SetString("themegravity", 409 load_time_data.SetString("themegravity",
419 (alignment & ThemeService::ALIGN_RIGHT) ? "right" : ""); 410 (alignment & ThemeService::ALIGN_RIGHT) ? "right" : "");
420 411
421 #if defined(ENABLE_PROMO_RESOURCE_SERVICE) 412 #if defined(ENABLE_PROMO_RESOURCE_SERVICE)
422 // If the user has preferences for a start and end time for a promo from 413 // If the user has preferences for a start and end time for a promo from
423 // the server, and this promo string exists, set the localized string. 414 // the server, and this promo string exists, set the localized string.
424 if (PromoResourceService::CanShowNotificationPromo(profile_)) { 415 if (PromoResourceService::CanShowNotificationPromo(profile_)) {
425 localized_strings.SetString("serverpromo", 416 load_time_data.SetString("serverpromo",
426 prefs->GetString(prefs::kNtpPromoLine)); 417 prefs->GetString(prefs::kNtpPromoLine));
427 } 418 }
428
429 // If the user has preferences for a start and end time for a custom logo,
430 // and the time now is between these two times, show the custom logo.
431 if (prefs->FindPreference(prefs::kNtpCustomLogoStart) &&
432 prefs->FindPreference(prefs::kNtpCustomLogoEnd)) {
433 localized_strings.SetString("customlogo",
434 InDateRange(prefs->GetDouble(prefs::kNtpCustomLogoStart),
435 prefs->GetDouble(prefs::kNtpCustomLogoEnd)) ?
436 "true" : "false");
437 } else {
438 localized_strings.SetString("customlogo", "false");
439 }
440 #else
441 localized_strings.SetString("customlogo", "false");
442 #endif 419 #endif
443 420
444 // Determine whether to show the menu for accessing tabs on other devices. 421 // Determine whether to show the menu for accessing tabs on other devices.
445 bool show_other_sessions_menu = !CommandLine::ForCurrentProcess()->HasSwitch( 422 bool show_other_sessions_menu = !CommandLine::ForCurrentProcess()->HasSwitch(
446 switches::kDisableNTPOtherSessionsMenu); 423 switches::kDisableNTPOtherSessionsMenu);
447 localized_strings.SetBoolean("showOtherSessionsMenu", 424 load_time_data.SetBoolean("showOtherSessionsMenu",
448 show_other_sessions_menu); 425 show_other_sessions_menu);
449 localized_strings.SetBoolean("isUserSignedIn", 426 load_time_data.SetBoolean("isUserSignedIn",
450 !prefs->GetString(prefs::kGoogleServicesUsername).empty()); 427 !prefs->GetString(prefs::kGoogleServicesUsername).empty());
451 428
452 // Load the new tab page appropriate for this build 429 // Load the new tab page appropriate for this build
453 std::string full_html;
454 base::StringPiece new_tab_html(ResourceBundle::GetSharedInstance(). 430 base::StringPiece new_tab_html(ResourceBundle::GetSharedInstance().
455 GetRawDataResource(IDR_NEW_TAB_4_HTML)); 431 GetRawDataResource(IDR_NEW_TAB_4_HTML));
456 full_html = jstemplate_builder::GetI18nTemplateHtml(new_tab_html, 432 jstemplate_builder::UseVersion2 version2;
457 &localized_strings); 433 std::string full_html =
434 jstemplate_builder::GetI18nTemplateHtml(new_tab_html, &load_time_data);
458 new_tab_html_ = base::RefCountedString::TakeString(&full_html); 435 new_tab_html_ = base::RefCountedString::TakeString(&full_html);
459 } 436 }
460 437
461 void NTPResourceCache::CreateNewTabIncognitoCSS() { 438 void NTPResourceCache::CreateNewTabIncognitoCSS() {
462 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); 439 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_);
463 DCHECK(tp); 440 DCHECK(tp);
464 441
465 // Get our theme colors 442 // Get our theme colors
466 SkColor color_background = 443 SkColor color_background =
467 GetThemeColor(tp, ThemeService::COLOR_NTP_BACKGROUND); 444 GetThemeColor(tp, ThemeService::COLOR_NTP_BACKGROUND);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 // Get our template. 554 // Get our template.
578 static const base::StringPiece new_tab_theme_css( 555 static const base::StringPiece new_tab_theme_css(
579 ResourceBundle::GetSharedInstance().GetRawDataResource( 556 ResourceBundle::GetSharedInstance().GetRawDataResource(
580 IDR_NEW_TAB_4_THEME_CSS)); 557 IDR_NEW_TAB_4_THEME_CSS));
581 558
582 // Create the string from our template and the replacements. 559 // Create the string from our template and the replacements.
583 std::string css_string; 560 std::string css_string;
584 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); 561 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL);
585 new_tab_css_ = base::RefCountedString::TakeString(&css_string); 562 new_tab_css_ = base::RefCountedString::TakeString(&css_string);
586 } 563 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/ntp_login_handler.cc ('k') | chrome/browser/ui/webui/ntp/ntp_resource_cache_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698