| OLD | NEW |
| 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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 incognito_tab_html, &localized_strings); | 282 incognito_tab_html, &localized_strings); |
| 283 | 283 |
| 284 new_tab_incognito_html_ = base::RefCountedString::TakeString(&full_html); | 284 new_tab_incognito_html_ = base::RefCountedString::TakeString(&full_html); |
| 285 } | 285 } |
| 286 | 286 |
| 287 void NTPResourceCache::CreateNewTabHTML() { | 287 void NTPResourceCache::CreateNewTabHTML() { |
| 288 // TODO(estade): these strings should be defined in their relevant handlers | 288 // TODO(estade): these strings should be defined in their relevant handlers |
| 289 // (in GetLocalizedValues) and should have more legible names. | 289 // (in GetLocalizedValues) and should have more legible names. |
| 290 // Show the profile name in the title and most visited labels if the current | 290 // Show the profile name in the title and most visited labels if the current |
| 291 // profile is not the default. | 291 // profile is not the default. |
| 292 PrefService* prefs = profile_->GetPrefs(); |
| 292 DictionaryValue localized_strings; | 293 DictionaryValue localized_strings; |
| 293 localized_strings.SetString("bookmarkbarattached", | 294 localized_strings.SetString("bookmarkbarattached", |
| 294 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) ? | 295 prefs->GetBoolean(prefs::kShowBookmarkBar) ? "true" : "false"); |
| 295 "true" : "false"); | |
| 296 localized_strings.SetString("hasattribution", | 296 localized_strings.SetString("hasattribution", |
| 297 ThemeServiceFactory::GetForProfile(profile_)->HasCustomImage( | 297 ThemeServiceFactory::GetForProfile(profile_)->HasCustomImage( |
| 298 IDR_THEME_NTP_ATTRIBUTION) ? | 298 IDR_THEME_NTP_ATTRIBUTION) ? |
| 299 "true" : "false"); | 299 "true" : "false"); |
| 300 localized_strings.SetString("title", | 300 localized_strings.SetString("title", |
| 301 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); | 301 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); |
| 302 localized_strings.SetString("mostvisited", | 302 localized_strings.SetString("mostvisited", |
| 303 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED)); | 303 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED)); |
| 304 localized_strings.SetString("suggestions", | 304 localized_strings.SetString("suggestions", |
| 305 l10n_util::GetStringUTF16(IDS_NEW_TAB_SUGGESTIONS)); | 305 l10n_util::GetStringUTF16(IDS_NEW_TAB_SUGGESTIONS)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 localized_strings.SetString("applaunchtypefullscreen", | 342 localized_strings.SetString("applaunchtypefullscreen", |
| 343 l10n_util::GetStringUTF16(IDS_APP_CONTEXT_MENU_OPEN_FULLSCREEN)); | 343 l10n_util::GetStringUTF16(IDS_APP_CONTEXT_MENU_OPEN_FULLSCREEN)); |
| 344 localized_strings.SetString("syncpromotext", | 344 localized_strings.SetString("syncpromotext", |
| 345 l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL)); | 345 l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL)); |
| 346 localized_strings.SetString("syncLinkText", | 346 localized_strings.SetString("syncLinkText", |
| 347 l10n_util::GetStringUTF16(IDS_SYNC_ADVANCED_OPTIONS)); | 347 l10n_util::GetStringUTF16(IDS_SYNC_ADVANCED_OPTIONS)); |
| 348 localized_strings.SetString("otherSessions", | 348 localized_strings.SetString("otherSessions", |
| 349 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_LABEL)); | 349 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_LABEL)); |
| 350 localized_strings.SetString("otherSessionsEmpty", | 350 localized_strings.SetString("otherSessionsEmpty", |
| 351 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_EMPTY)); | 351 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_EMPTY)); |
| 352 localized_strings.SetString("otherSessionsSignInText", |
| 353 l10n_util::GetStringFUTF16( |
| 354 IDS_SYNC_START_SYNC_BUTTON_LABEL, |
| 355 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); |
| 352 localized_strings.SetString("webStoreLink", | 356 localized_strings.SetString("webStoreLink", |
| 353 GetUrlWithLang(GURL(extension_urls::GetWebstoreLaunchURL()))); | 357 GetUrlWithLang(GURL(extension_urls::GetWebstoreLaunchURL()))); |
| 354 localized_strings.SetBoolean("isWebStoreExperimentEnabled", | 358 localized_strings.SetBoolean("isWebStoreExperimentEnabled", |
| 355 NewTabUI::ShouldShowWebStoreFooterLink()); | 359 NewTabUI::ShouldShowWebStoreFooterLink()); |
| 356 localized_strings.SetBoolean("appInstallHintEnabled", | 360 localized_strings.SetBoolean("appInstallHintEnabled", |
| 357 NewTabUI::ShouldShowAppInstallHint()); | 361 NewTabUI::ShouldShowAppInstallHint()); |
| 358 localized_strings.SetString("appInstallHintText", | 362 localized_strings.SetString("appInstallHintText", |
| 359 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_INSTALL_HINT_LABEL)); | 363 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_INSTALL_HINT_LABEL)); |
| 360 localized_strings.SetBoolean("isSuggestionsPageEnabled", | 364 localized_strings.SetBoolean("isSuggestionsPageEnabled", |
| 361 NewTabUI::IsSuggestionsPageEnabled()); | 365 NewTabUI::IsSuggestionsPageEnabled()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 384 localized_strings.SetString("anim", anim); | 388 localized_strings.SetString("anim", anim); |
| 385 | 389 |
| 386 int alignment; | 390 int alignment; |
| 387 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); | 391 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); |
| 388 tp->GetDisplayProperty(ThemeService::NTP_BACKGROUND_ALIGNMENT, &alignment); | 392 tp->GetDisplayProperty(ThemeService::NTP_BACKGROUND_ALIGNMENT, &alignment); |
| 389 localized_strings.SetString("themegravity", | 393 localized_strings.SetString("themegravity", |
| 390 (alignment & ThemeService::ALIGN_RIGHT) ? "right" : ""); | 394 (alignment & ThemeService::ALIGN_RIGHT) ? "right" : ""); |
| 391 | 395 |
| 392 // If the user has preferences for a start and end time for a custom logo, | 396 // If the user has preferences for a start and end time for a custom logo, |
| 393 // and the time now is between these two times, show the custom logo. | 397 // and the time now is between these two times, show the custom logo. |
| 394 if (profile_->GetPrefs()->FindPreference(prefs::kNtpCustomLogoStart) && | 398 if (prefs->FindPreference(prefs::kNtpCustomLogoStart) && |
| 395 profile_->GetPrefs()->FindPreference(prefs::kNtpCustomLogoEnd)) { | 399 prefs->FindPreference(prefs::kNtpCustomLogoEnd)) { |
| 396 localized_strings.SetString("customlogo", | 400 localized_strings.SetString("customlogo", |
| 397 InDateRange(profile_->GetPrefs()->GetDouble(prefs::kNtpCustomLogoStart), | 401 InDateRange(prefs->GetDouble(prefs::kNtpCustomLogoStart), |
| 398 profile_->GetPrefs()->GetDouble(prefs::kNtpCustomLogoEnd)) ? | 402 prefs->GetDouble(prefs::kNtpCustomLogoEnd)) ? |
| 399 "true" : "false"); | 403 "true" : "false"); |
| 400 } else { | 404 } else { |
| 401 localized_strings.SetString("customlogo", "false"); | 405 localized_strings.SetString("customlogo", "false"); |
| 402 } | 406 } |
| 403 | 407 |
| 404 // If the user has preferences for a start and end time for a promo from | 408 // If the user has preferences for a start and end time for a promo from |
| 405 // the server, and this promo string exists, set the localized string. | 409 // the server, and this promo string exists, set the localized string. |
| 406 if (PromoResourceService::CanShowNotificationPromo(profile_)) { | 410 if (PromoResourceService::CanShowNotificationPromo(profile_)) { |
| 407 localized_strings.SetString("serverpromo", | 411 localized_strings.SetString("serverpromo", |
| 408 profile_->GetPrefs()->GetString(prefs::kNtpPromoLine)); | 412 prefs->GetString(prefs::kNtpPromoLine)); |
| 409 } | 413 } |
| 410 | 414 |
| 411 // Determine whether to show the menu for accessing tabs on other devices. | 415 // Determine whether to show the menu for accessing tabs on other devices. |
| 412 bool show_other_sessions_menu = !CommandLine::ForCurrentProcess()->HasSwitch( | 416 bool show_other_sessions_menu = !CommandLine::ForCurrentProcess()->HasSwitch( |
| 413 switches::kDisableNTPOtherSessionsMenu); | 417 switches::kDisableNTPOtherSessionsMenu); |
| 414 localized_strings.SetBoolean("showOtherSessionsMenu", | 418 localized_strings.SetBoolean("showOtherSessionsMenu", |
| 415 show_other_sessions_menu); | 419 show_other_sessions_menu); |
| 420 localized_strings.SetBoolean("isUserSignedIn", |
| 421 !prefs->GetString(prefs::kGoogleServicesUsername).empty()); |
| 416 | 422 |
| 417 // Load the new tab page appropriate for this build | 423 // Load the new tab page appropriate for this build |
| 418 std::string full_html; | 424 std::string full_html; |
| 419 base::StringPiece new_tab_html(ResourceBundle::GetSharedInstance(). | 425 base::StringPiece new_tab_html(ResourceBundle::GetSharedInstance(). |
| 420 GetRawDataResource(IDR_NEW_TAB_4_HTML)); | 426 GetRawDataResource(IDR_NEW_TAB_4_HTML)); |
| 421 full_html = jstemplate_builder::GetI18nTemplateHtml(new_tab_html, | 427 full_html = jstemplate_builder::GetI18nTemplateHtml(new_tab_html, |
| 422 &localized_strings); | 428 &localized_strings); |
| 423 new_tab_html_ = base::RefCountedString::TakeString(&full_html); | 429 new_tab_html_ = base::RefCountedString::TakeString(&full_html); |
| 424 } | 430 } |
| 425 | 431 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 // Get our template. | 548 // Get our template. |
| 543 static const base::StringPiece new_tab_theme_css( | 549 static const base::StringPiece new_tab_theme_css( |
| 544 ResourceBundle::GetSharedInstance().GetRawDataResource( | 550 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 545 IDR_NEW_TAB_4_THEME_CSS)); | 551 IDR_NEW_TAB_4_THEME_CSS)); |
| 546 | 552 |
| 547 // Create the string from our template and the replacements. | 553 // Create the string from our template and the replacements. |
| 548 std::string css_string; | 554 std::string css_string; |
| 549 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); | 555 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); |
| 550 new_tab_css_ = base::RefCountedString::TakeString(&css_string); | 556 new_tab_css_ = base::RefCountedString::TakeString(&css_string); |
| 551 } | 557 } |
| OLD | NEW |