Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 } // namespace | 169 } // namespace |
| 170 | 170 |
| 171 NTPResourceCache::NTPResourceCache(Profile* profile) : profile_(profile) { | 171 NTPResourceCache::NTPResourceCache(Profile* profile) : profile_(profile) { |
| 172 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 172 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 173 content::Source<ThemeService>( | 173 content::Source<ThemeService>( |
| 174 ThemeServiceFactory::GetForProfile(profile))); | 174 ThemeServiceFactory::GetForProfile(profile))); |
| 175 registrar_.Add(this, chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, | 175 registrar_.Add(this, chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, |
| 176 content::NotificationService::AllSources()); | 176 content::NotificationService::AllSources()); |
| 177 registrar_.Add(this, chrome::NTP4_INTRO_PREF_CHANGED, | 177 registrar_.Add(this, chrome::NTP4_INTRO_PREF_CHANGED, |
| 178 content::NotificationService::AllSources()); | 178 content::NotificationService::AllSources()); |
| 179 registrar_.Add(this, chrome::NTP4_SYNC_PROMO_SHOW_NTP_BUBBLE_CHANGED, | |
| 180 content::NotificationService::AllSources()); | |
| 179 | 181 |
| 180 // Watch for pref changes that cause us to need to invalidate the HTML cache. | 182 // Watch for pref changes that cause us to need to invalidate the HTML cache. |
| 181 pref_change_registrar_.Init(profile_->GetPrefs()); | 183 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 182 pref_change_registrar_.Add(prefs::kSyncAcknowledgedSyncTypes, this); | 184 pref_change_registrar_.Add(prefs::kSyncAcknowledgedSyncTypes, this); |
| 183 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); | 185 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); |
| 184 pref_change_registrar_.Add(prefs::kHomePageIsNewTabPage, this); | 186 pref_change_registrar_.Add(prefs::kHomePageIsNewTabPage, this); |
| 185 pref_change_registrar_.Add(prefs::kNTPShownPage, this); | 187 pref_change_registrar_.Add(prefs::kNTPShownPage, this); |
|
Evan Stade
2011/11/30 03:38:03
doesn't work to just add kSyncPromoShowNTPBubble h
sail
2011/11/30 05:50:08
Done.
Ahh, that works great!
| |
| 186 } | 188 } |
| 187 | 189 |
| 188 NTPResourceCache::~NTPResourceCache() {} | 190 NTPResourceCache::~NTPResourceCache() {} |
| 189 | 191 |
| 190 RefCountedMemory* NTPResourceCache::GetNewTabHTML(bool is_incognito) { | 192 RefCountedMemory* NTPResourceCache::GetNewTabHTML(bool is_incognito) { |
| 191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 192 if (is_incognito) { | 194 if (is_incognito) { |
| 193 if (!new_tab_incognito_html_.get()) | 195 if (!new_tab_incognito_html_.get()) |
| 194 CreateNewTabIncognitoHTML(); | 196 CreateNewTabIncognitoHTML(); |
| 195 } else { | 197 } else { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 210 CreateNewTabCSS(); | 212 CreateNewTabCSS(); |
| 211 } | 213 } |
| 212 return is_incognito ? new_tab_incognito_css_.get() | 214 return is_incognito ? new_tab_incognito_css_.get() |
| 213 : new_tab_css_.get(); | 215 : new_tab_css_.get(); |
| 214 } | 216 } |
| 215 | 217 |
| 216 void NTPResourceCache::Observe(int type, | 218 void NTPResourceCache::Observe(int type, |
| 217 const content::NotificationSource& source, | 219 const content::NotificationSource& source, |
| 218 const content::NotificationDetails& details) { | 220 const content::NotificationDetails& details) { |
| 219 // Invalidate the cache. | 221 // Invalidate the cache. |
| 220 if (chrome::NOTIFICATION_BROWSER_THEME_CHANGED == type || | 222 switch (type) { |
| 221 chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED == type) { | 223 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: |
| 222 new_tab_incognito_html_ = NULL; | 224 case chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED: |
| 223 new_tab_html_ = NULL; | 225 new_tab_incognito_html_ = NULL; |
| 224 new_tab_incognito_css_ = NULL; | 226 new_tab_html_ = NULL; |
| 225 new_tab_css_ = NULL; | 227 new_tab_incognito_css_ = NULL; |
| 226 } else if (chrome::NOTIFICATION_PREF_CHANGED == type || | 228 new_tab_css_ = NULL; |
| 227 chrome::NTP4_INTRO_PREF_CHANGED) { | 229 break; |
| 228 // A change occurred to one of the preferences we care about, so flush the | 230 case chrome::NOTIFICATION_PREF_CHANGED: |
| 229 // cache. | 231 case chrome::NTP4_INTRO_PREF_CHANGED: |
| 230 new_tab_incognito_html_ = NULL; | 232 case chrome::NTP4_SYNC_PROMO_SHOW_NTP_BUBBLE_CHANGED: |
| 231 new_tab_html_ = NULL; | 233 // A change occurred to one of the preferences we care about, so flush the |
| 232 } else { | 234 // cache. |
| 233 NOTREACHED(); | 235 new_tab_incognito_html_ = NULL; |
| 236 new_tab_html_ = NULL; | |
| 237 break; | |
| 238 default: | |
| 239 NOTREACHED(); | |
| 240 break; | |
| 234 } | 241 } |
| 235 } | 242 } |
| 236 | 243 |
| 237 void NTPResourceCache::CreateNewTabIncognitoHTML() { | 244 void NTPResourceCache::CreateNewTabIncognitoHTML() { |
| 238 DictionaryValue localized_strings; | 245 DictionaryValue localized_strings; |
| 239 localized_strings.SetString("title", | 246 localized_strings.SetString("title", |
| 240 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); | 247 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); |
| 241 int new_tab_message_ids = IDS_NEW_TAB_OTR_MESSAGE; | 248 int new_tab_message_ids = IDS_NEW_TAB_OTR_MESSAGE; |
| 242 int new_tab_html_idr = IDR_INCOGNITO_TAB_HTML; | 249 int new_tab_html_idr = IDR_INCOGNITO_TAB_HTML; |
| 243 const char* new_tab_link = kLearnMoreIncognitoUrl; | 250 const char* new_tab_link = kLearnMoreIncognitoUrl; |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 583 IDR_NEW_TAB_4_THEME_CSS : IDR_NEW_TAB_THEME_CSS; | 590 IDR_NEW_TAB_4_THEME_CSS : IDR_NEW_TAB_THEME_CSS; |
| 584 static const base::StringPiece new_tab_theme_css( | 591 static const base::StringPiece new_tab_theme_css( |
| 585 ResourceBundle::GetSharedInstance().GetRawDataResource( | 592 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 586 ntp_css_resource_id)); | 593 ntp_css_resource_id)); |
| 587 | 594 |
| 588 // Create the string from our template and the replacements. | 595 // Create the string from our template and the replacements. |
| 589 std::string css_string; | 596 std::string css_string; |
| 590 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); | 597 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); |
| 591 new_tab_css_ = base::RefCountedString::TakeString(&css_string); | 598 new_tab_css_ = base::RefCountedString::TakeString(&css_string); |
| 592 } | 599 } |
| OLD | NEW |