| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 7 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/browser/sessions/session_types.h" | 24 #include "chrome/browser/sessions/session_types.h" |
| 25 #include "chrome/browser/sync/profile_sync_service.h" | 25 #include "chrome/browser/sync/profile_sync_service.h" |
| 26 #include "chrome/browser/themes/theme_service.h" | 26 #include "chrome/browser/themes/theme_service.h" |
| 27 #include "chrome/browser/themes/theme_service_factory.h" | 27 #include "chrome/browser/themes/theme_service_factory.h" |
| 28 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
| 29 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 29 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 30 #include "chrome/browser/ui/webui/metrics_handler.h" | 30 #include "chrome/browser/ui/webui/metrics_handler.h" |
| 31 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" | 31 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" |
| 32 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h" | 32 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h" |
| 33 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h" | 33 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h" |
| 34 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" | |
| 35 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" | 34 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" |
| 36 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" | 35 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" |
| 37 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h" | 36 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h" |
| 38 #include "chrome/browser/ui/webui/theme_source.h" | 37 #include "chrome/browser/ui/webui/theme_source.h" |
| 39 #include "chrome/common/chrome_notification_types.h" | 38 #include "chrome/common/chrome_notification_types.h" |
| 40 #include "chrome/common/chrome_switches.h" | 39 #include "chrome/common/chrome_switches.h" |
| 41 #include "chrome/common/extensions/extension.h" | 40 #include "chrome/common/extensions/extension.h" |
| 42 #include "chrome/common/pref_names.h" | 41 #include "chrome/common/pref_names.h" |
| 43 #include "chrome/common/url_constants.h" | 42 #include "chrome/common/url_constants.h" |
| 44 #include "content/public/browser/browser_thread.h" | 43 #include "content/public/browser/browser_thread.h" |
| 45 #include "content/public/browser/notification_service.h" | 44 #include "content/public/browser/notification_service.h" |
| 46 #include "content/public/browser/render_view_host.h" | 45 #include "content/public/browser/render_view_host.h" |
| 47 #include "content/public/browser/user_metrics.h" | 46 #include "content/public/browser/user_metrics.h" |
| 48 #include "content/public/browser/web_contents.h" | 47 #include "content/public/browser/web_contents.h" |
| 49 #include "content/public/browser/web_ui.h" | 48 #include "content/public/browser/web_ui.h" |
| 50 #include "grit/browser_resources.h" | 49 #include "grit/browser_resources.h" |
| 51 #include "grit/generated_resources.h" | 50 #include "grit/generated_resources.h" |
| 52 #include "grit/theme_resources.h" | 51 #include "grit/theme_resources.h" |
| 53 #include "ui/base/l10n/l10n_util.h" | 52 #include "ui/base/l10n/l10n_util.h" |
| 54 #include "ui/base/layout.h" | 53 #include "ui/base/layout.h" |
| 55 #include "ui/base/resource/resource_bundle.h" | 54 #include "ui/base/resource/resource_bundle.h" |
| 56 | 55 |
| 57 #if !defined(OS_ANDROID) | 56 #if !defined(OS_ANDROID) |
| 58 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 57 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
| 58 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" |
| 59 #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h" | 59 #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h" |
| 60 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h" | 60 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h" |
| 61 #include "chrome/browser/ui/webui/ntp/suggestions_page_handler.h" | 61 #include "chrome/browser/ui/webui/ntp/suggestions_page_handler.h" |
| 62 #else | 62 #else |
| 63 #include "chrome/browser/ui/webui/ntp/android/bookmarks_handler.h" | 63 #include "chrome/browser/ui/webui/ntp/android/bookmarks_handler.h" |
| 64 #include "chrome/browser/ui/webui/ntp/android/context_menu_handler.h" | 64 #include "chrome/browser/ui/webui/ntp/android/context_menu_handler.h" |
| 65 #include "chrome/browser/ui/webui/ntp/android/new_tab_page_ready_handler.h" |
| 65 #include "chrome/browser/ui/webui/ntp/android/promo_handler.h" | 66 #include "chrome/browser/ui/webui/ntp/android/promo_handler.h" |
| 66 #endif | 67 #endif |
| 67 | 68 |
| 68 using content::BrowserThread; | 69 using content::BrowserThread; |
| 69 using content::RenderViewHost; | 70 using content::RenderViewHost; |
| 70 using content::UserMetricsAction; | 71 using content::UserMetricsAction; |
| 71 using content::WebContents; | 72 using content::WebContents; |
| 72 using content::WebUIController; | 73 using content::WebUIController; |
| 73 | 74 |
| 74 namespace { | 75 namespace { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 104 // highly. Note this means we're including clicks on not only most visited | 105 // highly. Note this means we're including clicks on not only most visited |
| 105 // thumbnails, but also clicks on recently bookmarked. | 106 // thumbnails, but also clicks on recently bookmarked. |
| 106 web_ui->SetLinkTransitionType(content::PAGE_TRANSITION_AUTO_BOOKMARK); | 107 web_ui->SetLinkTransitionType(content::PAGE_TRANSITION_AUTO_BOOKMARK); |
| 107 | 108 |
| 108 if (!GetProfile()->IsOffTheRecord()) { | 109 if (!GetProfile()->IsOffTheRecord()) { |
| 109 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); | 110 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); |
| 110 web_ui->AddMessageHandler(new MostVisitedHandler()); | 111 web_ui->AddMessageHandler(new MostVisitedHandler()); |
| 111 web_ui->AddMessageHandler(new RecentlyClosedTabsHandler()); | 112 web_ui->AddMessageHandler(new RecentlyClosedTabsHandler()); |
| 112 web_ui->AddMessageHandler(new MetricsHandler()); | 113 web_ui->AddMessageHandler(new MetricsHandler()); |
| 113 #if !defined(OS_ANDROID) | 114 #if !defined(OS_ANDROID) |
| 115 web_ui->AddMessageHandler(new NewTabPageHandler()); |
| 114 if (NewTabUI::IsDiscoveryInNTPEnabled()) | 116 if (NewTabUI::IsDiscoveryInNTPEnabled()) |
| 115 web_ui->AddMessageHandler(new SuggestionsHandler()); | 117 web_ui->AddMessageHandler(new SuggestionsHandler()); |
| 116 // Android doesn't have a sync promo/username on NTP. | 118 // Android doesn't have a sync promo/username on NTP. |
| 117 if (GetProfile()->IsSyncAccessible()) | 119 if (GetProfile()->IsSyncAccessible()) |
| 118 web_ui->AddMessageHandler(new NewTabPageSyncHandler()); | 120 web_ui->AddMessageHandler(new NewTabPageSyncHandler()); |
| 119 | 121 |
| 120 // Or apps. | 122 // Or apps. |
| 121 if (ShouldShowApps()) { | 123 if (ShouldShowApps()) { |
| 122 ExtensionService* service = GetProfile()->GetExtensionService(); | 124 ExtensionService* service = GetProfile()->GetExtensionService(); |
| 123 // We might not have an ExtensionService (on ChromeOS when not logged in | 125 // We might not have an ExtensionService (on ChromeOS when not logged in |
| 124 // for example). | 126 // for example). |
| 125 if (service) | 127 if (service) |
| 126 web_ui->AddMessageHandler(new AppLauncherHandler(service)); | 128 web_ui->AddMessageHandler(new AppLauncherHandler(service)); |
| 127 } | 129 } |
| 128 #endif | 130 #endif |
| 129 | 131 |
| 130 web_ui->AddMessageHandler(new NewTabPageHandler()); | |
| 131 web_ui->AddMessageHandler(new FaviconWebUIHandler()); | 132 web_ui->AddMessageHandler(new FaviconWebUIHandler()); |
| 132 } | 133 } |
| 133 | 134 |
| 134 #if defined(OS_ANDROID) | 135 #if defined(OS_ANDROID) |
| 135 // These handlers are specific to the Android NTP page. | 136 // These handlers are specific to the Android NTP page. |
| 136 web_ui->AddMessageHandler(new BookmarksHandler()); | 137 web_ui->AddMessageHandler(new BookmarksHandler()); |
| 137 web_ui->AddMessageHandler(new ContextMenuHandler()); | 138 web_ui->AddMessageHandler(new ContextMenuHandler()); |
| 139 web_ui->AddMessageHandler(new NewTabPageReadyHandler()); |
| 138 if (!GetProfile()->IsOffTheRecord()) | 140 if (!GetProfile()->IsOffTheRecord()) |
| 139 web_ui->AddMessageHandler(new PromoHandler()); | 141 web_ui->AddMessageHandler(new PromoHandler()); |
| 140 #else | 142 #else |
| 141 // Android uses native UI for sync setup. | 143 // Android uses native UI for sync setup. |
| 142 if (NTPLoginHandler::ShouldShow(GetProfile())) | 144 if (NTPLoginHandler::ShouldShow(GetProfile())) |
| 143 web_ui->AddMessageHandler(new NTPLoginHandler()); | 145 web_ui->AddMessageHandler(new NTPLoginHandler()); |
| 144 #endif | 146 #endif |
| 145 | 147 |
| 146 // Initializing the CSS and HTML can require some CPU, so do it after | 148 // Initializing the CSS and HTML can require some CPU, so do it after |
| 147 // we've hooked up the most visited handler. This allows the DB query | 149 // we've hooked up the most visited handler. This allows the DB query |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 void NewTabUI::InitializeCSSCaches() { | 271 void NewTabUI::InitializeCSSCaches() { |
| 270 #if defined(ENABLE_THEMES) | 272 #if defined(ENABLE_THEMES) |
| 271 Profile* profile = GetProfile(); | 273 Profile* profile = GetProfile(); |
| 272 ThemeSource* theme = new ThemeSource(profile); | 274 ThemeSource* theme = new ThemeSource(profile); |
| 273 ChromeURLDataManager::AddDataSource(profile, theme); | 275 ChromeURLDataManager::AddDataSource(profile, theme); |
| 274 #endif | 276 #endif |
| 275 } | 277 } |
| 276 | 278 |
| 277 // static | 279 // static |
| 278 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { | 280 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { |
| 279 NewTabPageHandler::RegisterUserPrefs(prefs); | |
| 280 #if !defined(OS_ANDROID) | 281 #if !defined(OS_ANDROID) |
| 281 AppLauncherHandler::RegisterUserPrefs(prefs); | 282 AppLauncherHandler::RegisterUserPrefs(prefs); |
| 283 NewTabPageHandler::RegisterUserPrefs(prefs); |
| 282 if (NewTabUI::IsDiscoveryInNTPEnabled()) | 284 if (NewTabUI::IsDiscoveryInNTPEnabled()) |
| 283 SuggestionsHandler::RegisterUserPrefs(prefs); | 285 SuggestionsHandler::RegisterUserPrefs(prefs); |
| 284 #endif | 286 #endif |
| 285 MostVisitedHandler::RegisterUserPrefs(prefs); | 287 MostVisitedHandler::RegisterUserPrefs(prefs); |
| 286 browser_sync::ForeignSessionHandler::RegisterUserPrefs(prefs); | 288 browser_sync::ForeignSessionHandler::RegisterUserPrefs(prefs); |
| 287 } | 289 } |
| 288 | 290 |
| 289 // static | 291 // static |
| 290 bool NewTabUI::ShouldShowApps() { | 292 bool NewTabUI::ShouldShowApps() { |
| 291 #if defined(USE_ASH) || defined(OS_ANDROID) | 293 #if defined(USE_ASH) || defined(OS_ANDROID) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( | 374 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( |
| 373 it->second.second, ui::SCALE_FACTOR_NONE) : | 375 it->second.second, ui::SCALE_FACTOR_NONE) : |
| 374 new base::RefCountedStaticMemory); | 376 new base::RefCountedStaticMemory); |
| 375 SendResponse(request_id, resource_bytes); | 377 SendResponse(request_id, resource_bytes); |
| 376 return; | 378 return; |
| 377 } | 379 } |
| 378 | 380 |
| 379 if (!path.empty() && path[0] != '#') { | 381 if (!path.empty() && path[0] != '#') { |
| 380 // A path under new-tab was requested; it's likely a bad relative | 382 // A path under new-tab was requested; it's likely a bad relative |
| 381 // URL from the new tab page, but in any case it's an error. | 383 // URL from the new tab page, but in any case it's an error. |
| 384 |
| 385 // TODO(dtrainor): Can remove this #if check once we update the |
| 386 // accessibility script to no longer try to access urls like |
| 387 // '?2314124523523'. |
| 388 // See http://crbug.com/150252. |
| 389 #if !defined(OS_ANDROID) |
| 382 NOTREACHED() << path << " should not have been requested on the NTP"; | 390 NOTREACHED() << path << " should not have been requested on the NTP"; |
| 391 #endif |
| 383 return; | 392 return; |
| 384 } | 393 } |
| 385 | 394 |
| 386 scoped_refptr<base::RefCountedMemory> html_bytes( | 395 scoped_refptr<base::RefCountedMemory> html_bytes( |
| 387 NTPResourceCacheFactory::GetForProfile(profile_)-> | 396 NTPResourceCacheFactory::GetForProfile(profile_)-> |
| 388 GetNewTabHTML(is_incognito)); | 397 GetNewTabHTML(is_incognito)); |
| 389 | 398 |
| 390 SendResponse(request_id, html_bytes); | 399 SendResponse(request_id, html_bytes); |
| 391 } | 400 } |
| 392 | 401 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 406 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, | 415 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, |
| 407 const char* mime_type, | 416 const char* mime_type, |
| 408 int resource_id) { | 417 int resource_id) { |
| 409 DCHECK(resource); | 418 DCHECK(resource); |
| 410 DCHECK(mime_type); | 419 DCHECK(mime_type); |
| 411 resource_map_[std::string(resource)] = | 420 resource_map_[std::string(resource)] = |
| 412 std::make_pair(std::string(mime_type), resource_id); | 421 std::make_pair(std::string(mime_type), resource_id); |
| 413 } | 422 } |
| 414 | 423 |
| 415 NewTabUI::NewTabHTMLSource::~NewTabHTMLSource() {} | 424 NewTabUI::NewTabHTMLSource::~NewTabHTMLSource() {} |
| OLD | NEW |