Chromium Code Reviews| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 #include "ui/gfx/sys_color_change_listener.h" | 51 #include "ui/gfx/sys_color_change_listener.h" |
| 52 | 52 |
| 53 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS) | 53 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS) |
| 54 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" | 54 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" |
| 55 #elif defined(OS_MACOSX) | 55 #elif defined(OS_MACOSX) |
| 56 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" | 56 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" |
| 57 #elif defined(TOOLKIT_GTK) | 57 #elif defined(TOOLKIT_GTK) |
| 58 #include "chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.h" | 58 #include "chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.h" |
| 59 #endif | 59 #endif |
| 60 | 60 |
| 61 #if defined(OS_MACOSX) | |
| 62 #include "chrome/browser/platform_util.h" | |
| 63 #endif | |
| 64 | |
| 61 using base::Time; | 65 using base::Time; |
| 62 using content::BrowserThread; | 66 using content::BrowserThread; |
| 63 | 67 |
| 64 namespace { | 68 namespace { |
| 65 | 69 |
| 66 // The URL for the the Learn More page shown on incognito new tab. | 70 // The URL for the the Learn More page shown on incognito new tab. |
| 67 const char kLearnMoreIncognitoUrl[] = | 71 const char kLearnMoreIncognitoUrl[] = |
| 68 #if defined(OS_CHROMEOS) | 72 #if defined(OS_CHROMEOS) |
| 69 "https://www.google.com/support/chromeos/bin/answer.py?answer=95464"; | 73 "https://www.google.com/support/chromeos/bin/answer.py?answer=95464"; |
| 70 #else | 74 #else |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 // Watch for pref changes that cause us to need to invalidate the HTML cache. | 192 // Watch for pref changes that cause us to need to invalidate the HTML cache. |
| 189 pref_change_registrar_.Init(profile_->GetPrefs()); | 193 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 190 pref_change_registrar_.Add(prefs::kSyncAcknowledgedSyncTypes, this); | 194 pref_change_registrar_.Add(prefs::kSyncAcknowledgedSyncTypes, this); |
| 191 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); | 195 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); |
| 192 pref_change_registrar_.Add(prefs::kNtpShownPage, this); | 196 pref_change_registrar_.Add(prefs::kNtpShownPage, this); |
| 193 pref_change_registrar_.Add(prefs::kSyncPromoShowNTPBubble, this); | 197 pref_change_registrar_.Add(prefs::kSyncPromoShowNTPBubble, this); |
| 194 } | 198 } |
| 195 | 199 |
| 196 NTPResourceCache::~NTPResourceCache() {} | 200 NTPResourceCache::~NTPResourceCache() {} |
| 197 | 201 |
| 202 bool NTPResourceCache::NewTabCacheNeedsRefresh() { | |
| 203 #if defined(OS_MACOSX) | |
| 204 // Invalidate if the current value is different from the cached value. | |
| 205 bool is_enabled = platform_util::IsSwipeTrackingFromScrollEventsEnabled(); | |
| 206 if (is_enabled != is_swipe_tracking_from_scroll_events_enabled_) { | |
| 207 is_swipe_tracking_from_scroll_events_enabled_ = is_enabled; | |
| 208 return true; | |
| 209 } | |
| 210 #endif | |
| 211 return false; | |
| 212 } | |
| 213 | |
| 198 RefCountedMemory* NTPResourceCache::GetNewTabHTML(bool is_incognito) { | 214 RefCountedMemory* NTPResourceCache::GetNewTabHTML(bool is_incognito) { |
| 199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 200 if (is_incognito) { | 216 if (is_incognito) { |
| 201 if (!new_tab_incognito_html_.get()) | 217 if (!new_tab_incognito_html_.get()) |
| 202 CreateNewTabIncognitoHTML(); | 218 CreateNewTabIncognitoHTML(); |
| 203 } else { | 219 } else { |
| 204 if (!new_tab_html_.get()) | 220 // Refresh the cached HTML if necessary. |
| 221 // NOTE: NewTabCacheNeedsRefresh() must be called every time the new tab | |
| 222 // HTML is fetched, because it needs to initialized cached values. | |
|
Evan Stade
2012/04/18 21:16:35
grammar
Patrick Dubroy
2012/04/19 10:53:50
Done.
| |
| 223 if (NewTabCacheNeedsRefresh() || !new_tab_html_.get()) | |
| 205 CreateNewTabHTML(); | 224 CreateNewTabHTML(); |
| 206 } | 225 } |
| 207 return is_incognito ? new_tab_incognito_html_.get() : | 226 return is_incognito ? new_tab_incognito_html_.get() : |
| 208 new_tab_html_.get(); | 227 new_tab_html_.get(); |
| 209 } | 228 } |
| 210 | 229 |
| 211 RefCountedMemory* NTPResourceCache::GetNewTabCSS(bool is_incognito) { | 230 RefCountedMemory* NTPResourceCache::GetNewTabCSS(bool is_incognito) { |
| 212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 213 if (is_incognito) { | 232 if (is_incognito) { |
| 214 if (!new_tab_incognito_css_.get()) | 233 if (!new_tab_incognito_css_.get()) |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 localized_strings.SetBoolean("appInstallHintEnabled", | 377 localized_strings.SetBoolean("appInstallHintEnabled", |
| 359 NewTabUI::ShouldShowAppInstallHint()); | 378 NewTabUI::ShouldShowAppInstallHint()); |
| 360 localized_strings.SetString("appInstallHintText", | 379 localized_strings.SetString("appInstallHintText", |
| 361 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_INSTALL_HINT_LABEL)); | 380 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_INSTALL_HINT_LABEL)); |
| 362 localized_strings.SetBoolean("isSuggestionsPageEnabled", | 381 localized_strings.SetBoolean("isSuggestionsPageEnabled", |
| 363 NewTabUI::IsSuggestionsPageEnabled()); | 382 NewTabUI::IsSuggestionsPageEnabled()); |
| 364 localized_strings.SetBoolean("showApps", NewTabUI::ShouldShowApps()); | 383 localized_strings.SetBoolean("showApps", NewTabUI::ShouldShowApps()); |
| 365 localized_strings.SetString("hideSessionMenuItemText", | 384 localized_strings.SetString("hideSessionMenuItemText", |
| 366 l10n_util::GetStringUTF16(IDS_POLICY_HIDE)); | 385 l10n_util::GetStringUTF16(IDS_POLICY_HIDE)); |
| 367 | 386 |
| 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 | |
| 389 // feature is enabled. | |
| 390 localized_strings.SetBoolean("isSwipeTrackingFromScrollEventsEnabled", | |
| 391 is_swipe_tracking_from_scroll_events_enabled_); | |
| 392 | |
| 368 #if defined(OS_CHROMEOS) | 393 #if defined(OS_CHROMEOS) |
| 369 localized_strings.SetString("expandMenu", | 394 localized_strings.SetString("expandMenu", |
| 370 l10n_util::GetStringUTF16(IDS_NEW_TAB_CLOSE_MENU_EXPAND)); | 395 l10n_util::GetStringUTF16(IDS_NEW_TAB_CLOSE_MENU_EXPAND)); |
| 371 #endif | 396 #endif |
| 372 | 397 |
| 373 NewTabPageHandler::GetLocalizedValues(profile_, &localized_strings); | 398 NewTabPageHandler::GetLocalizedValues(profile_, &localized_strings); |
| 374 NTPLoginHandler::GetLocalizedValues(profile_, &localized_strings); | 399 NTPLoginHandler::GetLocalizedValues(profile_, &localized_strings); |
| 375 | 400 |
| 376 // Don't initiate the sync related message passing with the page if the sync | 401 // Don't initiate the sync related message passing with the page if the sync |
| 377 // code is not present. | 402 // code is not present. |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 // Get our template. | 577 // Get our template. |
| 553 static const base::StringPiece new_tab_theme_css( | 578 static const base::StringPiece new_tab_theme_css( |
| 554 ResourceBundle::GetSharedInstance().GetRawDataResource( | 579 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 555 IDR_NEW_TAB_4_THEME_CSS)); | 580 IDR_NEW_TAB_4_THEME_CSS)); |
| 556 | 581 |
| 557 // Create the string from our template and the replacements. | 582 // Create the string from our template and the replacements. |
| 558 std::string css_string; | 583 std::string css_string; |
| 559 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); | 584 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); |
| 560 new_tab_css_ = base::RefCountedString::TakeString(&css_string); | 585 new_tab_css_ = base::RefCountedString::TakeString(&css_string); |
| 561 } | 586 } |
| OLD | NEW |