| 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/new_tab_ui.h" | 5 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/webui/metrics_handler.h" | 17 #include "chrome/browser/ui/webui/metrics_handler.h" |
| 18 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 18 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
| 19 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h" | 19 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h" |
| 20 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" | 20 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" |
| 21 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h" | 21 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h" |
| 22 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h" | |
| 23 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" | 22 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" |
| 24 #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h" | 23 #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h" |
| 25 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h" | 24 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h" |
| 26 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" | 25 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" |
| 27 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" | 26 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" |
| 28 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h" | 27 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h" |
| 29 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
| 31 #include "chrome/grit/generated_resources.h" | 30 #include "chrome/grit/generated_resources.h" |
| 32 #include "components/pref_registry/pref_registry_syncable.h" | 31 #include "components/pref_registry/pref_registry_syncable.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 86 |
| 88 // We count all link clicks as AUTO_BOOKMARK, so that site can be ranked more | 87 // We count all link clicks as AUTO_BOOKMARK, so that site can be ranked more |
| 89 // highly. Note this means we're including clicks on not only most visited | 88 // highly. Note this means we're including clicks on not only most visited |
| 90 // thumbnails, but also clicks on recently bookmarked. | 89 // thumbnails, but also clicks on recently bookmarked. |
| 91 web_ui->SetLinkTransitionType(ui::PAGE_TRANSITION_AUTO_BOOKMARK); | 90 web_ui->SetLinkTransitionType(ui::PAGE_TRANSITION_AUTO_BOOKMARK); |
| 92 | 91 |
| 93 Profile* profile = GetProfile(); | 92 Profile* profile = GetProfile(); |
| 94 if (!profile->IsOffTheRecord()) { | 93 if (!profile->IsOffTheRecord()) { |
| 95 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); | 94 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); |
| 96 web_ui->AddMessageHandler(new MetricsHandler()); | 95 web_ui->AddMessageHandler(new MetricsHandler()); |
| 97 web_ui->AddMessageHandler(new MostVisitedHandler()); | |
| 98 web_ui->AddMessageHandler(new FaviconWebUIHandler()); | 96 web_ui->AddMessageHandler(new FaviconWebUIHandler()); |
| 99 web_ui->AddMessageHandler(new NewTabPageHandler()); | 97 web_ui->AddMessageHandler(new NewTabPageHandler()); |
| 100 web_ui->AddMessageHandler(new CoreAppLauncherHandler()); | 98 web_ui->AddMessageHandler(new CoreAppLauncherHandler()); |
| 101 web_ui->AddMessageHandler(new NewTabPageSyncHandler()); | 99 web_ui->AddMessageHandler(new NewTabPageSyncHandler()); |
| 102 | 100 |
| 103 ExtensionService* service = | 101 ExtensionService* service = |
| 104 extensions::ExtensionSystem::Get(profile)->extension_service(); | 102 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 105 // We might not have an ExtensionService (on ChromeOS when not logged in | 103 // We might not have an ExtensionService (on ChromeOS when not logged in |
| 106 // for example). | 104 // for example). |
| 107 if (service) | 105 if (service) |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 GetProfile()->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar) ? | 205 GetProfile()->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar) ? |
| 208 "true" : "false"); | 206 "true" : "false"); |
| 209 web_ui()->CallJavascriptFunction("ntp.setBookmarkBarAttached", attached); | 207 web_ui()->CallJavascriptFunction("ntp.setBookmarkBarAttached", attached); |
| 210 } | 208 } |
| 211 | 209 |
| 212 // static | 210 // static |
| 213 void NewTabUI::RegisterProfilePrefs( | 211 void NewTabUI::RegisterProfilePrefs( |
| 214 user_prefs::PrefRegistrySyncable* registry) { | 212 user_prefs::PrefRegistrySyncable* registry) { |
| 215 CoreAppLauncherHandler::RegisterProfilePrefs(registry); | 213 CoreAppLauncherHandler::RegisterProfilePrefs(registry); |
| 216 NewTabPageHandler::RegisterProfilePrefs(registry); | 214 NewTabPageHandler::RegisterProfilePrefs(registry); |
| 217 MostVisitedHandler::RegisterProfilePrefs(registry); | |
| 218 browser_sync::ForeignSessionHandler::RegisterProfilePrefs(registry); | 215 browser_sync::ForeignSessionHandler::RegisterProfilePrefs(registry); |
| 219 } | 216 } |
| 220 | 217 |
| 221 // static | 218 // static |
| 222 bool NewTabUI::ShouldShowApps() { | 219 bool NewTabUI::ShouldShowApps() { |
| 223 // Ash shows apps in app list thus should not show apps page in NTP4. | 220 // Ash shows apps in app list thus should not show apps page in NTP4. |
| 224 #if defined(USE_ASH) | 221 #if defined(USE_ASH) |
| 225 return chrome::GetActiveDesktop() != chrome::HOST_DESKTOP_TYPE_ASH; | 222 return chrome::GetActiveDesktop() != chrome::HOST_DESKTOP_TYPE_ASH; |
| 226 #else | 223 #else |
| 227 return true; | 224 return true; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, | 346 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, |
| 350 const char* mime_type, | 347 const char* mime_type, |
| 351 int resource_id) { | 348 int resource_id) { |
| 352 DCHECK(resource); | 349 DCHECK(resource); |
| 353 DCHECK(mime_type); | 350 DCHECK(mime_type); |
| 354 resource_map_[std::string(resource)] = | 351 resource_map_[std::string(resource)] = |
| 355 std::make_pair(std::string(mime_type), resource_id); | 352 std::make_pair(std::string(mime_type), resource_id); |
| 356 } | 353 } |
| 357 | 354 |
| 358 NewTabUI::NewTabHTMLSource::~NewTabHTMLSource() {} | 355 NewTabUI::NewTabHTMLSource::~NewTabHTMLSource() {} |
| OLD | NEW |