| 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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
| 15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 16 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
| 17 #include "base/metrics/field_trial.h" | |
| 18 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 19 #include "base/string_number_conversions.h" | 18 #include "base/string_number_conversions.h" |
| 20 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
| 21 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
| 22 #include "chrome/browser/defaults.h" | 21 #include "chrome/browser/defaults.h" |
| 23 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/sessions/session_types.h" | 24 #include "chrome/browser/sessions/session_types.h" |
| 26 #include "chrome/browser/sync/profile_sync_service.h" | 25 #include "chrome/browser/sync/profile_sync_service.h" |
| 27 #include "chrome/browser/themes/theme_service.h" | 26 #include "chrome/browser/themes/theme_service.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 // finished. Observed times are in the ~1200ms range on Windows. | 71 // finished. Observed times are in the ~1200ms range on Windows. |
| 73 const int kTimeoutMs = 2000; | 72 const int kTimeoutMs = 2000; |
| 74 | 73 |
| 75 // Strings sent to the page via jstemplates used to set the direction of the | 74 // Strings sent to the page via jstemplates used to set the direction of the |
| 76 // HTML document based on locale. | 75 // HTML document based on locale. |
| 77 const char kRTLHtmlTextDirection[] = "rtl"; | 76 const char kRTLHtmlTextDirection[] = "rtl"; |
| 78 const char kLTRHtmlTextDirection[] = "ltr"; | 77 const char kLTRHtmlTextDirection[] = "ltr"; |
| 79 | 78 |
| 80 static base::LazyInstance<std::set<const WebUIController*> > g_live_new_tabs; | 79 static base::LazyInstance<std::set<const WebUIController*> > g_live_new_tabs; |
| 81 | 80 |
| 82 // Group IDs for the web store link field trial. | |
| 83 int g_footer_group = 0; | |
| 84 int g_hint_group = 0; | |
| 85 | |
| 86 bool WebStoreLinkExperimentGroupIs(int group) { | |
| 87 return base::FieldTrialList::TrialExists(kWebStoreLinkExperiment) && | |
| 88 base::FieldTrialList::FindValue(kWebStoreLinkExperiment) == group; | |
| 89 } | |
| 90 | |
| 91 } // namespace | 81 } // namespace |
| 92 | 82 |
| 93 // The Web Store footer experiment FieldTrial name. | |
| 94 const char kWebStoreLinkExperiment[] = "WebStoreLinkExperiment"; | |
| 95 | |
| 96 /////////////////////////////////////////////////////////////////////////////// | 83 /////////////////////////////////////////////////////////////////////////////// |
| 97 // NewTabUI | 84 // NewTabUI |
| 98 | 85 |
| 99 NewTabUI::NewTabUI(content::WebUI* web_ui) | 86 NewTabUI::NewTabUI(content::WebUI* web_ui) |
| 100 : WebUIController(web_ui), | 87 : WebUIController(web_ui), |
| 101 showing_sync_bubble_(false) { | 88 showing_sync_bubble_(false) { |
| 102 g_live_new_tabs.Pointer()->insert(this); | 89 g_live_new_tabs.Pointer()->insert(this); |
| 103 // Override some options on the Web UI. | 90 // Override some options on the Web UI. |
| 104 web_ui->HideFavicon(); | 91 web_ui->HideFavicon(); |
| 105 | 92 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 NewTabPageHandler::RegisterUserPrefs(prefs); | 265 NewTabPageHandler::RegisterUserPrefs(prefs); |
| 279 #if !defined(OS_ANDROID) | 266 #if !defined(OS_ANDROID) |
| 280 AppLauncherHandler::RegisterUserPrefs(prefs); | 267 AppLauncherHandler::RegisterUserPrefs(prefs); |
| 281 #endif | 268 #endif |
| 282 MostVisitedHandler::RegisterUserPrefs(prefs); | 269 MostVisitedHandler::RegisterUserPrefs(prefs); |
| 283 if (NewTabUI::IsSuggestionsPageEnabled()) | 270 if (NewTabUI::IsSuggestionsPageEnabled()) |
| 284 SuggestionsHandler::RegisterUserPrefs(prefs); | 271 SuggestionsHandler::RegisterUserPrefs(prefs); |
| 285 } | 272 } |
| 286 | 273 |
| 287 // static | 274 // static |
| 288 void NewTabUI::SetupFieldTrials() { | |
| 289 scoped_refptr<base::FieldTrial> trial( | |
| 290 base::FieldTrialList::FactoryGetFieldTrial( | |
| 291 kWebStoreLinkExperiment, 1, "Disabled", 2025, 6, 1, NULL)); | |
| 292 | |
| 293 // Try to give the user a consistent experience, if possible. | |
| 294 if (base::FieldTrialList::IsOneTimeRandomizationEnabled()) | |
| 295 trial->UseOneTimeRandomization(); | |
| 296 | |
| 297 // 33.3% in each group. | |
| 298 g_footer_group = trial->AppendGroup("FooterLink", 1); | |
| 299 g_hint_group = trial->AppendGroup("PlusIcon", 0); | |
| 300 } | |
| 301 | |
| 302 // static | |
| 303 bool NewTabUI::ShouldShowWebStoreFooterLink() { | |
| 304 const CommandLine* cli = CommandLine::ForCurrentProcess(); | |
| 305 return cli->HasSwitch(switches::kEnableWebStoreLink) || | |
| 306 WebStoreLinkExperimentGroupIs(g_footer_group); | |
| 307 } | |
| 308 | |
| 309 // static | |
| 310 bool NewTabUI::ShouldShowAppInstallHint() { | |
| 311 const CommandLine* cli = CommandLine::ForCurrentProcess(); | |
| 312 return cli->HasSwitch(switches::kNtpAppInstallHint) || | |
| 313 WebStoreLinkExperimentGroupIs(g_hint_group); | |
| 314 } | |
| 315 | |
| 316 // static | |
| 317 bool NewTabUI::ShouldShowApps() { | 275 bool NewTabUI::ShouldShowApps() { |
| 318 #if defined(USE_ASH) || defined(OS_ANDROID) | 276 #if defined(USE_ASH) || defined(OS_ANDROID) |
| 319 // Ash shows apps in app list thus should not show apps page in NTP4. | 277 // Ash shows apps in app list thus should not show apps page in NTP4. |
| 320 // Android does not have apps. | 278 // Android does not have apps. |
| 321 return false; | 279 return false; |
| 322 #else | 280 #else |
| 323 return true; | 281 return true; |
| 324 #endif | 282 #endif |
| 325 } | 283 } |
| 326 | 284 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 } | 388 } |
| 431 | 389 |
| 432 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, | 390 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, |
| 433 const char* mime_type, | 391 const char* mime_type, |
| 434 int resource_id) { | 392 int resource_id) { |
| 435 DCHECK(resource); | 393 DCHECK(resource); |
| 436 DCHECK(mime_type); | 394 DCHECK(mime_type); |
| 437 resource_map_[std::string(resource)] = | 395 resource_map_[std::string(resource)] = |
| 438 std::make_pair(std::string(mime_type), resource_id); | 396 std::make_pair(std::string(mime_type), resource_id); |
| 439 } | 397 } |
| OLD | NEW |