| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/animation.h" | 7 #include "app/animation.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
| 10 #include "app/theme_provider.h" | 10 #include "app/theme_provider.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 136 |
| 137 } // namespace | 137 } // namespace |
| 138 | 138 |
| 139 NTPResourceCache::NTPResourceCache(Profile* profile) : profile_(profile) { | 139 NTPResourceCache::NTPResourceCache(Profile* profile) : profile_(profile) { |
| 140 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | 140 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
| 141 NotificationService::AllSources()); | 141 NotificationService::AllSources()); |
| 142 | 142 |
| 143 // Watch for pref changes that cause us to need to invalidate the HTML cache. | 143 // Watch for pref changes that cause us to need to invalidate the HTML cache. |
| 144 PrefService* pref_service = profile_->GetPrefs(); | 144 PrefService* pref_service = profile_->GetPrefs(); |
| 145 pref_service->AddPrefObserver(prefs::kShowBookmarkBar, this); | 145 pref_service->AddPrefObserver(prefs::kShowBookmarkBar, this); |
| 146 pref_service->AddPrefObserver(prefs::kHomePageIsNewTabPage, this); |
| 146 pref_service->AddPrefObserver(prefs::kNTPShownSections, this); | 147 pref_service->AddPrefObserver(prefs::kNTPShownSections, this); |
| 147 | 148 |
| 148 // Watch for pref changes that cause us to need to invalidate the CSS cache. | 149 // Watch for pref changes that cause us to need to invalidate the CSS cache. |
| 149 pref_service->AddPrefObserver(prefs::kNTPPromoLineRemaining, this); | 150 pref_service->AddPrefObserver(prefs::kNTPPromoLineRemaining, this); |
| 150 } | 151 } |
| 151 | 152 |
| 152 NTPResourceCache::~NTPResourceCache() { | 153 NTPResourceCache::~NTPResourceCache() { |
| 153 PrefService* pref_service = profile_->GetPrefs(); | 154 PrefService* pref_service = profile_->GetPrefs(); |
| 154 pref_service->RemovePrefObserver(prefs::kShowBookmarkBar, this); | 155 pref_service->RemovePrefObserver(prefs::kShowBookmarkBar, this); |
| 156 pref_service->RemovePrefObserver(prefs::kHomePageIsNewTabPage, this); |
| 155 pref_service->RemovePrefObserver(prefs::kNTPShownSections, this); | 157 pref_service->RemovePrefObserver(prefs::kNTPShownSections, this); |
| 156 | 158 |
| 157 pref_service->RemovePrefObserver(prefs::kNTPPromoLineRemaining, this); | 159 pref_service->RemovePrefObserver(prefs::kNTPPromoLineRemaining, this); |
| 158 } | 160 } |
| 159 | 161 |
| 160 RefCountedBytes* NTPResourceCache::GetNewTabHTML(bool is_off_the_record) { | 162 RefCountedBytes* NTPResourceCache::GetNewTabHTML(bool is_off_the_record) { |
| 161 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 163 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 162 if (is_off_the_record) { | 164 if (is_off_the_record) { |
| 163 if (!new_tab_incognito_html_.get()) | 165 if (!new_tab_incognito_html_.get()) |
| 164 CreateNewTabIncognitoHTML(); | 166 CreateNewTabIncognitoHTML(); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 l10n_util::GetString(IDS_PRODUCT_NAME), extensionLink)); | 352 l10n_util::GetString(IDS_PRODUCT_NAME), extensionLink)); |
| 351 localized_strings.SetString(L"extensionslink", extensionLink); | 353 localized_strings.SetString(L"extensionslink", extensionLink); |
| 352 | 354 |
| 353 // Don't initiate the sync related message passing with the page if the sync | 355 // Don't initiate the sync related message passing with the page if the sync |
| 354 // code is not present. | 356 // code is not present. |
| 355 if (profile_->GetProfileSyncService()) | 357 if (profile_->GetProfileSyncService()) |
| 356 localized_strings.SetString(L"syncispresent", "true"); | 358 localized_strings.SetString(L"syncispresent", "true"); |
| 357 else | 359 else |
| 358 localized_strings.SetString(L"syncispresent", "false"); | 360 localized_strings.SetString(L"syncispresent", "false"); |
| 359 | 361 |
| 362 if (!profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)) |
| 363 localized_strings.SetString(L"showsetashomepage", "true"); |
| 364 |
| 360 ChromeURLDataManager::DataSource::SetFontAndTextDirection(&localized_strings); | 365 ChromeURLDataManager::DataSource::SetFontAndTextDirection(&localized_strings); |
| 361 | 366 |
| 362 // Control fade and resize animations. | 367 // Control fade and resize animations. |
| 363 std::string anim = | 368 std::string anim = |
| 364 Animation::ShouldRenderRichAnimation() ? "true" : "false"; | 369 Animation::ShouldRenderRichAnimation() ? "true" : "false"; |
| 365 localized_strings.SetString(L"anim", anim); | 370 localized_strings.SetString(L"anim", anim); |
| 366 | 371 |
| 367 // Pass the shown_sections pref early so that we can prevent flicker. | 372 // Pass the shown_sections pref early so that we can prevent flicker. |
| 368 const int shown_sections = profile_->GetPrefs()->GetInteger( | 373 const int shown_sections = profile_->GetPrefs()->GetInteger( |
| 369 prefs::kNTPShownSections); | 374 prefs::kNTPShownSections); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 // Create the string from our template and the replacements. | 546 // Create the string from our template and the replacements. |
| 542 const std::string css_string = ReplaceStringPlaceholders( | 547 const std::string css_string = ReplaceStringPlaceholders( |
| 543 new_tab_theme_css, subst, NULL); | 548 new_tab_theme_css, subst, NULL); |
| 544 std::string full_css = ReplaceStringPlaceholders(css_string, subst2, NULL); | 549 std::string full_css = ReplaceStringPlaceholders(css_string, subst2, NULL); |
| 545 | 550 |
| 546 new_tab_css_ = new RefCountedBytes; | 551 new_tab_css_ = new RefCountedBytes; |
| 547 new_tab_css_->data.resize(full_css.size()); | 552 new_tab_css_->data.resize(full_css.size()); |
| 548 std::copy(full_css.begin(), full_css.end(), | 553 std::copy(full_css.begin(), full_css.end(), |
| 549 new_tab_css_->data.begin()); | 554 new_tab_css_->data.begin()); |
| 550 } | 555 } |
| OLD | NEW |