| 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 <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
| 13 #include "base/string16.h" | 13 #include "base/string16.h" |
| 14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/extensions/app_launcher.h" |
| 19 #include "chrome/browser/first_run/first_run.h" | 20 #include "chrome/browser/first_run/first_run.h" |
| 20 #include "chrome/browser/google/google_util.h" | 21 #include "chrome/browser/google/google_util.h" |
| 21 #include "chrome/browser/policy/browser_policy_connector.h" | 22 #include "chrome/browser/policy/browser_policy_connector.h" |
| 22 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/sync/profile_sync_service.h" | 25 #include "chrome/browser/sync/profile_sync_service.h" |
| 25 #include "chrome/browser/sync/profile_sync_service_factory.h" | 26 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 26 #include "chrome/browser/themes/theme_service.h" | 27 #include "chrome/browser/themes/theme_service.h" |
| 27 #include "chrome/browser/themes/theme_service_factory.h" | 28 #include "chrome/browser/themes/theme_service_factory.h" |
| 28 #include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h" | 29 #include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 186 |
| 186 bool NTPResourceCache::NewTabCacheNeedsRefresh() { | 187 bool NTPResourceCache::NewTabCacheNeedsRefresh() { |
| 187 #if defined(OS_MACOSX) | 188 #if defined(OS_MACOSX) |
| 188 // Invalidate if the current value is different from the cached value. | 189 // Invalidate if the current value is different from the cached value. |
| 189 bool is_enabled = platform_util::IsSwipeTrackingFromScrollEventsEnabled(); | 190 bool is_enabled = platform_util::IsSwipeTrackingFromScrollEventsEnabled(); |
| 190 if (is_enabled != is_swipe_tracking_from_scroll_events_enabled_) { | 191 if (is_enabled != is_swipe_tracking_from_scroll_events_enabled_) { |
| 191 is_swipe_tracking_from_scroll_events_enabled_ = is_enabled; | 192 is_swipe_tracking_from_scroll_events_enabled_ = is_enabled; |
| 192 return true; | 193 return true; |
| 193 } | 194 } |
| 194 #endif | 195 #endif |
| 196 bool should_show_apps_page = !extensions::IsAppLauncherEnabled(); |
| 197 if (should_show_apps_page != should_show_apps_page_) { |
| 198 should_show_apps_page_ = should_show_apps_page; |
| 199 return true; |
| 200 } |
| 195 return false; | 201 return false; |
| 196 } | 202 } |
| 197 | 203 |
| 198 base::RefCountedMemory* NTPResourceCache::GetNewTabHTML(bool is_incognito) { | 204 base::RefCountedMemory* NTPResourceCache::GetNewTabHTML(bool is_incognito) { |
| 199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 200 if (is_incognito) { | 206 if (is_incognito) { |
| 201 if (!new_tab_incognito_html_.get()) | 207 if (!new_tab_incognito_html_.get()) |
| 202 CreateNewTabIncognitoHTML(); | 208 CreateNewTabIncognitoHTML(); |
| 203 } else { | 209 } else { |
| 204 // Refresh the cached HTML if necessary. | 210 // Refresh the cached HTML if necessary. |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 load_time_data.SetString("otherSessionsLearnMoreUrl", | 378 load_time_data.SetString("otherSessionsLearnMoreUrl", |
| 373 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_LEARN_MORE_URL)); | 379 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_LEARN_MORE_URL)); |
| 374 load_time_data.SetString("learnMore", | 380 load_time_data.SetString("learnMore", |
| 375 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); | 381 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); |
| 376 load_time_data.SetString("webStoreLink", | 382 load_time_data.SetString("webStoreLink", |
| 377 GetUrlWithLang(GURL(extension_urls::GetWebstoreLaunchURL()))); | 383 GetUrlWithLang(GURL(extension_urls::GetWebstoreLaunchURL()))); |
| 378 load_time_data.SetString("appInstallHintText", | 384 load_time_data.SetString("appInstallHintText", |
| 379 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_INSTALL_HINT_LABEL)); | 385 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_INSTALL_HINT_LABEL)); |
| 380 load_time_data.SetBoolean("isDiscoveryInNTPEnabled", | 386 load_time_data.SetBoolean("isDiscoveryInNTPEnabled", |
| 381 NewTabUI::IsDiscoveryInNTPEnabled()); | 387 NewTabUI::IsDiscoveryInNTPEnabled()); |
| 382 load_time_data.SetBoolean("showApps", NewTabUI::ShouldShowApps()); | |
| 383 load_time_data.SetString("collapseSessionMenuItemText", | 388 load_time_data.SetString("collapseSessionMenuItemText", |
| 384 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_COLLAPSE_SESSION)); | 389 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_COLLAPSE_SESSION)); |
| 385 load_time_data.SetString("expandSessionMenuItemText", | 390 load_time_data.SetString("expandSessionMenuItemText", |
| 386 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_EXPAND_SESSION)); | 391 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_EXPAND_SESSION)); |
| 387 load_time_data.SetString("restoreSessionMenuItemText", | 392 load_time_data.SetString("restoreSessionMenuItemText", |
| 388 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_OPEN_ALL)); | 393 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_OPEN_ALL)); |
| 389 load_time_data.SetString("learn_more", | 394 load_time_data.SetString("learn_more", |
| 390 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); | 395 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); |
| 391 load_time_data.SetString("tile_grid_screenreader_accessible_description", | 396 load_time_data.SetString("tile_grid_screenreader_accessible_description", |
| 392 l10n_util::GetStringUTF16(IDS_NEW_TAB_TILE_GRID_ACCESSIBLE_DESCRIPTION)); | 397 l10n_util::GetStringUTF16(IDS_NEW_TAB_TILE_GRID_ACCESSIBLE_DESCRIPTION)); |
| 393 load_time_data.SetString("page_switcher_change_title", | 398 load_time_data.SetString("page_switcher_change_title", |
| 394 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_SWITCHER_CHANGE_TITLE)); | 399 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_SWITCHER_CHANGE_TITLE)); |
| 395 load_time_data.SetString("page_switcher_same_title", | 400 load_time_data.SetString("page_switcher_same_title", |
| 396 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_SWITCHER_SAME_TITLE)); | 401 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_SWITCHER_SAME_TITLE)); |
| 397 // On Mac OS X 10.7+, horizontal scrolling can be treated as a back or | 402 // On Mac OS X 10.7+, horizontal scrolling can be treated as a back or |
| 398 // forward gesture. Pass through a flag that indicates whether or not that | 403 // forward gesture. Pass through a flag that indicates whether or not that |
| 399 // feature is enabled. | 404 // feature is enabled. |
| 400 load_time_data.SetBoolean("isSwipeTrackingFromScrollEventsEnabled", | 405 load_time_data.SetBoolean("isSwipeTrackingFromScrollEventsEnabled", |
| 401 is_swipe_tracking_from_scroll_events_enabled_); | 406 is_swipe_tracking_from_scroll_events_enabled_); |
| 407 load_time_data.SetBoolean("showApps", should_show_apps_page_); |
| 402 | 408 |
| 403 #if defined(OS_CHROMEOS) | 409 #if defined(OS_CHROMEOS) |
| 404 load_time_data.SetString("expandMenu", | 410 load_time_data.SetString("expandMenu", |
| 405 l10n_util::GetStringUTF16(IDS_NEW_TAB_CLOSE_MENU_EXPAND)); | 411 l10n_util::GetStringUTF16(IDS_NEW_TAB_CLOSE_MENU_EXPAND)); |
| 406 #endif | 412 #endif |
| 407 | 413 |
| 408 NewTabPageHandler::GetLocalizedValues(profile_, &load_time_data); | 414 NewTabPageHandler::GetLocalizedValues(profile_, &load_time_data); |
| 409 NTPLoginHandler::GetLocalizedValues(profile_, &load_time_data); | 415 NTPLoginHandler::GetLocalizedValues(profile_, &load_time_data); |
| 410 | 416 |
| 411 web_ui_util::SetFontAndTextDirection(&load_time_data); | 417 web_ui_util::SetFontAndTextDirection(&load_time_data); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 static const base::StringPiece new_tab_theme_css( | 585 static const base::StringPiece new_tab_theme_css( |
| 580 ResourceBundle::GetSharedInstance().GetRawDataResource( | 586 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 581 chrome::search::IsInstantExtendedAPIEnabled(profile_) ? | 587 chrome::search::IsInstantExtendedAPIEnabled(profile_) ? |
| 582 IDR_NEW_TAB_SEARCH_THEME_CSS : IDR_NEW_TAB_4_THEME_CSS)); | 588 IDR_NEW_TAB_SEARCH_THEME_CSS : IDR_NEW_TAB_4_THEME_CSS)); |
| 583 | 589 |
| 584 // Create the string from our template and the replacements. | 590 // Create the string from our template and the replacements. |
| 585 std::string css_string; | 591 std::string css_string; |
| 586 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); | 592 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); |
| 587 new_tab_css_ = base::RefCountedString::TakeString(&css_string); | 593 new_tab_css_ = base::RefCountedString::TakeString(&css_string); |
| 588 } | 594 } |
| OLD | NEW |