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/most_visited_handler.h" |
21 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" | 22 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" |
22 #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" |
23 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h" | 24 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h" |
24 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" | 25 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" |
25 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" | 26 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" |
26 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h" | 27 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h" |
27 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
28 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
29 #include "chrome/grit/generated_resources.h" | 30 #include "chrome/grit/generated_resources.h" |
30 #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... |
85 web_ui->OverrideTitle(l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); | 86 web_ui->OverrideTitle(l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); |
86 | 87 |
87 // We count all link clicks as AUTO_BOOKMARK, so that site can be ranked more | 88 // We count all link clicks as AUTO_BOOKMARK, so that site can be ranked more |
88 // highly. Note this means we're including clicks on not only most visited | 89 // highly. Note this means we're including clicks on not only most visited |
89 // thumbnails, but also clicks on recently bookmarked. | 90 // thumbnails, but also clicks on recently bookmarked. |
90 web_ui->SetLinkTransitionType(ui::PAGE_TRANSITION_AUTO_BOOKMARK); | 91 web_ui->SetLinkTransitionType(ui::PAGE_TRANSITION_AUTO_BOOKMARK); |
91 | 92 |
92 Profile* profile = GetProfile(); | 93 Profile* profile = GetProfile(); |
93 if (!profile->IsOffTheRecord()) { | 94 if (!profile->IsOffTheRecord()) { |
94 web_ui->AddMessageHandler(new MetricsHandler()); | 95 web_ui->AddMessageHandler(new MetricsHandler()); |
| 96 web_ui->AddMessageHandler(new MostVisitedHandler()); |
95 web_ui->AddMessageHandler(new FaviconWebUIHandler()); | 97 web_ui->AddMessageHandler(new FaviconWebUIHandler()); |
96 web_ui->AddMessageHandler(new NewTabPageHandler()); | 98 web_ui->AddMessageHandler(new NewTabPageHandler()); |
97 web_ui->AddMessageHandler(new CoreAppLauncherHandler()); | 99 web_ui->AddMessageHandler(new CoreAppLauncherHandler()); |
98 web_ui->AddMessageHandler(new NewTabPageSyncHandler()); | 100 web_ui->AddMessageHandler(new NewTabPageSyncHandler()); |
99 | 101 |
100 ExtensionService* service = | 102 ExtensionService* service = |
101 extensions::ExtensionSystem::Get(profile)->extension_service(); | 103 extensions::ExtensionSystem::Get(profile)->extension_service(); |
102 // We might not have an ExtensionService (on ChromeOS when not logged in | 104 // We might not have an ExtensionService (on ChromeOS when not logged in |
103 // for example). | 105 // for example). |
104 if (service) | 106 if (service) |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 GetProfile()->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar) ? | 206 GetProfile()->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar) ? |
205 "true" : "false"); | 207 "true" : "false"); |
206 web_ui()->CallJavascriptFunction("ntp.setBookmarkBarAttached", attached); | 208 web_ui()->CallJavascriptFunction("ntp.setBookmarkBarAttached", attached); |
207 } | 209 } |
208 | 210 |
209 // static | 211 // static |
210 void NewTabUI::RegisterProfilePrefs( | 212 void NewTabUI::RegisterProfilePrefs( |
211 user_prefs::PrefRegistrySyncable* registry) { | 213 user_prefs::PrefRegistrySyncable* registry) { |
212 CoreAppLauncherHandler::RegisterProfilePrefs(registry); | 214 CoreAppLauncherHandler::RegisterProfilePrefs(registry); |
213 NewTabPageHandler::RegisterProfilePrefs(registry); | 215 NewTabPageHandler::RegisterProfilePrefs(registry); |
| 216 MostVisitedHandler::RegisterProfilePrefs(registry); |
214 } | 217 } |
215 | 218 |
216 // static | 219 // static |
217 bool NewTabUI::ShouldShowApps() { | 220 bool NewTabUI::ShouldShowApps() { |
218 // Ash shows apps in app list thus should not show apps page in NTP4. | 221 // Ash shows apps in app list thus should not show apps page in NTP4. |
219 #if defined(USE_ASH) | 222 #if defined(USE_ASH) |
220 return chrome::GetActiveDesktop() != chrome::HOST_DESKTOP_TYPE_ASH; | 223 return chrome::GetActiveDesktop() != chrome::HOST_DESKTOP_TYPE_ASH; |
221 #else | 224 #else |
222 return true; | 225 return true; |
223 #endif | 226 #endif |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, | 347 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, |
345 const char* mime_type, | 348 const char* mime_type, |
346 int resource_id) { | 349 int resource_id) { |
347 DCHECK(resource); | 350 DCHECK(resource); |
348 DCHECK(mime_type); | 351 DCHECK(mime_type); |
349 resource_map_[std::string(resource)] = | 352 resource_map_[std::string(resource)] = |
350 std::make_pair(std::string(mime_type), resource_id); | 353 std::make_pair(std::string(mime_type), resource_id); |
351 } | 354 } |
352 | 355 |
353 NewTabUI::NewTabHTMLSource::~NewTabHTMLSource() {} | 356 NewTabUI::NewTabHTMLSource::~NewTabHTMLSource() {} |
OLD | NEW |