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