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