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/dom_ui/ntp_resource_cache.h" | 5 #include "chrome/browser/dom_ui/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/ref_counted_memory.h" | 12 #include "base/ref_counted_memory.h" |
13 #include "base/string16.h" | 13 #include "base/string16.h" |
14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "chrome/browser/browser_thread.h" | 18 #include "chrome/browser/browser_thread.h" |
19 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" | 19 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
20 #include "chrome/browser/dom_ui/shown_sections_handler.h" | 20 #include "chrome/browser/dom_ui/shown_sections_handler.h" |
21 #include "chrome/browser/google/google_util.h" | 21 #include "chrome/browser/google/google_util.h" |
22 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/themes/browser_theme_provider.h" | 24 #include "chrome/browser/themes/browser_theme_provider.h" |
25 #include "chrome/browser/web_resource/web_resource_service.h" | 25 #include "chrome/browser/web_resource/promo_resource_service.h" |
26 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/extensions/extension.h" | 27 #include "chrome/common/extensions/extension.h" |
28 #include "chrome/common/extensions/extension_constants.h" | 28 #include "chrome/common/extensions/extension_constants.h" |
29 #include "chrome/common/jstemplate_builder.h" | 29 #include "chrome/common/jstemplate_builder.h" |
30 #include "chrome/common/notification_service.h" | 30 #include "chrome/common/notification_service.h" |
31 #include "chrome/common/notification_type.h" | 31 #include "chrome/common/notification_type.h" |
32 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
33 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
34 #include "grit/browser_resources.h" | 34 #include "grit/browser_resources.h" |
35 #include "grit/chromium_strings.h" | 35 #include "grit/chromium_strings.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 Time start_time = Time::FromDoubleT(begin); | 142 Time start_time = Time::FromDoubleT(begin); |
143 Time end_time = Time::FromDoubleT(end); | 143 Time end_time = Time::FromDoubleT(end); |
144 return start_time < Time::Now() && end_time > Time::Now(); | 144 return start_time < Time::Now() && end_time > Time::Now(); |
145 } | 145 } |
146 | 146 |
147 } // namespace | 147 } // namespace |
148 | 148 |
149 NTPResourceCache::NTPResourceCache(Profile* profile) : profile_(profile) { | 149 NTPResourceCache::NTPResourceCache(Profile* profile) : profile_(profile) { |
150 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | 150 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
151 NotificationService::AllSources()); | 151 NotificationService::AllSources()); |
152 registrar_.Add(this, NotificationType::WEB_RESOURCE_STATE_CHANGED, | 152 registrar_.Add(this, NotificationType::PROMO_RESOURCE_STATE_CHANGED, |
153 NotificationService::AllSources()); | 153 NotificationService::AllSources()); |
154 | 154 |
155 // Watch for pref changes that cause us to need to invalidate the HTML cache. | 155 // Watch for pref changes that cause us to need to invalidate the HTML cache. |
156 pref_change_registrar_.Init(profile_->GetPrefs()); | 156 pref_change_registrar_.Init(profile_->GetPrefs()); |
157 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); | 157 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); |
158 pref_change_registrar_.Add(prefs::kNTPShownSections, this); | 158 pref_change_registrar_.Add(prefs::kNTPShownSections, this); |
159 } | 159 } |
160 | 160 |
161 NTPResourceCache::~NTPResourceCache() {} | 161 NTPResourceCache::~NTPResourceCache() {} |
162 | 162 |
(...skipping 20 matching lines...) Expand all Loading... |
183 CreateNewTabCSS(); | 183 CreateNewTabCSS(); |
184 } | 184 } |
185 return is_off_the_record ? new_tab_incognito_css_.get() | 185 return is_off_the_record ? new_tab_incognito_css_.get() |
186 : new_tab_css_.get(); | 186 : new_tab_css_.get(); |
187 } | 187 } |
188 | 188 |
189 void NTPResourceCache::Observe(NotificationType type, | 189 void NTPResourceCache::Observe(NotificationType type, |
190 const NotificationSource& source, const NotificationDetails& details) { | 190 const NotificationSource& source, const NotificationDetails& details) { |
191 // Invalidate the cache. | 191 // Invalidate the cache. |
192 if (NotificationType::BROWSER_THEME_CHANGED == type || | 192 if (NotificationType::BROWSER_THEME_CHANGED == type || |
193 NotificationType::WEB_RESOURCE_STATE_CHANGED == type) { | 193 NotificationType::PROMO_RESOURCE_STATE_CHANGED == type) { |
194 new_tab_incognito_html_ = NULL; | 194 new_tab_incognito_html_ = NULL; |
195 new_tab_html_ = NULL; | 195 new_tab_html_ = NULL; |
196 new_tab_incognito_css_ = NULL; | 196 new_tab_incognito_css_ = NULL; |
197 new_tab_css_ = NULL; | 197 new_tab_css_ = NULL; |
198 } else if (NotificationType::PREF_CHANGED == type) { | 198 } else if (NotificationType::PREF_CHANGED == type) { |
199 std::string* pref_name = Details<std::string>(details).ptr(); | 199 std::string* pref_name = Details<std::string>(details).ptr(); |
200 if (*pref_name == prefs::kShowBookmarkBar || | 200 if (*pref_name == prefs::kShowBookmarkBar || |
201 *pref_name == prefs::kHomePageIsNewTabPage || | 201 *pref_name == prefs::kHomePageIsNewTabPage || |
202 *pref_name == prefs::kNTPShownSections) { | 202 *pref_name == prefs::kNTPShownSections) { |
203 new_tab_incognito_html_ = NULL; | 203 new_tab_incognito_html_ = NULL; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 "true" : "false"); | 373 "true" : "false"); |
374 } else { | 374 } else { |
375 localized_strings.SetString("customlogo", "false"); | 375 localized_strings.SetString("customlogo", "false"); |
376 } | 376 } |
377 | 377 |
378 // If the user has preferences for a start and end time for a promo from | 378 // If the user has preferences for a start and end time for a promo from |
379 // the server, and this promo string exists, set the localized string. | 379 // the server, and this promo string exists, set the localized string. |
380 if (profile_->GetPrefs()->FindPreference(prefs::kNTPPromoStart) && | 380 if (profile_->GetPrefs()->FindPreference(prefs::kNTPPromoStart) && |
381 profile_->GetPrefs()->FindPreference(prefs::kNTPPromoEnd) && | 381 profile_->GetPrefs()->FindPreference(prefs::kNTPPromoEnd) && |
382 profile_->GetPrefs()->FindPreference(prefs::kNTPPromoLine) && | 382 profile_->GetPrefs()->FindPreference(prefs::kNTPPromoLine) && |
383 WebResourceServiceUtil::CanShowPromo(profile_)) { | 383 PromoResourceServiceUtil::CanShowPromo(profile_)) { |
384 localized_strings.SetString("serverpromo", | 384 localized_strings.SetString("serverpromo", |
385 InDateRange(profile_->GetPrefs()->GetDouble(prefs::kNTPPromoStart), | 385 InDateRange(profile_->GetPrefs()->GetDouble(prefs::kNTPPromoStart), |
386 profile_->GetPrefs()->GetDouble(prefs::kNTPPromoEnd)) ? | 386 profile_->GetPrefs()->GetDouble(prefs::kNTPPromoEnd)) ? |
387 profile_->GetPrefs()->GetString(prefs::kNTPPromoLine) : | 387 profile_->GetPrefs()->GetString(prefs::kNTPPromoLine) : |
388 std::string()); | 388 std::string()); |
389 } | 389 } |
390 | 390 |
391 base::StringPiece new_tab_html(ResourceBundle::GetSharedInstance(). | 391 base::StringPiece new_tab_html(ResourceBundle::GetSharedInstance(). |
392 GetRawDataResource(IDR_NEW_NEW_TAB_HTML)); | 392 GetRawDataResource(IDR_NEW_NEW_TAB_HTML)); |
393 | 393 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 std::string css_string; | 550 std::string css_string; |
551 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); | 551 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); |
552 css_string = ReplaceStringPlaceholders(css_string, subst2, NULL); | 552 css_string = ReplaceStringPlaceholders(css_string, subst2, NULL); |
553 css_string = ReplaceStringPlaceholders(css_string, subst3, NULL); | 553 css_string = ReplaceStringPlaceholders(css_string, subst3, NULL); |
554 | 554 |
555 new_tab_css_ = new RefCountedBytes; | 555 new_tab_css_ = new RefCountedBytes; |
556 new_tab_css_->data.resize(css_string.size()); | 556 new_tab_css_->data.resize(css_string.size()); |
557 std::copy(css_string.begin(), css_string.end(), | 557 std::copy(css_string.begin(), css_string.end(), |
558 new_tab_css_->data.begin()); | 558 new_tab_css_->data.begin()); |
559 } | 559 } |
OLD | NEW |