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" |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 void NTPResourceCache::Observe(int type, | 212 void NTPResourceCache::Observe(int type, |
213 const content::NotificationSource& source, | 213 const content::NotificationSource& source, |
214 const content::NotificationDetails& details) { | 214 const content::NotificationDetails& details) { |
215 // Invalidate the cache. | 215 // Invalidate the cache. |
216 if (chrome::NOTIFICATION_BROWSER_THEME_CHANGED == type || | 216 if (chrome::NOTIFICATION_BROWSER_THEME_CHANGED == type || |
217 chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED == type) { | 217 chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED == type) { |
218 new_tab_incognito_html_ = NULL; | 218 new_tab_incognito_html_ = NULL; |
219 new_tab_html_ = NULL; | 219 new_tab_html_ = NULL; |
220 new_tab_incognito_css_ = NULL; | 220 new_tab_incognito_css_ = NULL; |
221 new_tab_css_ = NULL; | 221 new_tab_css_ = NULL; |
222 } else if (chrome::NOTIFICATION_PREF_CHANGED == type) { | |
223 // A change occurred to one of the preferences we care about, so flush the | |
224 // cache. | |
225 new_tab_incognito_html_ = NULL; | |
226 new_tab_html_ = NULL; | |
227 new_tab_css_ = NULL; | |
228 } else if (chrome::NOTIFICATION_NTP_BACKGROUND_THEME_Y_POS_CHANGED == type) { | 222 } else if (chrome::NOTIFICATION_NTP_BACKGROUND_THEME_Y_POS_CHANGED == type) { |
229 css_background_y_pos_ = *(content::Details<int>(details).ptr()); | 223 css_background_y_pos_ = *(content::Details<int>(details).ptr()); |
230 if (new_tab_css_.get()) | 224 if (new_tab_css_.get()) |
231 UpdateNewTabCSSBackgroundPosition(); | 225 UpdateNewTabCSSBackgroundPosition(); |
232 } else { | 226 } else { |
233 NOTREACHED(); | 227 NOTREACHED(); |
234 } | 228 } |
235 } | 229 } |
236 | 230 |
| 231 void NTPResourceCache::OnPreferenceChanged(PrefServiceBase* service, |
| 232 const std::string& pref_name) { |
| 233 // A change occurred to one of the preferences we care about, so flush the |
| 234 // cache. |
| 235 new_tab_incognito_html_ = NULL; |
| 236 new_tab_html_ = NULL; |
| 237 new_tab_css_ = NULL; |
| 238 } |
| 239 |
237 void NTPResourceCache::CreateNewTabIncognitoHTML() { | 240 void NTPResourceCache::CreateNewTabIncognitoHTML() { |
238 DictionaryValue localized_strings; | 241 DictionaryValue localized_strings; |
239 localized_strings.SetString("title", | 242 localized_strings.SetString("title", |
240 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); | 243 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); |
241 int new_tab_message_ids = IDS_NEW_TAB_OTR_MESSAGE; | 244 int new_tab_message_ids = IDS_NEW_TAB_OTR_MESSAGE; |
242 int new_tab_html_idr = IDR_INCOGNITO_TAB_HTML; | 245 int new_tab_html_idr = IDR_INCOGNITO_TAB_HTML; |
243 const char* new_tab_link = kLearnMoreIncognitoUrl; | 246 const char* new_tab_link = kLearnMoreIncognitoUrl; |
244 // TODO(altimofeev): consider implementation without 'if def' usage. | 247 // TODO(altimofeev): consider implementation without 'if def' usage. |
245 #if defined(OS_CHROMEOS) | 248 #if defined(OS_CHROMEOS) |
246 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) { | 249 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) { |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 kCSSBackgroundPositionDelimiter, background_pos_start); | 635 kCSSBackgroundPositionDelimiter, background_pos_start); |
633 DCHECK(background_pos_end != std::string::npos); | 636 DCHECK(background_pos_end != std::string::npos); |
634 std::string new_background_pos = GetNewTabBackgroundCSS( | 637 std::string new_background_pos = GetNewTabBackgroundCSS( |
635 ThemeServiceFactory::GetForProfile(profile_), false); | 638 ThemeServiceFactory::GetForProfile(profile_), false); |
636 new_css_string.replace(background_pos_start, | 639 new_css_string.replace(background_pos_start, |
637 background_pos_end - background_pos_start, | 640 background_pos_end - background_pos_start, |
638 new_background_pos); | 641 new_background_pos); |
639 | 642 |
640 new_tab_css_ = base::RefCountedString::TakeString(&new_css_string); | 643 new_tab_css_ = base::RefCountedString::TakeString(&new_css_string); |
641 } | 644 } |
OLD | NEW |