| 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 10 matching lines...) Expand all Loading... |
| 21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
| 22 #include "chrome/browser/defaults.h" | 22 #include "chrome/browser/defaults.h" |
| 23 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/sessions/session_types.h" | 25 #include "chrome/browser/sessions/session_types.h" |
| 26 #include "chrome/browser/sync/profile_sync_service.h" | 26 #include "chrome/browser/sync/profile_sync_service.h" |
| 27 #include "chrome/browser/themes/theme_service.h" | 27 #include "chrome/browser/themes/theme_service.h" |
| 28 #include "chrome/browser/themes/theme_service_factory.h" | 28 #include "chrome/browser/themes/theme_service_factory.h" |
| 29 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.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/app_launcher_handler.h" | |
| 32 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" | 31 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" |
| 33 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h" | 32 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h" |
| 34 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h" | 33 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h" |
| 35 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" | 34 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" |
| 36 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h" | 35 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h" |
| 37 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" | 36 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" |
| 38 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" | 37 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" |
| 39 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h" | 38 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h" |
| 40 #include "chrome/browser/ui/webui/ntp/suggestions_page_handler.h" | 39 #include "chrome/browser/ui/webui/ntp/suggestions_page_handler.h" |
| 41 #include "chrome/browser/ui/webui/theme_source.h" | 40 #include "chrome/browser/ui/webui/theme_source.h" |
| 42 #include "chrome/common/chrome_notification_types.h" | 41 #include "chrome/common/chrome_notification_types.h" |
| 43 #include "chrome/common/chrome_switches.h" | 42 #include "chrome/common/chrome_switches.h" |
| 44 #include "chrome/common/extensions/extension.h" | 43 #include "chrome/common/extensions/extension.h" |
| 45 #include "chrome/common/pref_names.h" | 44 #include "chrome/common/pref_names.h" |
| 46 #include "chrome/common/url_constants.h" | 45 #include "chrome/common/url_constants.h" |
| 47 #include "content/public/browser/browser_thread.h" | 46 #include "content/public/browser/browser_thread.h" |
| 48 #include "content/public/browser/notification_service.h" | 47 #include "content/public/browser/notification_service.h" |
| 49 #include "content/public/browser/render_view_host.h" | 48 #include "content/public/browser/render_view_host.h" |
| 50 #include "content/public/browser/user_metrics.h" | 49 #include "content/public/browser/user_metrics.h" |
| 51 #include "content/public/browser/web_contents.h" | 50 #include "content/public/browser/web_contents.h" |
| 52 #include "content/public/browser/web_ui.h" | 51 #include "content/public/browser/web_ui.h" |
| 53 #include "grit/browser_resources.h" | 52 #include "grit/browser_resources.h" |
| 54 #include "grit/generated_resources.h" | 53 #include "grit/generated_resources.h" |
| 55 #include "grit/theme_resources.h" | 54 #include "grit/theme_resources.h" |
| 56 #include "ui/base/l10n/l10n_util.h" | 55 #include "ui/base/l10n/l10n_util.h" |
| 57 | 56 |
| 58 #if !defined(OS_ANDROID) | 57 #if !defined(OS_ANDROID) |
| 58 #include "chrome/browser/ui/webui/ntp/app_launcher_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 #endif | 60 #endif |
| 61 | 61 |
| 62 using content::BrowserThread; | 62 using content::BrowserThread; |
| 63 using content::RenderViewHost; | 63 using content::RenderViewHost; |
| 64 using content::UserMetricsAction; | 64 using content::UserMetricsAction; |
| 65 using content::WebContents; | 65 using content::WebContents; |
| 66 using content::WebUIController; | 66 using content::WebUIController; |
| 67 | 67 |
| 68 namespace { | 68 namespace { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); | 115 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); |
| 116 web_ui->AddMessageHandler(new MostVisitedHandler()); | 116 web_ui->AddMessageHandler(new MostVisitedHandler()); |
| 117 if (NewTabUI::IsSuggestionsPageEnabled()) | 117 if (NewTabUI::IsSuggestionsPageEnabled()) |
| 118 web_ui->AddMessageHandler(new SuggestionsHandler()); | 118 web_ui->AddMessageHandler(new SuggestionsHandler()); |
| 119 web_ui->AddMessageHandler(new RecentlyClosedTabsHandler()); | 119 web_ui->AddMessageHandler(new RecentlyClosedTabsHandler()); |
| 120 web_ui->AddMessageHandler(new MetricsHandler()); | 120 web_ui->AddMessageHandler(new MetricsHandler()); |
| 121 #if !defined(OS_ANDROID) | 121 #if !defined(OS_ANDROID) |
| 122 // Android doesn't have a sync promo/username on NTP. | 122 // Android doesn't have a sync promo/username on NTP. |
| 123 if (GetProfile()->IsSyncAccessible()) | 123 if (GetProfile()->IsSyncAccessible()) |
| 124 web_ui->AddMessageHandler(new NewTabPageSyncHandler()); | 124 web_ui->AddMessageHandler(new NewTabPageSyncHandler()); |
| 125 #endif | |
| 126 | 125 |
| 126 // Or apps. |
| 127 if (ShouldShowApps()) { | 127 if (ShouldShowApps()) { |
| 128 ExtensionService* service = GetProfile()->GetExtensionService(); | 128 ExtensionService* service = GetProfile()->GetExtensionService(); |
| 129 // We might not have an ExtensionService (on ChromeOS when not logged in | 129 // We might not have an ExtensionService (on ChromeOS when not logged in |
| 130 // for example). | 130 // for example). |
| 131 if (service) | 131 if (service) |
| 132 web_ui->AddMessageHandler(new AppLauncherHandler(service)); | 132 web_ui->AddMessageHandler(new AppLauncherHandler(service)); |
| 133 } | 133 } |
| 134 #endif |
| 134 | 135 |
| 135 web_ui->AddMessageHandler(new NewTabPageHandler()); | 136 web_ui->AddMessageHandler(new NewTabPageHandler()); |
| 136 web_ui->AddMessageHandler(new FaviconWebUIHandler()); | 137 web_ui->AddMessageHandler(new FaviconWebUIHandler()); |
| 137 } | 138 } |
| 138 | 139 |
| 139 #if !defined(OS_ANDROID) | 140 #if !defined(OS_ANDROID) |
| 140 // Android uses native UI for sync setup. | 141 // Android uses native UI for sync setup. |
| 141 if (NTPLoginHandler::ShouldShow(GetProfile())) | 142 if (NTPLoginHandler::ShouldShow(GetProfile())) |
| 142 web_ui->AddMessageHandler(new NTPLoginHandler()); | 143 web_ui->AddMessageHandler(new NTPLoginHandler()); |
| 143 #endif | 144 #endif |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 #if defined(ENABLE_THEMES) | 260 #if defined(ENABLE_THEMES) |
| 260 Profile* profile = GetProfile(); | 261 Profile* profile = GetProfile(); |
| 261 ThemeSource* theme = new ThemeSource(profile); | 262 ThemeSource* theme = new ThemeSource(profile); |
| 262 profile->GetChromeURLDataManager()->AddDataSource(theme); | 263 profile->GetChromeURLDataManager()->AddDataSource(theme); |
| 263 #endif | 264 #endif |
| 264 } | 265 } |
| 265 | 266 |
| 266 // static | 267 // static |
| 267 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { | 268 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { |
| 268 NewTabPageHandler::RegisterUserPrefs(prefs); | 269 NewTabPageHandler::RegisterUserPrefs(prefs); |
| 270 #if !defined(OS_ANDROID) |
| 269 AppLauncherHandler::RegisterUserPrefs(prefs); | 271 AppLauncherHandler::RegisterUserPrefs(prefs); |
| 272 #endif |
| 270 MostVisitedHandler::RegisterUserPrefs(prefs); | 273 MostVisitedHandler::RegisterUserPrefs(prefs); |
| 271 if (NewTabUI::IsSuggestionsPageEnabled()) | 274 if (NewTabUI::IsSuggestionsPageEnabled()) |
| 272 SuggestionsHandler::RegisterUserPrefs(prefs); | 275 SuggestionsHandler::RegisterUserPrefs(prefs); |
| 273 } | 276 } |
| 274 | 277 |
| 275 // static | 278 // static |
| 276 void NewTabUI::SetupFieldTrials() { | 279 void NewTabUI::SetupFieldTrials() { |
| 277 scoped_refptr<base::FieldTrial> trial( | 280 scoped_refptr<base::FieldTrial> trial( |
| 278 base::FieldTrialList::FactoryGetFieldTrial( | 281 base::FieldTrialList::FactoryGetFieldTrial( |
| 279 kWebStoreLinkExperiment, 3, "Disabled", 2012, 6, 1, NULL)); | 282 kWebStoreLinkExperiment, 3, "Disabled", 2012, 6, 1, NULL)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 296 | 299 |
| 297 // static | 300 // static |
| 298 bool NewTabUI::ShouldShowAppInstallHint() { | 301 bool NewTabUI::ShouldShowAppInstallHint() { |
| 299 const CommandLine* cli = CommandLine::ForCurrentProcess(); | 302 const CommandLine* cli = CommandLine::ForCurrentProcess(); |
| 300 return cli->HasSwitch(switches::kNtpAppInstallHint) || | 303 return cli->HasSwitch(switches::kNtpAppInstallHint) || |
| 301 WebStoreLinkExperimentGroupIs(g_hint_group); | 304 WebStoreLinkExperimentGroupIs(g_hint_group); |
| 302 } | 305 } |
| 303 | 306 |
| 304 // static | 307 // static |
| 305 bool NewTabUI::ShouldShowApps() { | 308 bool NewTabUI::ShouldShowApps() { |
| 306 #if defined(USE_ASH) | 309 #if defined(USE_ASH) || defined(OS_ANDROID) |
| 307 // Ash shows apps in app list thus should not show apps page in NTP4. | 310 // Ash shows apps in app list thus should not show apps page in NTP4. |
| 311 // Android does not have apps. |
| 308 return false; | 312 return false; |
| 309 #else | 313 #else |
| 310 return true; | 314 return true; |
| 311 #endif | 315 #endif |
| 312 } | 316 } |
| 313 | 317 |
| 314 // static | 318 // static |
| 315 bool NewTabUI::IsSuggestionsPageEnabled() { | 319 bool NewTabUI::IsSuggestionsPageEnabled() { |
| 316 return CommandLine::ForCurrentProcess()->HasSwitch( | 320 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 317 switches::kEnableSuggestionsTabPage); | 321 switches::kEnableSuggestionsTabPage); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 } | 421 } |
| 418 | 422 |
| 419 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, | 423 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, |
| 420 const char* mime_type, | 424 const char* mime_type, |
| 421 int resource_id) { | 425 int resource_id) { |
| 422 DCHECK(resource); | 426 DCHECK(resource); |
| 423 DCHECK(mime_type); | 427 DCHECK(mime_type); |
| 424 resource_map_[std::string(resource)] = | 428 resource_map_[std::string(resource)] = |
| 425 std::make_pair(std::string(mime_type), resource_id); | 429 std::make_pair(std::string(mime_type), resource_id); |
| 426 } | 430 } |
| OLD | NEW |