Chromium Code Reviews| 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 20 matching lines...) Expand all Loading... | |
| 31 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 31 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
| 32 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" | 32 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" |
| 33 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h" | 33 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h" |
| 34 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h" | 34 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h" |
| 35 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" | 35 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" |
| 36 #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h" | 36 #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h" |
| 37 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h" | 37 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h" |
| 38 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" | 38 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" |
| 39 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" | 39 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" |
| 40 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h" | 40 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h" |
| 41 #include "chrome/browser/ui/webui/ntp/suggested_page_handler.h" | |
| 41 #include "chrome/browser/ui/webui/theme_source.h" | 42 #include "chrome/browser/ui/webui/theme_source.h" |
| 42 #include "chrome/common/chrome_notification_types.h" | 43 #include "chrome/common/chrome_notification_types.h" |
| 43 #include "chrome/common/chrome_switches.h" | 44 #include "chrome/common/chrome_switches.h" |
| 44 #include "chrome/common/extensions/extension.h" | 45 #include "chrome/common/extensions/extension.h" |
| 45 #include "chrome/common/pref_names.h" | 46 #include "chrome/common/pref_names.h" |
| 46 #include "chrome/common/url_constants.h" | 47 #include "chrome/common/url_constants.h" |
| 47 #include "content/browser/renderer_host/render_view_host.h" | 48 #include "content/browser/renderer_host/render_view_host.h" |
| 48 #include "content/public/browser/browser_thread.h" | 49 #include "content/public/browser/browser_thread.h" |
| 49 #include "content/public/browser/notification_service.h" | 50 #include "content/public/browser/notification_service.h" |
| 50 #include "content/public/browser/user_metrics.h" | 51 #include "content/public/browser/user_metrics.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 web_ui->OverrideTitle(l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); | 93 web_ui->OverrideTitle(l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); |
| 93 | 94 |
| 94 // We count all link clicks as AUTO_BOOKMARK, so that site can be ranked more | 95 // We count all link clicks as AUTO_BOOKMARK, so that site can be ranked more |
| 95 // highly. Note this means we're including clicks on not only most visited | 96 // highly. Note this means we're including clicks on not only most visited |
| 96 // thumbnails, but also clicks on recently bookmarked. | 97 // thumbnails, but also clicks on recently bookmarked. |
| 97 web_ui->SetLinkTransitionType(content::PAGE_TRANSITION_AUTO_BOOKMARK); | 98 web_ui->SetLinkTransitionType(content::PAGE_TRANSITION_AUTO_BOOKMARK); |
| 98 | 99 |
| 99 if (!GetProfile()->IsOffTheRecord()) { | 100 if (!GetProfile()->IsOffTheRecord()) { |
| 100 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); | 101 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); |
| 101 web_ui->AddMessageHandler(new MostVisitedHandler()); | 102 web_ui->AddMessageHandler(new MostVisitedHandler()); |
| 103 web_ui->AddMessageHandler(new SuggestedHandler()); | |
| 102 web_ui->AddMessageHandler(new RecentlyClosedTabsHandler()); | 104 web_ui->AddMessageHandler(new RecentlyClosedTabsHandler()); |
| 103 web_ui->AddMessageHandler(new MetricsHandler()); | 105 web_ui->AddMessageHandler(new MetricsHandler()); |
| 104 if (GetProfile()->IsSyncAccessible()) | 106 if (GetProfile()->IsSyncAccessible()) |
| 105 web_ui->AddMessageHandler(new NewTabPageSyncHandler()); | 107 web_ui->AddMessageHandler(new NewTabPageSyncHandler()); |
| 106 ExtensionService* service = GetProfile()->GetExtensionService(); | 108 ExtensionService* service = GetProfile()->GetExtensionService(); |
| 107 // We might not have an ExtensionService (on ChromeOS when not logged in | 109 // We might not have an ExtensionService (on ChromeOS when not logged in |
| 108 // for example). | 110 // for example). |
| 109 if (service) | 111 if (service) |
| 110 web_ui->AddMessageHandler(new AppLauncherHandler(service)); | 112 web_ui->AddMessageHandler(new AppLauncherHandler(service)); |
| 111 | 113 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 Profile* profile = GetProfile(); | 213 Profile* profile = GetProfile(); |
| 212 ThemeSource* theme = new ThemeSource(profile); | 214 ThemeSource* theme = new ThemeSource(profile); |
| 213 profile->GetChromeURLDataManager()->AddDataSource(theme); | 215 profile->GetChromeURLDataManager()->AddDataSource(theme); |
| 214 } | 216 } |
| 215 | 217 |
| 216 // static | 218 // static |
| 217 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { | 219 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { |
| 218 NewTabPageHandler::RegisterUserPrefs(prefs); | 220 NewTabPageHandler::RegisterUserPrefs(prefs); |
| 219 AppLauncherHandler::RegisterUserPrefs(prefs); | 221 AppLauncherHandler::RegisterUserPrefs(prefs); |
| 220 MostVisitedHandler::RegisterUserPrefs(prefs); | 222 MostVisitedHandler::RegisterUserPrefs(prefs); |
| 223 SuggestedHandler::RegisterUserPrefs(prefs); | |
| 221 } | 224 } |
| 222 | 225 |
| 223 // static | 226 // static |
| 224 void NewTabUI::SetupFieldTrials() { | 227 void NewTabUI::SetupFieldTrials() { |
| 225 scoped_refptr<base::FieldTrial> trial( | 228 scoped_refptr<base::FieldTrial> trial( |
| 226 new base::FieldTrial("WebStoreLinkExperiment", 1000, "Disabled", | 229 new base::FieldTrial("WebStoreLinkExperiment", 1000, "Disabled", |
| 227 2012, 6, 1)); | 230 2012, 6, 1)); |
| 228 | 231 |
| 229 // Try to give the user a consistent experience, if possible. | 232 // Try to give the user a consistent experience, if possible. |
| 230 if (base::FieldTrialList::IsOneTimeRandomizationEnabled()) | 233 if (base::FieldTrialList::IsOneTimeRandomizationEnabled()) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 241 return true; | 244 return true; |
| 242 | 245 |
| 243 if (!base::FieldTrialList::TrialExists(kWebStoreLinkExperiment)) | 246 if (!base::FieldTrialList::TrialExists(kWebStoreLinkExperiment)) |
| 244 return false; | 247 return false; |
| 245 | 248 |
| 246 return base::FieldTrialList::FindValue(kWebStoreLinkExperiment) != | 249 return base::FieldTrialList::FindValue(kWebStoreLinkExperiment) != |
| 247 base::FieldTrial::kDefaultGroupNumber; | 250 base::FieldTrial::kDefaultGroupNumber; |
| 248 } | 251 } |
| 249 | 252 |
| 250 // static | 253 // static |
| 254 bool NewTabUI::IsSuggestedPageEnabled() { | |
| 255 const CommandLine* cli = CommandLine::ForCurrentProcess(); | |
| 256 if (cli->HasSwitch(switches::kEnableSuggestedTabPage)) | |
| 257 return true; | |
| 258 return false; | |
|
Dan Beam
2012/02/09 01:43:06
why not
return CommandLine::ForCurrentProcess()-
GeorgeY
2012/02/10 00:00:36
sure
| |
| 259 } | |
| 260 | |
| 261 // static | |
| 251 void NewTabUI::SetURLTitleAndDirection(DictionaryValue* dictionary, | 262 void NewTabUI::SetURLTitleAndDirection(DictionaryValue* dictionary, |
| 252 const string16& title, | 263 const string16& title, |
| 253 const GURL& gurl) { | 264 const GURL& gurl) { |
| 254 dictionary->SetString("url", gurl.spec()); | 265 dictionary->SetString("url", gurl.spec()); |
| 255 | 266 |
| 256 bool using_url_as_the_title = false; | 267 bool using_url_as_the_title = false; |
| 257 string16 title_to_set(title); | 268 string16 title_to_set(title); |
| 258 if (title_to_set.empty()) { | 269 if (title_to_set.empty()) { |
| 259 using_url_as_the_title = true; | 270 using_url_as_the_title = true; |
| 260 title_to_set = UTF8ToUTF16(gurl.spec()); | 271 title_to_set = UTF8ToUTF16(gurl.spec()); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 SendResponse(request_id, html_bytes); | 332 SendResponse(request_id, html_bytes); |
| 322 } | 333 } |
| 323 | 334 |
| 324 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { | 335 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { |
| 325 return "text/html"; | 336 return "text/html"; |
| 326 } | 337 } |
| 327 | 338 |
| 328 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { | 339 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { |
| 329 return false; | 340 return false; |
| 330 } | 341 } |
| OLD | NEW |