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