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" |
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/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.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_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/extensions/app_launcher.h" |
19 #include "chrome/browser/first_run/first_run.h" | 20 #include "chrome/browser/first_run/first_run.h" |
20 #include "chrome/browser/google/google_util.h" | 21 #include "chrome/browser/google/google_util.h" |
21 #include "chrome/browser/policy/browser_policy_connector.h" | 22 #include "chrome/browser/policy/browser_policy_connector.h" |
22 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" |
23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/sync/profile_sync_service.h" | 25 #include "chrome/browser/sync/profile_sync_service.h" |
25 #include "chrome/browser/sync/profile_sync_service_factory.h" | 26 #include "chrome/browser/sync/profile_sync_service_factory.h" |
26 #include "chrome/browser/themes/theme_service.h" | 27 #include "chrome/browser/themes/theme_service.h" |
27 #include "chrome/browser/themes/theme_service_factory.h" | 28 #include "chrome/browser/themes/theme_service_factory.h" |
28 #include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h" | 29 #include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 const ui::ThemeProvider* theme_provider) { | 157 const ui::ThemeProvider* theme_provider) { |
157 int repeat_mode; | 158 int repeat_mode; |
158 theme_provider->GetDisplayProperty( | 159 theme_provider->GetDisplayProperty( |
159 ThemeService::NTP_BACKGROUND_TILING, &repeat_mode); | 160 ThemeService::NTP_BACKGROUND_TILING, &repeat_mode); |
160 return ThemeService::TilingToString(repeat_mode); | 161 return ThemeService::TilingToString(repeat_mode); |
161 } | 162 } |
162 | 163 |
163 } // namespace | 164 } // namespace |
164 | 165 |
165 NTPResourceCache::NTPResourceCache(Profile* profile) | 166 NTPResourceCache::NTPResourceCache(Profile* profile) |
166 : profile_(profile), is_swipe_tracking_from_scroll_events_enabled_(false) { | 167 : profile_(profile), is_swipe_tracking_from_scroll_events_enabled_(false), |
| 168 should_show_apps_page_(NewTabUI::ShouldShowApps()) { |
167 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 169 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
168 content::Source<ThemeService>( | 170 content::Source<ThemeService>( |
169 ThemeServiceFactory::GetForProfile(profile))); | 171 ThemeServiceFactory::GetForProfile(profile))); |
170 registrar_.Add(this, chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, | 172 registrar_.Add(this, chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, |
171 content::NotificationService::AllSources()); | 173 content::NotificationService::AllSources()); |
172 | 174 |
173 base::Closure callback = base::Bind(&NTPResourceCache::OnPreferenceChanged, | 175 base::Closure callback = base::Bind(&NTPResourceCache::OnPreferenceChanged, |
174 base::Unretained(this)); | 176 base::Unretained(this)); |
175 | 177 |
176 // Watch for pref changes that cause us to need to invalidate the HTML cache. | 178 // Watch for pref changes that cause us to need to invalidate the HTML cache. |
177 pref_change_registrar_.Init(profile_->GetPrefs()); | 179 pref_change_registrar_.Init(profile_->GetPrefs()); |
178 pref_change_registrar_.Add(prefs::kSyncAcknowledgedSyncTypes, callback); | 180 pref_change_registrar_.Add(prefs::kSyncAcknowledgedSyncTypes, callback); |
179 pref_change_registrar_.Add(prefs::kShowBookmarkBar, callback); | 181 pref_change_registrar_.Add(prefs::kShowBookmarkBar, callback); |
180 pref_change_registrar_.Add(prefs::kNtpShownPage, callback); | 182 pref_change_registrar_.Add(prefs::kNtpShownPage, callback); |
181 pref_change_registrar_.Add(prefs::kSyncPromoShowNTPBubble, callback); | 183 pref_change_registrar_.Add(prefs::kSyncPromoShowNTPBubble, callback); |
182 } | 184 } |
183 | 185 |
184 NTPResourceCache::~NTPResourceCache() {} | 186 NTPResourceCache::~NTPResourceCache() {} |
185 | 187 |
186 bool NTPResourceCache::NewTabCacheNeedsRefresh() { | 188 bool NTPResourceCache::NewTabCacheNeedsRefresh() { |
187 #if defined(OS_MACOSX) | 189 #if defined(OS_MACOSX) |
188 // Invalidate if the current value is different from the cached value. | 190 // Invalidate if the current value is different from the cached value. |
189 bool is_enabled = platform_util::IsSwipeTrackingFromScrollEventsEnabled(); | 191 bool is_enabled = platform_util::IsSwipeTrackingFromScrollEventsEnabled(); |
190 if (is_enabled != is_swipe_tracking_from_scroll_events_enabled_) { | 192 if (is_enabled != is_swipe_tracking_from_scroll_events_enabled_) { |
191 is_swipe_tracking_from_scroll_events_enabled_ = is_enabled; | 193 is_swipe_tracking_from_scroll_events_enabled_ = is_enabled; |
192 return true; | 194 return true; |
193 } | 195 } |
194 #endif | 196 #endif |
| 197 bool should_show_apps_page = !extensions::IsAppLauncherEnabled(); |
| 198 if (should_show_apps_page != should_show_apps_page_) { |
| 199 should_show_apps_page_ = should_show_apps_page; |
| 200 return true; |
| 201 } |
195 return false; | 202 return false; |
196 } | 203 } |
197 | 204 |
198 base::RefCountedMemory* NTPResourceCache::GetNewTabHTML(bool is_incognito) { | 205 base::RefCountedMemory* NTPResourceCache::GetNewTabHTML(bool is_incognito) { |
199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
200 if (is_incognito) { | 207 if (is_incognito) { |
201 if (!new_tab_incognito_html_.get()) | 208 if (!new_tab_incognito_html_.get()) |
202 CreateNewTabIncognitoHTML(); | 209 CreateNewTabIncognitoHTML(); |
203 } else { | 210 } else { |
204 // Refresh the cached HTML if necessary. | 211 // Refresh the cached HTML if necessary. |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 load_time_data.SetString("otherSessionsLearnMoreUrl", | 379 load_time_data.SetString("otherSessionsLearnMoreUrl", |
373 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_LEARN_MORE_URL)); | 380 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_LEARN_MORE_URL)); |
374 load_time_data.SetString("learnMore", | 381 load_time_data.SetString("learnMore", |
375 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); | 382 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); |
376 load_time_data.SetString("webStoreLink", | 383 load_time_data.SetString("webStoreLink", |
377 GetUrlWithLang(GURL(extension_urls::GetWebstoreLaunchURL()))); | 384 GetUrlWithLang(GURL(extension_urls::GetWebstoreLaunchURL()))); |
378 load_time_data.SetString("appInstallHintText", | 385 load_time_data.SetString("appInstallHintText", |
379 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_INSTALL_HINT_LABEL)); | 386 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_INSTALL_HINT_LABEL)); |
380 load_time_data.SetBoolean("isDiscoveryInNTPEnabled", | 387 load_time_data.SetBoolean("isDiscoveryInNTPEnabled", |
381 NewTabUI::IsDiscoveryInNTPEnabled()); | 388 NewTabUI::IsDiscoveryInNTPEnabled()); |
382 load_time_data.SetBoolean("showApps", NewTabUI::ShouldShowApps()); | |
383 load_time_data.SetString("collapseSessionMenuItemText", | 389 load_time_data.SetString("collapseSessionMenuItemText", |
384 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_COLLAPSE_SESSION)); | 390 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_COLLAPSE_SESSION)); |
385 load_time_data.SetString("expandSessionMenuItemText", | 391 load_time_data.SetString("expandSessionMenuItemText", |
386 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_EXPAND_SESSION)); | 392 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_EXPAND_SESSION)); |
387 load_time_data.SetString("restoreSessionMenuItemText", | 393 load_time_data.SetString("restoreSessionMenuItemText", |
388 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_OPEN_ALL)); | 394 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_OPEN_ALL)); |
389 load_time_data.SetString("learn_more", | 395 load_time_data.SetString("learn_more", |
390 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); | 396 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); |
391 load_time_data.SetString("tile_grid_screenreader_accessible_description", | 397 load_time_data.SetString("tile_grid_screenreader_accessible_description", |
392 l10n_util::GetStringUTF16(IDS_NEW_TAB_TILE_GRID_ACCESSIBLE_DESCRIPTION)); | 398 l10n_util::GetStringUTF16(IDS_NEW_TAB_TILE_GRID_ACCESSIBLE_DESCRIPTION)); |
393 load_time_data.SetString("page_switcher_change_title", | 399 load_time_data.SetString("page_switcher_change_title", |
394 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_SWITCHER_CHANGE_TITLE)); | 400 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_SWITCHER_CHANGE_TITLE)); |
395 load_time_data.SetString("page_switcher_same_title", | 401 load_time_data.SetString("page_switcher_same_title", |
396 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_SWITCHER_SAME_TITLE)); | 402 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_SWITCHER_SAME_TITLE)); |
397 // On Mac OS X 10.7+, horizontal scrolling can be treated as a back or | 403 // On Mac OS X 10.7+, horizontal scrolling can be treated as a back or |
398 // forward gesture. Pass through a flag that indicates whether or not that | 404 // forward gesture. Pass through a flag that indicates whether or not that |
399 // feature is enabled. | 405 // feature is enabled. |
400 load_time_data.SetBoolean("isSwipeTrackingFromScrollEventsEnabled", | 406 load_time_data.SetBoolean("isSwipeTrackingFromScrollEventsEnabled", |
401 is_swipe_tracking_from_scroll_events_enabled_); | 407 is_swipe_tracking_from_scroll_events_enabled_); |
| 408 load_time_data.SetBoolean("showApps", should_show_apps_page_); |
402 | 409 |
403 #if defined(OS_CHROMEOS) | 410 #if defined(OS_CHROMEOS) |
404 load_time_data.SetString("expandMenu", | 411 load_time_data.SetString("expandMenu", |
405 l10n_util::GetStringUTF16(IDS_NEW_TAB_CLOSE_MENU_EXPAND)); | 412 l10n_util::GetStringUTF16(IDS_NEW_TAB_CLOSE_MENU_EXPAND)); |
406 #endif | 413 #endif |
407 | 414 |
408 NewTabPageHandler::GetLocalizedValues(profile_, &load_time_data); | 415 NewTabPageHandler::GetLocalizedValues(profile_, &load_time_data); |
409 NTPLoginHandler::GetLocalizedValues(profile_, &load_time_data); | 416 NTPLoginHandler::GetLocalizedValues(profile_, &load_time_data); |
410 | 417 |
411 webui::SetFontAndTextDirection(&load_time_data); | 418 webui::SetFontAndTextDirection(&load_time_data); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 static const base::StringPiece new_tab_theme_css( | 586 static const base::StringPiece new_tab_theme_css( |
580 ResourceBundle::GetSharedInstance().GetRawDataResource( | 587 ResourceBundle::GetSharedInstance().GetRawDataResource( |
581 chrome::search::IsInstantExtendedAPIEnabled(profile_) ? | 588 chrome::search::IsInstantExtendedAPIEnabled(profile_) ? |
582 IDR_NEW_TAB_SEARCH_THEME_CSS : IDR_NEW_TAB_4_THEME_CSS)); | 589 IDR_NEW_TAB_SEARCH_THEME_CSS : IDR_NEW_TAB_4_THEME_CSS)); |
583 | 590 |
584 // Create the string from our template and the replacements. | 591 // Create the string from our template and the replacements. |
585 std::string css_string; | 592 std::string css_string; |
586 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); | 593 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); |
587 new_tab_css_ = base::RefCountedString::TakeString(&css_string); | 594 new_tab_css_ = base::RefCountedString::TakeString(&css_string); |
588 } | 595 } |
OLD | NEW |