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" | 17 #include "base/metrics/field_trial.h" |
18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
19 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
20 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
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/chrome_url_data_manager.h" |
30 #include "chrome/browser/ui/webui/metrics_handler.h" | 31 #include "chrome/browser/ui/webui/metrics_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/ntp_login_handler.h" | 36 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h" |
36 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" | 37 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" |
37 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" | 38 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" |
38 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h" | 39 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h" |
39 #include "chrome/browser/ui/webui/ntp/suggestions_page_handler.h" | 40 #include "chrome/browser/ui/webui/ntp/suggestions_page_handler.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 // These two resources should be loaded only if suggestions NTP is enabled. | 153 // These two resources should be loaded only if suggestions NTP is enabled. |
153 html_source->AddResource("suggestions_page.css", "text/css", | 154 html_source->AddResource("suggestions_page.css", "text/css", |
154 NewTabUI::IsSuggestionsPageEnabled() ? IDR_SUGGESTIONS_PAGE_CSS : 0); | 155 NewTabUI::IsSuggestionsPageEnabled() ? IDR_SUGGESTIONS_PAGE_CSS : 0); |
155 if (NewTabUI::IsSuggestionsPageEnabled()) { | 156 if (NewTabUI::IsSuggestionsPageEnabled()) { |
156 html_source->AddResource("suggestions_page.js", "application/javascript", | 157 html_source->AddResource("suggestions_page.js", "application/javascript", |
157 IDR_SUGGESTIONS_PAGE_JS); | 158 IDR_SUGGESTIONS_PAGE_JS); |
158 } | 159 } |
159 // ChromeURLDataManager assumes the ownership of the html_source and in some | 160 // ChromeURLDataManager assumes the ownership of the html_source and in some |
160 // tests immediately deletes it, so html_source should not be accessed after | 161 // tests immediately deletes it, so html_source should not be accessed after |
161 // this call. | 162 // this call. |
162 GetProfile()->GetChromeURLDataManager()->AddDataSource(html_source); | 163 Profile* profile = GetProfile(); |
| 164 ChromeURLDataManager::AddDataSource(profile, html_source); |
163 | 165 |
164 pref_change_registrar_.Init(GetProfile()->GetPrefs()); | 166 pref_change_registrar_.Init(GetProfile()->GetPrefs()); |
165 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); | 167 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); |
166 | 168 |
167 #if defined(ENABLE_THEMES) | 169 #if defined(ENABLE_THEMES) |
168 // Listen for theme installation. | 170 // Listen for theme installation. |
169 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 171 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
170 content::Source<ThemeService>( | 172 content::Source<ThemeService>( |
171 ThemeServiceFactory::GetForProfile(GetProfile()))); | 173 ThemeServiceFactory::GetForProfile(GetProfile()))); |
172 #endif | 174 #endif |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 } | 255 } |
254 default: | 256 default: |
255 CHECK(false) << "Unexpected notification: " << type; | 257 CHECK(false) << "Unexpected notification: " << type; |
256 } | 258 } |
257 } | 259 } |
258 | 260 |
259 void NewTabUI::InitializeCSSCaches() { | 261 void NewTabUI::InitializeCSSCaches() { |
260 #if defined(ENABLE_THEMES) | 262 #if defined(ENABLE_THEMES) |
261 Profile* profile = GetProfile(); | 263 Profile* profile = GetProfile(); |
262 ThemeSource* theme = new ThemeSource(profile); | 264 ThemeSource* theme = new ThemeSource(profile); |
263 profile->GetChromeURLDataManager()->AddDataSource(theme); | 265 ChromeURLDataManager::AddDataSource(profile, theme); |
264 #endif | 266 #endif |
265 } | 267 } |
266 | 268 |
267 // static | 269 // static |
268 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { | 270 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { |
269 NewTabPageHandler::RegisterUserPrefs(prefs); | 271 NewTabPageHandler::RegisterUserPrefs(prefs); |
270 #if !defined(OS_ANDROID) | 272 #if !defined(OS_ANDROID) |
271 AppLauncherHandler::RegisterUserPrefs(prefs); | 273 AppLauncherHandler::RegisterUserPrefs(prefs); |
272 #endif | 274 #endif |
273 MostVisitedHandler::RegisterUserPrefs(prefs); | 275 MostVisitedHandler::RegisterUserPrefs(prefs); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 } | 423 } |
422 | 424 |
423 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, | 425 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, |
424 const char* mime_type, | 426 const char* mime_type, |
425 int resource_id) { | 427 int resource_id) { |
426 DCHECK(resource); | 428 DCHECK(resource); |
427 DCHECK(mime_type); | 429 DCHECK(mime_type); |
428 resource_map_[std::string(resource)] = | 430 resource_map_[std::string(resource)] = |
429 std::make_pair(std::string(mime_type), resource_id); | 431 std::make_pair(std::string(mime_type), resource_id); |
430 } | 432 } |
OLD | NEW |