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 "apps/app_launcher.h" | 10 #include "apps/app_launcher.h" |
| 11 #include "apps/pref_names.h" |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/file_util.h" | 13 #include "base/file_util.h" |
13 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
14 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
15 #include "base/string16.h" | 16 #include "base/string16.h" |
16 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
18 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
19 #include "base/values.h" | 20 #include "base/values.h" |
20 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 174 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
174 content::Source<ThemeService>( | 175 content::Source<ThemeService>( |
175 ThemeServiceFactory::GetForProfile(profile))); | 176 ThemeServiceFactory::GetForProfile(profile))); |
176 registrar_.Add(this, chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, | 177 registrar_.Add(this, chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, |
177 content::NotificationService::AllSources()); | 178 content::NotificationService::AllSources()); |
178 | 179 |
179 base::Closure callback = base::Bind(&NTPResourceCache::OnPreferenceChanged, | 180 base::Closure callback = base::Bind(&NTPResourceCache::OnPreferenceChanged, |
180 base::Unretained(this)); | 181 base::Unretained(this)); |
181 | 182 |
182 // Watch for pref changes that cause us to need to invalidate the HTML cache. | 183 // Watch for pref changes that cause us to need to invalidate the HTML cache. |
183 pref_change_registrar_.Init(profile_->GetPrefs()); | 184 profile_pref_change_registrar_.Init(profile_->GetPrefs()); |
184 pref_change_registrar_.Add(prefs::kSyncAcknowledgedSyncTypes, callback); | 185 profile_pref_change_registrar_.Add(prefs::kSyncAcknowledgedSyncTypes, |
185 pref_change_registrar_.Add(prefs::kShowBookmarkBar, callback); | 186 callback); |
186 pref_change_registrar_.Add(prefs::kNtpShownPage, callback); | 187 profile_pref_change_registrar_.Add(prefs::kShowBookmarkBar, callback); |
187 pref_change_registrar_.Add(prefs::kSyncPromoShowNTPBubble, callback); | 188 profile_pref_change_registrar_.Add(prefs::kNtpShownPage, callback); |
188 pref_change_registrar_.Add(prefs::kHideWebStoreIcon, callback); | 189 profile_pref_change_registrar_.Add(prefs::kSyncPromoShowNTPBubble, callback); |
| 190 profile_pref_change_registrar_.Add(prefs::kHideWebStoreIcon, callback); |
| 191 |
| 192 local_state_pref_change_registrar_.Init(g_browser_process->local_state()); |
| 193 local_state_pref_change_registrar_.Add(apps::prefs::kShowAppLauncherPromo, |
| 194 callback); |
189 } | 195 } |
190 | 196 |
191 NTPResourceCache::~NTPResourceCache() {} | 197 NTPResourceCache::~NTPResourceCache() {} |
192 | 198 |
193 bool NTPResourceCache::NewTabCacheNeedsRefresh() { | 199 bool NTPResourceCache::NewTabCacheNeedsRefresh() { |
194 #if defined(OS_MACOSX) | 200 #if defined(OS_MACOSX) |
195 // Invalidate if the current value is different from the cached value. | 201 // Invalidate if the current value is different from the cached value. |
196 bool is_enabled = platform_util::IsSwipeTrackingFromScrollEventsEnabled(); | 202 bool is_enabled = platform_util::IsSwipeTrackingFromScrollEventsEnabled(); |
197 if (is_enabled != is_swipe_tracking_from_scroll_events_enabled_) { | 203 if (is_enabled != is_swipe_tracking_from_scroll_events_enabled_) { |
198 is_swipe_tracking_from_scroll_events_enabled_ = is_enabled; | 204 is_swipe_tracking_from_scroll_events_enabled_ = is_enabled; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 | 320 |
315 new_tab_incognito_html_ = base::RefCountedString::TakeString(&full_html); | 321 new_tab_incognito_html_ = base::RefCountedString::TakeString(&full_html); |
316 } | 322 } |
317 | 323 |
318 void NTPResourceCache::CreateNewTabHTML() { | 324 void NTPResourceCache::CreateNewTabHTML() { |
319 // TODO(estade): these strings should be defined in their relevant handlers | 325 // TODO(estade): these strings should be defined in their relevant handlers |
320 // (in GetLocalizedValues) and should have more legible names. | 326 // (in GetLocalizedValues) and should have more legible names. |
321 // Show the profile name in the title and most visited labels if the current | 327 // Show the profile name in the title and most visited labels if the current |
322 // profile is not the default. | 328 // profile is not the default. |
323 PrefService* prefs = profile_->GetPrefs(); | 329 PrefService* prefs = profile_->GetPrefs(); |
| 330 PrefService* local_state = g_browser_process->local_state(); |
324 DictionaryValue load_time_data; | 331 DictionaryValue load_time_data; |
325 load_time_data.SetBoolean("bookmarkbarattached", | 332 load_time_data.SetBoolean("bookmarkbarattached", |
326 prefs->GetBoolean(prefs::kShowBookmarkBar)); | 333 prefs->GetBoolean(prefs::kShowBookmarkBar)); |
327 load_time_data.SetBoolean("hasattribution", | 334 load_time_data.SetBoolean("hasattribution", |
328 ThemeServiceFactory::GetForProfile(profile_)->HasCustomImage( | 335 ThemeServiceFactory::GetForProfile(profile_)->HasCustomImage( |
329 IDR_THEME_NTP_ATTRIBUTION)); | 336 IDR_THEME_NTP_ATTRIBUTION)); |
330 load_time_data.SetBoolean("showMostvisited", should_show_most_visited_page_); | 337 load_time_data.SetBoolean("showMostvisited", should_show_most_visited_page_); |
| 338 load_time_data.SetBoolean( |
| 339 "showAppLauncherPromo", |
| 340 local_state->GetBoolean(apps::prefs::kShowAppLauncherPromo)); |
331 load_time_data.SetBoolean("showRecentlyClosed", | 341 load_time_data.SetBoolean("showRecentlyClosed", |
332 should_show_recently_closed_menu_); | 342 should_show_recently_closed_menu_); |
333 load_time_data.SetString("title", | 343 load_time_data.SetString("title", |
334 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); | 344 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); |
335 load_time_data.SetString("mostvisited", | 345 load_time_data.SetString("mostvisited", |
336 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED)); | 346 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED)); |
337 load_time_data.SetString("suggestions", | 347 load_time_data.SetString("suggestions", |
338 l10n_util::GetStringUTF16(IDS_NEW_TAB_SUGGESTIONS)); | 348 l10n_util::GetStringUTF16(IDS_NEW_TAB_SUGGESTIONS)); |
339 load_time_data.SetString("restoreThumbnailsShort", | 349 load_time_data.SetString("restoreThumbnailsShort", |
340 l10n_util::GetStringUTF16(IDS_NEW_TAB_RESTORE_THUMBNAILS_SHORT_LINK)); | 350 l10n_util::GetStringUTF16(IDS_NEW_TAB_RESTORE_THUMBNAILS_SHORT_LINK)); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 load_time_data.SetString("restoreSessionMenuItemText", | 409 load_time_data.SetString("restoreSessionMenuItemText", |
400 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_OPEN_ALL)); | 410 l10n_util::GetStringUTF16(IDS_NEW_TAB_OTHER_SESSIONS_OPEN_ALL)); |
401 load_time_data.SetString("learn_more", | 411 load_time_data.SetString("learn_more", |
402 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); | 412 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); |
403 load_time_data.SetString("tile_grid_screenreader_accessible_description", | 413 load_time_data.SetString("tile_grid_screenreader_accessible_description", |
404 l10n_util::GetStringUTF16(IDS_NEW_TAB_TILE_GRID_ACCESSIBLE_DESCRIPTION)); | 414 l10n_util::GetStringUTF16(IDS_NEW_TAB_TILE_GRID_ACCESSIBLE_DESCRIPTION)); |
405 load_time_data.SetString("page_switcher_change_title", | 415 load_time_data.SetString("page_switcher_change_title", |
406 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_SWITCHER_CHANGE_TITLE)); | 416 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_SWITCHER_CHANGE_TITLE)); |
407 load_time_data.SetString("page_switcher_same_title", | 417 load_time_data.SetString("page_switcher_same_title", |
408 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_SWITCHER_SAME_TITLE)); | 418 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_SWITCHER_SAME_TITLE)); |
| 419 load_time_data.SetString("appsPromoTitle", |
| 420 l10n_util::GetStringUTF16(IDS_NEW_TAB_PAGE_APPS_PROMO_TITLE)); |
409 // On Mac OS X 10.7+, horizontal scrolling can be treated as a back or | 421 // On Mac OS X 10.7+, horizontal scrolling can be treated as a back or |
410 // forward gesture. Pass through a flag that indicates whether or not that | 422 // forward gesture. Pass through a flag that indicates whether or not that |
411 // feature is enabled. | 423 // feature is enabled. |
412 load_time_data.SetBoolean("isSwipeTrackingFromScrollEventsEnabled", | 424 load_time_data.SetBoolean("isSwipeTrackingFromScrollEventsEnabled", |
413 is_swipe_tracking_from_scroll_events_enabled_); | 425 is_swipe_tracking_from_scroll_events_enabled_); |
414 load_time_data.SetBoolean("showApps", should_show_apps_page_); | 426 load_time_data.SetBoolean("showApps", should_show_apps_page_); |
415 load_time_data.SetBoolean("showWebStoreIcon", | 427 load_time_data.SetBoolean("showWebStoreIcon", |
416 !prefs->GetBoolean(prefs::kHideWebStoreIcon)); | 428 !prefs->GetBoolean(prefs::kHideWebStoreIcon)); |
417 | 429 |
418 #if defined(OS_CHROMEOS) | 430 #if defined(OS_CHROMEOS) |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 // Get our template. | 605 // Get our template. |
594 static const base::StringPiece new_tab_theme_css( | 606 static const base::StringPiece new_tab_theme_css( |
595 ResourceBundle::GetSharedInstance().GetRawDataResource( | 607 ResourceBundle::GetSharedInstance().GetRawDataResource( |
596 IDR_NEW_TAB_4_THEME_CSS)); | 608 IDR_NEW_TAB_4_THEME_CSS)); |
597 | 609 |
598 // Create the string from our template and the replacements. | 610 // Create the string from our template and the replacements. |
599 std::string css_string; | 611 std::string css_string; |
600 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); | 612 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); |
601 new_tab_css_ = base::RefCountedString::TakeString(&css_string); | 613 new_tab_css_ = base::RefCountedString::TakeString(&css_string); |
602 } | 614 } |
OLD | NEW |