OLD | NEW |
1 // Copyright (c) 2011 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" |
17 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
18 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
19 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
20 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
21 #include "chrome/browser/defaults.h" | 22 #include "chrome/browser/defaults.h" |
22 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" |
23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/sessions/session_types.h" | 25 #include "chrome/browser/sessions/session_types.h" |
25 #include "chrome/browser/sync/profile_sync_service.h" | 26 #include "chrome/browser/sync/profile_sync_service.h" |
| 27 #include "chrome/browser/themes/theme_service_factory.h" |
26 #include "chrome/browser/themes/theme_service.h" | 28 #include "chrome/browser/themes/theme_service.h" |
27 #include "chrome/browser/themes/theme_service_factory.h" | |
28 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
29 #include "chrome/browser/ui/webui/metrics_handler.h" | 30 #include "chrome/browser/ui/webui/metrics_handler.h" |
30 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 31 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
31 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" | 32 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" |
32 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h" | 33 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h" |
33 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h" | 34 #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/new_tab_page_handler.h" |
35 #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" |
36 #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" |
37 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" | 39 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" |
38 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" | |
39 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h" | 40 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h" |
40 #include "chrome/browser/ui/webui/theme_source.h" | 41 #include "chrome/browser/ui/webui/theme_source.h" |
41 #include "chrome/common/chrome_notification_types.h" | 42 #include "chrome/common/chrome_notification_types.h" |
42 #include "chrome/common/chrome_switches.h" | 43 #include "chrome/common/chrome_switches.h" |
43 #include "chrome/common/extensions/extension.h" | 44 #include "chrome/common/extensions/extension.h" |
44 #include "chrome/common/pref_names.h" | 45 #include "chrome/common/pref_names.h" |
45 #include "chrome/common/url_constants.h" | 46 #include "chrome/common/url_constants.h" |
46 #include "content/browser/renderer_host/render_view_host.h" | 47 #include "content/browser/renderer_host/render_view_host.h" |
47 #include "content/public/browser/browser_thread.h" | 48 #include "content/public/browser/browser_thread.h" |
48 #include "content/public/browser/notification_service.h" | 49 #include "content/public/browser/notification_service.h" |
(...skipping 15 matching lines...) Expand all Loading... |
64 // finished. Observed times are in the ~1200ms range on Windows. | 65 // finished. Observed times are in the ~1200ms range on Windows. |
65 const int kTimeoutMs = 2000; | 66 const int kTimeoutMs = 2000; |
66 | 67 |
67 // Strings sent to the page via jstemplates used to set the direction of the | 68 // Strings sent to the page via jstemplates used to set the direction of the |
68 // HTML document based on locale. | 69 // HTML document based on locale. |
69 const char kRTLHtmlTextDirection[] = "rtl"; | 70 const char kRTLHtmlTextDirection[] = "rtl"; |
70 const char kLTRHtmlTextDirection[] = "ltr"; | 71 const char kLTRHtmlTextDirection[] = "ltr"; |
71 | 72 |
72 static base::LazyInstance<std::set<const WebUIController*> > g_live_new_tabs; | 73 static base::LazyInstance<std::set<const WebUIController*> > g_live_new_tabs; |
73 | 74 |
| 75 // The Web Store footer experiment FieldTrial name. |
| 76 const char kWebStoreLinkExperiment[] = "WebStoreLinkExperiment"; |
| 77 |
74 } // namespace | 78 } // namespace |
75 | 79 |
76 /////////////////////////////////////////////////////////////////////////////// | 80 /////////////////////////////////////////////////////////////////////////////// |
77 // NewTabUI | 81 // NewTabUI |
78 | 82 |
79 NewTabUI::NewTabUI(content::WebUI* web_ui) | 83 NewTabUI::NewTabUI(content::WebUI* web_ui) |
80 : WebUIController(web_ui) { | 84 : WebUIController(web_ui) { |
81 g_live_new_tabs.Pointer()->insert(this); | 85 g_live_new_tabs.Pointer()->insert(this); |
82 // Override some options on the Web UI. | 86 // Override some options on the Web UI. |
83 web_ui->HideFavicon(); | 87 web_ui->HideFavicon(); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 } | 213 } |
210 | 214 |
211 // static | 215 // static |
212 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { | 216 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { |
213 NewTabPageHandler::RegisterUserPrefs(prefs); | 217 NewTabPageHandler::RegisterUserPrefs(prefs); |
214 AppLauncherHandler::RegisterUserPrefs(prefs); | 218 AppLauncherHandler::RegisterUserPrefs(prefs); |
215 MostVisitedHandler::RegisterUserPrefs(prefs); | 219 MostVisitedHandler::RegisterUserPrefs(prefs); |
216 } | 220 } |
217 | 221 |
218 // static | 222 // static |
| 223 void NewTabUI::SetupFieldTrials() { |
| 224 scoped_refptr<base::FieldTrial> trial( |
| 225 new base::FieldTrial("WebStoreLinkExperiment", 1000, "Disabled", |
| 226 2012, 6, 1)); |
| 227 |
| 228 // Try to give the user a consistent experience, if possible. |
| 229 if (base::FieldTrialList::IsOneTimeRandomizationEnabled()) |
| 230 trial->UseOneTimeRandomization(); |
| 231 |
| 232 // 4% in Enabled group. |
| 233 trial->AppendGroup("Enabled", 40); |
| 234 } |
| 235 |
| 236 // static |
| 237 bool NewTabUI::IsWebStoreExperimentEnabled() { |
| 238 const CommandLine* cli = CommandLine::ForCurrentProcess(); |
| 239 if (cli->HasSwitch(switches::kEnableWebStoreLink)) |
| 240 return true; |
| 241 |
| 242 if (!base::FieldTrialList::TrialExists(kWebStoreLinkExperiment)) |
| 243 return false; |
| 244 |
| 245 return base::FieldTrialList::FindValue(kWebStoreLinkExperiment) != |
| 246 base::FieldTrial::kDefaultGroupNumber; |
| 247 } |
| 248 |
| 249 // static |
219 void NewTabUI::SetURLTitleAndDirection(DictionaryValue* dictionary, | 250 void NewTabUI::SetURLTitleAndDirection(DictionaryValue* dictionary, |
220 const string16& title, | 251 const string16& title, |
221 const GURL& gurl) { | 252 const GURL& gurl) { |
222 dictionary->SetString("url", gurl.spec()); | 253 dictionary->SetString("url", gurl.spec()); |
223 | 254 |
224 bool using_url_as_the_title = false; | 255 bool using_url_as_the_title = false; |
225 string16 title_to_set(title); | 256 string16 title_to_set(title); |
226 if (title_to_set.empty()) { | 257 if (title_to_set.empty()) { |
227 using_url_as_the_title = true; | 258 using_url_as_the_title = true; |
228 title_to_set = UTF8ToUTF16(gurl.spec()); | 259 title_to_set = UTF8ToUTF16(gurl.spec()); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 SendResponse(request_id, html_bytes); | 320 SendResponse(request_id, html_bytes); |
290 } | 321 } |
291 | 322 |
292 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { | 323 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { |
293 return "text/html"; | 324 return "text/html"; |
294 } | 325 } |
295 | 326 |
296 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { | 327 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { |
297 return false; | 328 return false; |
298 } | 329 } |
OLD | NEW |