| 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 base::Unretained(this)); | 175 base::Unretained(this)); |
| 176 | 176 |
| 177 // Watch for pref changes that cause us to need to invalidate the HTML cache. | 177 // Watch for pref changes that cause us to need to invalidate the HTML cache. |
| 178 profile_pref_change_registrar_.Init(profile_->GetPrefs()); | 178 profile_pref_change_registrar_.Init(profile_->GetPrefs()); |
| 179 profile_pref_change_registrar_.Add(bookmarks::prefs::kShowBookmarkBar, | 179 profile_pref_change_registrar_.Add(bookmarks::prefs::kShowBookmarkBar, |
| 180 callback); | 180 callback); |
| 181 profile_pref_change_registrar_.Add(prefs::kNtpShownPage, callback); | 181 profile_pref_change_registrar_.Add(prefs::kNtpShownPage, callback); |
| 182 profile_pref_change_registrar_.Add(prefs::kSignInPromoShowNTPBubble, | 182 profile_pref_change_registrar_.Add(prefs::kSignInPromoShowNTPBubble, |
| 183 callback); | 183 callback); |
| 184 profile_pref_change_registrar_.Add(prefs::kHideWebStoreIcon, callback); | 184 profile_pref_change_registrar_.Add(prefs::kHideWebStoreIcon, callback); |
| 185 | |
| 186 // Some tests don't have a local state. | |
| 187 #if defined(ENABLE_APP_LIST) | |
| 188 if (g_browser_process->local_state()) { | |
| 189 local_state_pref_change_registrar_.Init(g_browser_process->local_state()); | |
| 190 local_state_pref_change_registrar_.Add(prefs::kShowAppLauncherPromo, | |
| 191 callback); | |
| 192 local_state_pref_change_registrar_.Add( | |
| 193 prefs::kAppLauncherHasBeenEnabled, callback); | |
| 194 } | |
| 195 #endif | |
| 196 } | 185 } |
| 197 | 186 |
| 198 NTPResourceCache::~NTPResourceCache() {} | 187 NTPResourceCache::~NTPResourceCache() {} |
| 199 | 188 |
| 200 bool NTPResourceCache::NewTabCacheNeedsRefresh() { | 189 bool NTPResourceCache::NewTabCacheNeedsRefresh() { |
| 201 #if defined(OS_MACOSX) | 190 #if defined(OS_MACOSX) |
| 202 // Invalidate if the current value is different from the cached value. | 191 // Invalidate if the current value is different from the cached value. |
| 203 bool is_enabled = platform_util::IsSwipeTrackingFromScrollEventsEnabled(); | 192 bool is_enabled = platform_util::IsSwipeTrackingFromScrollEventsEnabled(); |
| 204 if (is_enabled != is_swipe_tracking_from_scroll_events_enabled_) { | 193 if (is_enabled != is_swipe_tracking_from_scroll_events_enabled_) { |
| 205 is_swipe_tracking_from_scroll_events_enabled_ = is_enabled; | 194 is_swipe_tracking_from_scroll_events_enabled_ = is_enabled; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 | 388 |
| 400 void NTPResourceCache::CreateNewTabHTML() { | 389 void NTPResourceCache::CreateNewTabHTML() { |
| 401 // TODO(estade): these strings should be defined in their relevant handlers | 390 // TODO(estade): these strings should be defined in their relevant handlers |
| 402 // (in GetLocalizedValues) and should have more legible names. | 391 // (in GetLocalizedValues) and should have more legible names. |
| 403 // Show the profile name in the title and most visited labels if the current | 392 // Show the profile name in the title and most visited labels if the current |
| 404 // profile is not the default. | 393 // profile is not the default. |
| 405 PrefService* prefs = profile_->GetPrefs(); | 394 PrefService* prefs = profile_->GetPrefs(); |
| 406 base::DictionaryValue load_time_data; | 395 base::DictionaryValue load_time_data; |
| 407 load_time_data.SetBoolean("bookmarkbarattached", | 396 load_time_data.SetBoolean("bookmarkbarattached", |
| 408 prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar)); | 397 prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar)); |
| 409 load_time_data.SetBoolean("showAppLauncherPromo", | |
| 410 ShouldShowAppLauncherPromo()); | |
| 411 load_time_data.SetString("title", | 398 load_time_data.SetString("title", |
| 412 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); | 399 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); |
| 413 load_time_data.SetString("webStoreTitle", | 400 load_time_data.SetString("webStoreTitle", |
| 414 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE)); | 401 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE)); |
| 415 load_time_data.SetString("webStoreTitleShort", | 402 load_time_data.SetString("webStoreTitleShort", |
| 416 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE_SHORT)); | 403 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE_SHORT)); |
| 417 load_time_data.SetString("attributionintro", | 404 load_time_data.SetString("attributionintro", |
| 418 l10n_util::GetStringUTF16(IDS_NEW_TAB_ATTRIBUTION_INTRO)); | 405 l10n_util::GetStringUTF16(IDS_NEW_TAB_ATTRIBUTION_INTRO)); |
| 419 load_time_data.SetString("appuninstall", | 406 load_time_data.SetString("appuninstall", |
| 420 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); | 407 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 451 load_time_data.SetString("appInstallHintText", | 438 load_time_data.SetString("appInstallHintText", |
| 452 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_INSTALL_HINT_LABEL)); | 439 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_INSTALL_HINT_LABEL)); |
| 453 load_time_data.SetString("learn_more", | 440 load_time_data.SetString("learn_more", |
| 454 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); | 441 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); |
| 455 load_time_data.SetString("tile_grid_screenreader_accessible_description", | 442 load_time_data.SetString("tile_grid_screenreader_accessible_description", |
| 456 l10n_util::GetStringUTF16(IDS_NEW_TAB_TILE_GRID_ACCESSIBLE_DESCRIPTION)); | 443 l10n_util::GetStringUTF16(IDS_NEW_TAB_TILE_GRID_ACCESSIBLE_DESCRIPTION)); |
| 457 load_time_data.SetString("page_switcher_change_title", | 444 load_time_data.SetString("page_switcher_change_title", |
| 458 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_SWITCHER_CHANGE_TITLE)); | 445 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_SWITCHER_CHANGE_TITLE)); |
| 459 load_time_data.SetString("page_switcher_same_title", | 446 load_time_data.SetString("page_switcher_same_title", |
| 460 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_SWITCHER_SAME_TITLE)); | 447 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_SWITCHER_SAME_TITLE)); |
| 461 load_time_data.SetString("appsPromoTitle", | |
| 462 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_APPS_PROMO_TITLE)); | |
| 463 // On Mac OS X 10.7+, horizontal scrolling can be treated as a back or | 448 // On Mac OS X 10.7+, horizontal scrolling can be treated as a back or |
| 464 // forward gesture. Pass through a flag that indicates whether or not that | 449 // forward gesture. Pass through a flag that indicates whether or not that |
| 465 // feature is enabled. | 450 // feature is enabled. |
| 466 load_time_data.SetBoolean("isSwipeTrackingFromScrollEventsEnabled", | 451 load_time_data.SetBoolean("isSwipeTrackingFromScrollEventsEnabled", |
| 467 is_swipe_tracking_from_scroll_events_enabled_); | 452 is_swipe_tracking_from_scroll_events_enabled_); |
| 468 | 453 |
| 469 load_time_data.SetBoolean("showApps", should_show_apps_page_); | 454 load_time_data.SetBoolean("showApps", should_show_apps_page_); |
| 470 load_time_data.SetBoolean("showWebStoreIcon", | 455 load_time_data.SetBoolean("showWebStoreIcon", |
| 471 !prefs->GetBoolean(prefs::kHideWebStoreIcon)); | 456 !prefs->GetBoolean(prefs::kHideWebStoreIcon)); |
| 472 | 457 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 // Get our template. | 589 // Get our template. |
| 605 static const base::StringPiece new_tab_theme_css( | 590 static const base::StringPiece new_tab_theme_css( |
| 606 ResourceBundle::GetSharedInstance().GetRawDataResource( | 591 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 607 IDR_NEW_TAB_4_THEME_CSS)); | 592 IDR_NEW_TAB_4_THEME_CSS)); |
| 608 | 593 |
| 609 // Create the string from our template and the replacements. | 594 // Create the string from our template and the replacements. |
| 610 std::string css_string = | 595 std::string css_string = |
| 611 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); | 596 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); |
| 612 new_tab_css_ = base::RefCountedString::TakeString(&css_string); | 597 new_tab_css_ = base::RefCountedString::TakeString(&css_string); |
| 613 } | 598 } |
| OLD | NEW |