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

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

Issue 259393006: Remove WebUI NTP on Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
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"
19 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h"
18 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" 20 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h"
19 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h" 21 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h"
20 #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"
24 #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h"
25 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h"
21 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" 26 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h"
22 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" 27 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h"
23 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h" 28 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h"
24 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h" 29 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h"
30 #include "chrome/browser/ui/webui/ntp/suggestions_page_handler.h"
25 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
26 #include "chrome/common/url_constants.h" 32 #include "chrome/common/url_constants.h"
27 #include "components/user_prefs/pref_registry_syncable.h" 33 #include "components/user_prefs/pref_registry_syncable.h"
28 #include "content/public/browser/browser_thread.h" 34 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/notification_service.h" 35 #include "content/public/browser/notification_service.h"
30 #include "content/public/browser/render_process_host.h" 36 #include "content/public/browser/render_process_host.h"
31 #include "content/public/browser/render_view_host.h" 37 #include "content/public/browser/render_view_host.h"
32 #include "content/public/browser/url_data_source.h" 38 #include "content/public/browser/url_data_source.h"
33 #include "content/public/browser/web_contents.h" 39 #include "content/public/browser/web_contents.h"
34 #include "content/public/browser/web_ui.h" 40 #include "content/public/browser/web_ui.h"
35 #include "grit/browser_resources.h" 41 #include "grit/browser_resources.h"
36 #include "grit/generated_resources.h" 42 #include "grit/generated_resources.h"
37 #include "ui/base/l10n/l10n_util.h" 43 #include "ui/base/l10n/l10n_util.h"
38 44
39 #if !defined(OS_ANDROID)
40 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
41 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h"
42 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h"
43 #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h"
44 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h"
45 #include "chrome/browser/ui/webui/ntp/suggestions_page_handler.h"
46 #else
47 #include "chrome/browser/ui/webui/ntp/android/bookmarks_handler.h"
48 #include "chrome/browser/ui/webui/ntp/android/context_menu_handler.h"
49 #include "chrome/browser/ui/webui/ntp/android/navigation_handler.h"
50 #include "chrome/browser/ui/webui/ntp/android/new_tab_page_ready_handler.h"
51 #include "chrome/browser/ui/webui/ntp/android/promo_handler.h"
52 #endif
53
54 #if defined(ENABLE_THEMES) 45 #if defined(ENABLE_THEMES)
55 #include "chrome/browser/ui/webui/theme_handler.h" 46 #include "chrome/browser/ui/webui/theme_handler.h"
56 #endif 47 #endif
57 48
58 #if defined(USE_ASH) 49 #if defined(USE_ASH)
59 #include "chrome/browser/ui/host_desktop.h" 50 #include "chrome/browser/ui/host_desktop.h"
60 #endif 51 #endif
61 52
62 using content::BrowserThread; 53 using content::BrowserThread;
63 using content::RenderViewHost; 54 using content::RenderViewHost;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 // We count all link clicks as AUTO_BOOKMARK, so that site can be ranked more 89 // We count all link clicks as AUTO_BOOKMARK, so that site can be ranked more
99 // highly. Note this means we're including clicks on not only most visited 90 // highly. Note this means we're including clicks on not only most visited
100 // thumbnails, but also clicks on recently bookmarked. 91 // thumbnails, but also clicks on recently bookmarked.
101 web_ui->SetLinkTransitionType(content::PAGE_TRANSITION_AUTO_BOOKMARK); 92 web_ui->SetLinkTransitionType(content::PAGE_TRANSITION_AUTO_BOOKMARK);
102 93
103 if (!GetProfile()->IsOffTheRecord()) { 94 if (!GetProfile()->IsOffTheRecord()) {
104 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); 95 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler());
105 web_ui->AddMessageHandler(new MetricsHandler()); 96 web_ui->AddMessageHandler(new MetricsHandler());
106 web_ui->AddMessageHandler(new MostVisitedHandler()); 97 web_ui->AddMessageHandler(new MostVisitedHandler());
107 web_ui->AddMessageHandler(new RecentlyClosedTabsHandler()); 98 web_ui->AddMessageHandler(new RecentlyClosedTabsHandler());
108 #if !defined(OS_ANDROID)
109 web_ui->AddMessageHandler(new FaviconWebUIHandler()); 99 web_ui->AddMessageHandler(new FaviconWebUIHandler());
110 web_ui->AddMessageHandler(new NewTabPageHandler()); 100 web_ui->AddMessageHandler(new NewTabPageHandler());
111 web_ui->AddMessageHandler(new CoreAppLauncherHandler()); 101 web_ui->AddMessageHandler(new CoreAppLauncherHandler());
112 if (NewTabUI::IsDiscoveryInNTPEnabled()) 102 if (NewTabUI::IsDiscoveryInNTPEnabled())
113 web_ui->AddMessageHandler(new SuggestionsHandler()); 103 web_ui->AddMessageHandler(new SuggestionsHandler());
114 // Android doesn't have a sync promo/username on NTP.
115 web_ui->AddMessageHandler(new NewTabPageSyncHandler()); 104 web_ui->AddMessageHandler(new NewTabPageSyncHandler());
116 105
117 if (MightShowApps()) { 106 ExtensionService* service = GetProfile()->GetExtensionService();
118 ExtensionService* service = GetProfile()->GetExtensionService(); 107 // We might not have an ExtensionService (on ChromeOS when not logged in
119 // We might not have an ExtensionService (on ChromeOS when not logged in 108 // for example).
120 // for example). 109 if (service)
121 if (service) 110 web_ui->AddMessageHandler(new AppLauncherHandler(service));
122 web_ui->AddMessageHandler(new AppLauncherHandler(service));
123 }
124 #endif
125 } 111 }
126 112
127 #if defined(OS_ANDROID)
128 // These handlers are specific to the Android NTP page.
129 web_ui->AddMessageHandler(new BookmarksHandler());
130 web_ui->AddMessageHandler(new ContextMenuHandler());
131 web_ui->AddMessageHandler(new FaviconWebUIHandler());
132 web_ui->AddMessageHandler(new NavigationHandler());
133 web_ui->AddMessageHandler(new NewTabPageReadyHandler());
134 if (!GetProfile()->IsOffTheRecord())
135 web_ui->AddMessageHandler(new PromoHandler());
136 #else
137 // Android uses native UI for sync setup.
138 if (NTPLoginHandler::ShouldShow(GetProfile())) 113 if (NTPLoginHandler::ShouldShow(GetProfile()))
139 web_ui->AddMessageHandler(new NTPLoginHandler()); 114 web_ui->AddMessageHandler(new NTPLoginHandler());
140 #endif
141 115
142 #if defined(ENABLE_THEMES) 116 #if defined(ENABLE_THEMES)
143 // The theme handler can require some CPU, so do it after hooking up the most 117 // The theme handler can require some CPU, so do it after hooking up the most
144 // visited handler. This allows the DB query for the new tab thumbs to happen 118 // visited handler. This allows the DB query for the new tab thumbs to happen
145 // earlier. 119 // earlier.
146 web_ui->AddMessageHandler(new ThemeHandler()); 120 web_ui->AddMessageHandler(new ThemeHandler());
147 #endif 121 #endif
148 122
149 scoped_ptr<NewTabHTMLSource> html_source(new NewTabHTMLSource( 123 scoped_ptr<NewTabHTMLSource> html_source(new NewTabHTMLSource(
150 GetProfile()->GetOriginalProfile())); 124 GetProfile()->GetOriginalProfile()));
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 void NewTabUI::OnShowBookmarkBarChanged() { 214 void NewTabUI::OnShowBookmarkBarChanged() {
241 base::StringValue attached( 215 base::StringValue attached(
242 GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) ? 216 GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) ?
243 "true" : "false"); 217 "true" : "false");
244 web_ui()->CallJavascriptFunction("ntp.setBookmarkBarAttached", attached); 218 web_ui()->CallJavascriptFunction("ntp.setBookmarkBarAttached", attached);
245 } 219 }
246 220
247 // static 221 // static
248 void NewTabUI::RegisterProfilePrefs( 222 void NewTabUI::RegisterProfilePrefs(
249 user_prefs::PrefRegistrySyncable* registry) { 223 user_prefs::PrefRegistrySyncable* registry) {
250 #if !defined(OS_ANDROID)
251 CoreAppLauncherHandler::RegisterProfilePrefs(registry); 224 CoreAppLauncherHandler::RegisterProfilePrefs(registry);
252 NewTabPageHandler::RegisterProfilePrefs(registry); 225 NewTabPageHandler::RegisterProfilePrefs(registry);
253 if (NewTabUI::IsDiscoveryInNTPEnabled()) 226 if (NewTabUI::IsDiscoveryInNTPEnabled())
254 SuggestionsHandler::RegisterProfilePrefs(registry); 227 SuggestionsHandler::RegisterProfilePrefs(registry);
255 #endif
256 MostVisitedHandler::RegisterProfilePrefs(registry); 228 MostVisitedHandler::RegisterProfilePrefs(registry);
257 browser_sync::ForeignSessionHandler::RegisterProfilePrefs(registry); 229 browser_sync::ForeignSessionHandler::RegisterProfilePrefs(registry);
258 } 230 }
259 231
260 // static 232 // static
261 bool NewTabUI::MightShowApps() {
262 // Android does not have apps.
263 #if defined(OS_ANDROID)
264 return false;
265 #else
266 return true;
267 #endif
268 }
269
270 // static
271 bool NewTabUI::ShouldShowApps() { 233 bool NewTabUI::ShouldShowApps() {
272 // Ash shows apps in app list thus should not show apps page in NTP4. 234 // Ash shows apps in app list thus should not show apps page in NTP4.
273 // Android does not have apps. 235 #if defined(USE_ASH)
274 #if defined(OS_ANDROID)
275 return false;
276 #elif defined(USE_ASH)
277 return chrome::GetActiveDesktop() != chrome::HOST_DESKTOP_TYPE_ASH; 236 return chrome::GetActiveDesktop() != chrome::HOST_DESKTOP_TYPE_ASH;
278 #else 237 #else
279 return true; 238 return true;
280 #endif 239 #endif
281 } 240 }
282 241
283 // static 242 // static
284 bool NewTabUI::IsDiscoveryInNTPEnabled() { 243 bool NewTabUI::IsDiscoveryInNTPEnabled() {
285 // TODO(beaudoin): The flag was removed during a clean-up pass. We leave that 244 // TODO(beaudoin): The flag was removed during a clean-up pass. We leave that
286 // here to easily enable it back when we will explore this option again. 245 // here to easily enable it back when we will explore this option again.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( 324 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
366 it->second.second) : 325 it->second.second) :
367 new base::RefCountedStaticMemory); 326 new base::RefCountedStaticMemory);
368 callback.Run(resource_bytes.get()); 327 callback.Run(resource_bytes.get());
369 return; 328 return;
370 } 329 }
371 330
372 if (!path.empty() && path[0] != '#') { 331 if (!path.empty() && path[0] != '#') {
373 // A path under new-tab was requested; it's likely a bad relative 332 // A path under new-tab was requested; it's likely a bad relative
374 // URL from the new tab page, but in any case it's an error. 333 // URL from the new tab page, but in any case it's an error.
375
376 // TODO(dtrainor): Can remove this #if check once we update the
377 // accessibility script to no longer try to access urls like
378 // '?2314124523523'.
379 // See http://crbug.com/150252.
380 #if !defined(OS_ANDROID)
381 NOTREACHED() << path << " should not have been requested on the NTP"; 334 NOTREACHED() << path << " should not have been requested on the NTP";
382 #endif
383 callback.Run(NULL); 335 callback.Run(NULL);
384 return; 336 return;
385 } 337 }
386 338
387 content::RenderProcessHost* render_host = 339 content::RenderProcessHost* render_host =
388 content::RenderProcessHost::FromID(render_process_id); 340 content::RenderProcessHost::FromID(render_process_id);
389 NTPResourceCache::WindowType win_type = NTPResourceCache::GetWindowType( 341 NTPResourceCache::WindowType win_type = NTPResourceCache::GetWindowType(
390 profile_, render_host); 342 profile_, render_host);
391 scoped_refptr<base::RefCountedMemory> html_bytes( 343 scoped_refptr<base::RefCountedMemory> html_bytes(
392 NTPResourceCacheFactory::GetForProfile(profile_)-> 344 NTPResourceCacheFactory::GetForProfile(profile_)->
(...skipping 22 matching lines...) Expand all
415 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, 367 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource,
416 const char* mime_type, 368 const char* mime_type,
417 int resource_id) { 369 int resource_id) {
418 DCHECK(resource); 370 DCHECK(resource);
419 DCHECK(mime_type); 371 DCHECK(mime_type);
420 resource_map_[std::string(resource)] = 372 resource_map_[std::string(resource)] =
421 std::make_pair(std::string(mime_type), resource_id); 373 std::make_pair(std::string(mime_type), resource_id);
422 } 374 }
423 375
424 NewTabUI::NewTabHTMLSource::~NewTabHTMLSource() {} 376 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_login_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698