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 <algorithm> | 7 #include <algorithm> |
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/stringprintf.h" | 14 #include "base/stringprintf.h" |
15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
16 #include "base/time.h" | 16 #include "base/time.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chrome/browser/defaults.h" | 19 #include "chrome/browser/defaults.h" |
20 #include "chrome/browser/google/google_util.h" | 20 #include "chrome/browser/google/google_util.h" |
21 #include "chrome/browser/prefs/pref_service.h" | 21 #include "chrome/browser/prefs/pref_service.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/themes/theme_service.h" | 23 #include "chrome/browser/themes/theme_service.h" |
24 #include "chrome/browser/themes/theme_service_factory.h" | 24 #include "chrome/browser/themes/theme_service_factory.h" |
25 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 25 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
26 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h" | 26 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h" |
27 #include "chrome/browser/web_resource/promo_resource_service.h" | 27 #include "chrome/browser/web_resource/promo_resource_service.h" |
| 28 #include "chrome/common/chrome_notification_types.h" |
28 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
29 #include "chrome/common/extensions/extension.h" | 30 #include "chrome/common/extensions/extension.h" |
30 #include "chrome/common/extensions/extension_constants.h" | 31 #include "chrome/common/extensions/extension_constants.h" |
31 #include "chrome/common/jstemplate_builder.h" | 32 #include "chrome/common/jstemplate_builder.h" |
32 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
33 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
34 #include "content/browser/browser_thread.h" | 35 #include "content/browser/browser_thread.h" |
35 #include "content/browser/user_metrics.h" | 36 #include "content/browser/user_metrics.h" |
36 #include "content/common/notification_service.h" | 37 #include "content/common/notification_service.h" |
37 #include "content/common/notification_type.h" | |
38 #include "grit/browser_resources.h" | 38 #include "grit/browser_resources.h" |
39 #include "grit/chromium_strings.h" | 39 #include "grit/chromium_strings.h" |
40 #include "grit/generated_resources.h" | 40 #include "grit/generated_resources.h" |
41 #include "grit/locale_settings.h" | 41 #include "grit/locale_settings.h" |
42 #include "grit/theme_resources.h" | 42 #include "grit/theme_resources.h" |
43 #include "ui/base/animation/animation.h" | 43 #include "ui/base/animation/animation.h" |
44 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
45 #include "ui/base/resource/resource_bundle.h" | 45 #include "ui/base/resource/resource_bundle.h" |
46 #include "ui/base/theme_provider.h" | 46 #include "ui/base/theme_provider.h" |
47 #include "ui/gfx/color_utils.h" | 47 #include "ui/gfx/color_utils.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // Is the current time within a given date range? | 147 // Is the current time within a given date range? |
148 bool InDateRange(double begin, double end) { | 148 bool InDateRange(double begin, double end) { |
149 Time start_time = Time::FromDoubleT(begin); | 149 Time start_time = Time::FromDoubleT(begin); |
150 Time end_time = Time::FromDoubleT(end); | 150 Time end_time = Time::FromDoubleT(end); |
151 return start_time < Time::Now() && end_time > Time::Now(); | 151 return start_time < Time::Now() && end_time > Time::Now(); |
152 } | 152 } |
153 | 153 |
154 } // namespace | 154 } // namespace |
155 | 155 |
156 NTPResourceCache::NTPResourceCache(Profile* profile) : profile_(profile) { | 156 NTPResourceCache::NTPResourceCache(Profile* profile) : profile_(profile) { |
157 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | 157 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
158 Source<ThemeService>( | 158 Source<ThemeService>( |
159 ThemeServiceFactory::GetForProfile(profile))); | 159 ThemeServiceFactory::GetForProfile(profile))); |
160 registrar_.Add(this, NotificationType::PROMO_RESOURCE_STATE_CHANGED, | 160 registrar_.Add(this, chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, |
161 NotificationService::AllSources()); | 161 NotificationService::AllSources()); |
162 | 162 |
163 // Watch for pref changes that cause us to need to invalidate the HTML cache. | 163 // Watch for pref changes that cause us to need to invalidate the HTML cache. |
164 pref_change_registrar_.Init(profile_->GetPrefs()); | 164 pref_change_registrar_.Init(profile_->GetPrefs()); |
165 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); | 165 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); |
166 pref_change_registrar_.Add(prefs::kEnableBookmarkBar, this); | 166 pref_change_registrar_.Add(prefs::kEnableBookmarkBar, this); |
167 pref_change_registrar_.Add(prefs::kNTPShownSections, this); | 167 pref_change_registrar_.Add(prefs::kNTPShownSections, this); |
168 } | 168 } |
169 | 169 |
170 NTPResourceCache::~NTPResourceCache() {} | 170 NTPResourceCache::~NTPResourceCache() {} |
(...skipping 17 matching lines...) Expand all Loading... |
188 if (!new_tab_incognito_css_.get()) | 188 if (!new_tab_incognito_css_.get()) |
189 CreateNewTabIncognitoCSS(); | 189 CreateNewTabIncognitoCSS(); |
190 } else { | 190 } else { |
191 if (!new_tab_css_.get()) | 191 if (!new_tab_css_.get()) |
192 CreateNewTabCSS(); | 192 CreateNewTabCSS(); |
193 } | 193 } |
194 return is_incognito ? new_tab_incognito_css_.get() | 194 return is_incognito ? new_tab_incognito_css_.get() |
195 : new_tab_css_.get(); | 195 : new_tab_css_.get(); |
196 } | 196 } |
197 | 197 |
198 void NTPResourceCache::Observe(NotificationType type, | 198 void NTPResourceCache::Observe(int type, |
199 const NotificationSource& source, const NotificationDetails& details) { | 199 const NotificationSource& source, const NotificationDetails& details) { |
200 // Invalidate the cache. | 200 // Invalidate the cache. |
201 if (NotificationType::BROWSER_THEME_CHANGED == type || | 201 if (chrome::NOTIFICATION_BROWSER_THEME_CHANGED == type || |
202 NotificationType::PROMO_RESOURCE_STATE_CHANGED == type) { | 202 chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED == type) { |
203 new_tab_incognito_html_ = NULL; | 203 new_tab_incognito_html_ = NULL; |
204 new_tab_html_ = NULL; | 204 new_tab_html_ = NULL; |
205 new_tab_incognito_css_ = NULL; | 205 new_tab_incognito_css_ = NULL; |
206 new_tab_css_ = NULL; | 206 new_tab_css_ = NULL; |
207 } else if (NotificationType::PREF_CHANGED == type) { | 207 } else if (chrome::NOTIFICATION_PREF_CHANGED == type) { |
208 std::string* pref_name = Details<std::string>(details).ptr(); | 208 std::string* pref_name = Details<std::string>(details).ptr(); |
209 if (*pref_name == prefs::kShowBookmarkBar || | 209 if (*pref_name == prefs::kShowBookmarkBar || |
210 *pref_name == prefs::kEnableBookmarkBar || | 210 *pref_name == prefs::kEnableBookmarkBar || |
211 *pref_name == prefs::kHomePageIsNewTabPage || | 211 *pref_name == prefs::kHomePageIsNewTabPage || |
212 *pref_name == prefs::kNTPShownSections) { | 212 *pref_name == prefs::kNTPShownSections) { |
213 new_tab_incognito_html_ = NULL; | 213 new_tab_incognito_html_ = NULL; |
214 new_tab_html_ = NULL; | 214 new_tab_html_ = NULL; |
215 } else { | 215 } else { |
216 NOTREACHED(); | 216 NOTREACHED(); |
217 } | 217 } |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 ntp_css_resource_id)); | 561 ntp_css_resource_id)); |
562 | 562 |
563 // Create the string from our template and the replacements. | 563 // Create the string from our template and the replacements. |
564 std::string css_string; | 564 std::string css_string; |
565 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); | 565 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); |
566 new_tab_css_ = new RefCountedBytes; | 566 new_tab_css_ = new RefCountedBytes; |
567 new_tab_css_->data.resize(css_string.size()); | 567 new_tab_css_->data.resize(css_string.size()); |
568 std::copy(css_string.begin(), css_string.end(), | 568 std::copy(css_string.begin(), css_string.end(), |
569 new_tab_css_->data.begin()); | 569 new_tab_css_->data.begin()); |
570 } | 570 } |
OLD | NEW |