Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: chrome/browser/ui/webui/ntp/new_tab_ui.cc

Issue 1141843004: NTP Zombie Code Slayer II: Suggestions Page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: and remove urls Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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" 22 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h"
23 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" 23 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h"
24 #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h" 24 #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h"
25 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h" 25 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h"
26 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" 26 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h"
27 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" 27 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h"
28 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h" 28 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h"
29 #include "chrome/browser/ui/webui/ntp/suggestions_page_handler.h"
30 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
31 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
32 #include "chrome/grit/generated_resources.h" 31 #include "chrome/grit/generated_resources.h"
33 #include "components/pref_registry/pref_registry_syncable.h" 32 #include "components/pref_registry/pref_registry_syncable.h"
34 #include "content/public/browser/browser_thread.h" 33 #include "content/public/browser/browser_thread.h"
35 #include "content/public/browser/notification_service.h" 34 #include "content/public/browser/notification_service.h"
36 #include "content/public/browser/render_process_host.h" 35 #include "content/public/browser/render_process_host.h"
37 #include "content/public/browser/render_view_host.h" 36 #include "content/public/browser/render_view_host.h"
38 #include "content/public/browser/url_data_source.h" 37 #include "content/public/browser/url_data_source.h"
39 #include "content/public/browser/web_contents.h" 38 #include "content/public/browser/web_contents.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 web_ui->SetLinkTransitionType(ui::PAGE_TRANSITION_AUTO_BOOKMARK); 91 web_ui->SetLinkTransitionType(ui::PAGE_TRANSITION_AUTO_BOOKMARK);
93 92
94 Profile* profile = GetProfile(); 93 Profile* profile = GetProfile();
95 if (!profile->IsOffTheRecord()) { 94 if (!profile->IsOffTheRecord()) {
96 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); 95 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler());
97 web_ui->AddMessageHandler(new MetricsHandler()); 96 web_ui->AddMessageHandler(new MetricsHandler());
98 web_ui->AddMessageHandler(new MostVisitedHandler()); 97 web_ui->AddMessageHandler(new MostVisitedHandler());
99 web_ui->AddMessageHandler(new FaviconWebUIHandler()); 98 web_ui->AddMessageHandler(new FaviconWebUIHandler());
100 web_ui->AddMessageHandler(new NewTabPageHandler()); 99 web_ui->AddMessageHandler(new NewTabPageHandler());
101 web_ui->AddMessageHandler(new CoreAppLauncherHandler()); 100 web_ui->AddMessageHandler(new CoreAppLauncherHandler());
102 if (NewTabUI::IsDiscoveryInNTPEnabled())
103 web_ui->AddMessageHandler(new SuggestionsHandler());
104 web_ui->AddMessageHandler(new NewTabPageSyncHandler()); 101 web_ui->AddMessageHandler(new NewTabPageSyncHandler());
105 102
106 ExtensionService* service = 103 ExtensionService* service =
107 extensions::ExtensionSystem::Get(profile)->extension_service(); 104 extensions::ExtensionSystem::Get(profile)->extension_service();
108 // We might not have an ExtensionService (on ChromeOS when not logged in 105 // We might not have an ExtensionService (on ChromeOS when not logged in
109 // for example). 106 // for example).
110 if (service) 107 if (service)
111 web_ui->AddMessageHandler(new AppLauncherHandler(service)); 108 web_ui->AddMessageHandler(new AppLauncherHandler(service));
112 } 109 }
113 110
114 if (NTPLoginHandler::ShouldShow(profile)) 111 if (NTPLoginHandler::ShouldShow(profile))
115 web_ui->AddMessageHandler(new NTPLoginHandler()); 112 web_ui->AddMessageHandler(new NTPLoginHandler());
116 113
117 #if defined(ENABLE_THEMES) 114 #if defined(ENABLE_THEMES)
118 // The theme handler can require some CPU, so do it after hooking up the most 115 // The theme handler can require some CPU, so do it after hooking up the most
119 // visited handler. This allows the DB query for the new tab thumbs to happen 116 // visited handler. This allows the DB query for the new tab thumbs to happen
120 // earlier. 117 // earlier.
121 web_ui->AddMessageHandler(new ThemeHandler()); 118 web_ui->AddMessageHandler(new ThemeHandler());
122 #endif 119 #endif
123 120
124 scoped_ptr<NewTabHTMLSource> html_source( 121 scoped_ptr<NewTabHTMLSource> html_source(
125 new NewTabHTMLSource(profile->GetOriginalProfile())); 122 new NewTabHTMLSource(profile->GetOriginalProfile()));
126 123
127 // These two resources should be loaded only if suggestions NTP is enabled.
128 html_source->AddResource("suggestions_page.css", "text/css",
129 NewTabUI::IsDiscoveryInNTPEnabled() ? IDR_SUGGESTIONS_PAGE_CSS : 0);
130 if (NewTabUI::IsDiscoveryInNTPEnabled()) {
131 html_source->AddResource("suggestions_page.js", "application/javascript",
132 IDR_SUGGESTIONS_PAGE_JS);
133 }
134 // content::URLDataSource assumes the ownership of the html_source. 124 // content::URLDataSource assumes the ownership of the html_source.
135 content::URLDataSource::Add(profile, html_source.release()); 125 content::URLDataSource::Add(profile, html_source.release());
136 126
137 pref_change_registrar_.Init(profile->GetPrefs()); 127 pref_change_registrar_.Init(profile->GetPrefs());
138 pref_change_registrar_.Add(bookmarks::prefs::kShowBookmarkBar, 128 pref_change_registrar_.Add(bookmarks::prefs::kShowBookmarkBar,
139 base::Bind(&NewTabUI::OnShowBookmarkBarChanged, 129 base::Bind(&NewTabUI::OnShowBookmarkBarChanged,
140 base::Unretained(this))); 130 base::Unretained(this)));
141 } 131 }
142 132
143 NewTabUI::~NewTabUI() { 133 NewTabUI::~NewTabUI() {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 GetProfile()->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar) ? 207 GetProfile()->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar) ?
218 "true" : "false"); 208 "true" : "false");
219 web_ui()->CallJavascriptFunction("ntp.setBookmarkBarAttached", attached); 209 web_ui()->CallJavascriptFunction("ntp.setBookmarkBarAttached", attached);
220 } 210 }
221 211
222 // static 212 // static
223 void NewTabUI::RegisterProfilePrefs( 213 void NewTabUI::RegisterProfilePrefs(
224 user_prefs::PrefRegistrySyncable* registry) { 214 user_prefs::PrefRegistrySyncable* registry) {
225 CoreAppLauncherHandler::RegisterProfilePrefs(registry); 215 CoreAppLauncherHandler::RegisterProfilePrefs(registry);
226 NewTabPageHandler::RegisterProfilePrefs(registry); 216 NewTabPageHandler::RegisterProfilePrefs(registry);
227 if (NewTabUI::IsDiscoveryInNTPEnabled())
228 SuggestionsHandler::RegisterProfilePrefs(registry);
229 MostVisitedHandler::RegisterProfilePrefs(registry); 217 MostVisitedHandler::RegisterProfilePrefs(registry);
230 browser_sync::ForeignSessionHandler::RegisterProfilePrefs(registry); 218 browser_sync::ForeignSessionHandler::RegisterProfilePrefs(registry);
231 } 219 }
232 220
233 // static 221 // static
234 bool NewTabUI::ShouldShowApps() { 222 bool NewTabUI::ShouldShowApps() {
235 // Ash shows apps in app list thus should not show apps page in NTP4. 223 // Ash shows apps in app list thus should not show apps page in NTP4.
236 #if defined(USE_ASH) 224 #if defined(USE_ASH)
237 return chrome::GetActiveDesktop() != chrome::HOST_DESKTOP_TYPE_ASH; 225 return chrome::GetActiveDesktop() != chrome::HOST_DESKTOP_TYPE_ASH;
238 #else 226 #else
239 return true; 227 return true;
240 #endif 228 #endif
241 } 229 }
242 230
243 // static 231 // static
244 bool NewTabUI::IsDiscoveryInNTPEnabled() {
245 // TODO(beaudoin): The flag was removed during a clean-up pass. We leave that
246 // here to easily enable it back when we will explore this option again.
247 return false;
248 }
249
250 // static
251 void NewTabUI::SetUrlTitleAndDirection(base::DictionaryValue* dictionary, 232 void NewTabUI::SetUrlTitleAndDirection(base::DictionaryValue* dictionary,
252 const base::string16& title, 233 const base::string16& title,
253 const GURL& gurl) { 234 const GURL& gurl) {
254 dictionary->SetString("url", gurl.spec()); 235 dictionary->SetString("url", gurl.spec());
255 236
256 bool using_url_as_the_title = false; 237 bool using_url_as_the_title = false;
257 base::string16 title_to_set(title); 238 base::string16 title_to_set(title);
258 if (title_to_set.empty()) { 239 if (title_to_set.empty()) {
259 using_url_as_the_title = true; 240 using_url_as_the_title = true;
260 title_to_set = base::UTF8ToUTF16(gurl.spec()); 241 title_to_set = base::UTF8ToUTF16(gurl.spec());
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, 349 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource,
369 const char* mime_type, 350 const char* mime_type,
370 int resource_id) { 351 int resource_id) {
371 DCHECK(resource); 352 DCHECK(resource);
372 DCHECK(mime_type); 353 DCHECK(mime_type);
373 resource_map_[std::string(resource)] = 354 resource_map_[std::string(resource)] =
374 std::make_pair(std::string(mime_type), resource_id); 355 std::make_pair(std::string(mime_type), resource_id);
375 } 356 }
376 357
377 NewTabUI::NewTabHTMLSource::~NewTabHTMLSource() {} 358 NewTabUI::NewTabHTMLSource::~NewTabHTMLSource() {}
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/new_tab_ui.h ('k') | chrome/browser/ui/webui/ntp/ntp_resource_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698