| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "chrome/browser/ui/webui/ntp/bookmarks_handler.h" | 28 #include "chrome/browser/ui/webui/ntp/bookmarks_handler.h" |
| 29 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" | 29 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" |
| 30 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h" | 30 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h" |
| 31 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h" | 31 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h" |
| 32 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" | 32 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" |
| 33 #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h" | 33 #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h" |
| 34 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h" | 34 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h" |
| 35 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" | 35 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" |
| 36 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" | 36 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" |
| 37 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h" | 37 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h" |
| 38 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h" | |
| 39 #include "chrome/browser/ui/webui/theme_source.h" | 38 #include "chrome/browser/ui/webui/theme_source.h" |
| 40 #include "chrome/common/chrome_notification_types.h" | 39 #include "chrome/common/chrome_notification_types.h" |
| 41 #include "chrome/common/chrome_switches.h" | 40 #include "chrome/common/chrome_switches.h" |
| 42 #include "chrome/common/extensions/extension.h" | 41 #include "chrome/common/extensions/extension.h" |
| 43 #include "chrome/common/pref_names.h" | 42 #include "chrome/common/pref_names.h" |
| 44 #include "chrome/common/url_constants.h" | 43 #include "chrome/common/url_constants.h" |
| 45 #include "content/browser/renderer_host/render_view_host.h" | 44 #include "content/browser/renderer_host/render_view_host.h" |
| 46 #include "content/browser/tab_contents/tab_contents.h" | 45 #include "content/browser/tab_contents/tab_contents.h" |
| 47 #include "content/browser/user_metrics.h" | 46 #include "content/browser/user_metrics.h" |
| 48 #include "content/public/browser/browser_thread.h" | 47 #include "content/public/browser/browser_thread.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 75 focus_location_bar_by_default_ = true; | 74 focus_location_bar_by_default_ = true; |
| 76 should_hide_url_ = true; | 75 should_hide_url_ = true; |
| 77 overridden_title_ = l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); | 76 overridden_title_ = l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); |
| 78 | 77 |
| 79 // We count all link clicks as AUTO_BOOKMARK, so that site can be ranked more | 78 // We count all link clicks as AUTO_BOOKMARK, so that site can be ranked more |
| 80 // highly. Note this means we're including clicks on not only most visited | 79 // highly. Note this means we're including clicks on not only most visited |
| 81 // thumbnails, but also clicks on recently bookmarked. | 80 // thumbnails, but also clicks on recently bookmarked. |
| 82 link_transition_type_ = content::PAGE_TRANSITION_AUTO_BOOKMARK; | 81 link_transition_type_ = content::PAGE_TRANSITION_AUTO_BOOKMARK; |
| 83 | 82 |
| 84 if (!GetProfile()->IsOffTheRecord()) { | 83 if (!GetProfile()->IsOffTheRecord()) { |
| 85 PrefService* pref_service = GetProfile()->GetPrefs(); | |
| 86 AddMessageHandler((new ShownSectionsHandler(pref_service))->Attach(this)); | |
| 87 AddMessageHandler((new browser_sync::ForeignSessionHandler())-> | 84 AddMessageHandler((new browser_sync::ForeignSessionHandler())-> |
| 88 Attach(this)); | 85 Attach(this)); |
| 89 AddMessageHandler((new MostVisitedHandler())->Attach(this)); | 86 AddMessageHandler((new MostVisitedHandler())->Attach(this)); |
| 90 AddMessageHandler((new RecentlyClosedTabsHandler())->Attach(this)); | 87 AddMessageHandler((new RecentlyClosedTabsHandler())->Attach(this)); |
| 91 AddMessageHandler((new MetricsHandler())->Attach(this)); | 88 AddMessageHandler((new MetricsHandler())->Attach(this)); |
| 92 if (GetProfile()->IsSyncAccessible()) | 89 if (GetProfile()->IsSyncAccessible()) |
| 93 AddMessageHandler((new NewTabPageSyncHandler())->Attach(this)); | 90 AddMessageHandler((new NewTabPageSyncHandler())->Attach(this)); |
| 94 ExtensionService* service = GetProfile()->GetExtensionService(); | 91 ExtensionService* service = GetProfile()->GetExtensionService(); |
| 95 // We might not have an ExtensionService (on ChromeOS when not logged in | 92 // We might not have an ExtensionService (on ChromeOS when not logged in |
| 96 // for example). | 93 // for example). |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 215 } |
| 219 | 216 |
| 220 void NewTabUI::InitializeCSSCaches() { | 217 void NewTabUI::InitializeCSSCaches() { |
| 221 Profile* profile = GetProfile(); | 218 Profile* profile = GetProfile(); |
| 222 ThemeSource* theme = new ThemeSource(profile); | 219 ThemeSource* theme = new ThemeSource(profile); |
| 223 profile->GetChromeURLDataManager()->AddDataSource(theme); | 220 profile->GetChromeURLDataManager()->AddDataSource(theme); |
| 224 } | 221 } |
| 225 | 222 |
| 226 // static | 223 // static |
| 227 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { | 224 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { |
| 228 prefs->RegisterIntegerPref(prefs::kNTPPrefVersion, | |
| 229 0, | |
| 230 PrefService::UNSYNCABLE_PREF); | |
| 231 | |
| 232 NewTabPageHandler::RegisterUserPrefs(prefs); | 225 NewTabPageHandler::RegisterUserPrefs(prefs); |
| 233 AppLauncherHandler::RegisterUserPrefs(prefs); | 226 AppLauncherHandler::RegisterUserPrefs(prefs); |
| 234 MostVisitedHandler::RegisterUserPrefs(prefs); | 227 MostVisitedHandler::RegisterUserPrefs(prefs); |
| 235 ShownSectionsHandler::RegisterUserPrefs(prefs); | |
| 236 if (NTP4Enabled()) | 228 if (NTP4Enabled()) |
| 237 BookmarksHandler::RegisterUserPrefs(prefs); | 229 BookmarksHandler::RegisterUserPrefs(prefs); |
| 238 | |
| 239 UpdateUserPrefsVersion(prefs); | |
| 240 } | 230 } |
| 241 | 231 |
| 242 // static | 232 // static |
| 243 bool NewTabUI::UpdateUserPrefsVersion(PrefService* prefs) { | |
| 244 const int old_pref_version = prefs->GetInteger(prefs::kNTPPrefVersion); | |
| 245 if (old_pref_version != current_pref_version()) { | |
| 246 MigrateUserPrefs(prefs, old_pref_version, current_pref_version()); | |
| 247 prefs->SetInteger(prefs::kNTPPrefVersion, current_pref_version()); | |
| 248 return true; | |
| 249 } | |
| 250 return false; | |
| 251 } | |
| 252 | |
| 253 // static | |
| 254 void NewTabUI::MigrateUserPrefs(PrefService* prefs, int old_pref_version, | |
| 255 int new_pref_version) { | |
| 256 ShownSectionsHandler::MigrateUserPrefs(prefs, old_pref_version, | |
| 257 current_pref_version()); | |
| 258 } | |
| 259 | |
| 260 // static | |
| 261 void NewTabUI::SetURLTitleAndDirection(DictionaryValue* dictionary, | 233 void NewTabUI::SetURLTitleAndDirection(DictionaryValue* dictionary, |
| 262 const string16& title, | 234 const string16& title, |
| 263 const GURL& gurl) { | 235 const GURL& gurl) { |
| 264 dictionary->SetString("url", gurl.spec()); | 236 dictionary->SetString("url", gurl.spec()); |
| 265 | 237 |
| 266 bool using_url_as_the_title = false; | 238 bool using_url_as_the_title = false; |
| 267 string16 title_to_set(title); | 239 string16 title_to_set(title); |
| 268 if (title_to_set.empty()) { | 240 if (title_to_set.empty()) { |
| 269 using_url_as_the_title = true; | 241 using_url_as_the_title = true; |
| 270 title_to_set = UTF8ToUTF16(gurl.spec()); | 242 title_to_set = UTF8ToUTF16(gurl.spec()); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 SendResponse(request_id, html_bytes); | 309 SendResponse(request_id, html_bytes); |
| 338 } | 310 } |
| 339 | 311 |
| 340 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { | 312 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { |
| 341 return "text/html"; | 313 return "text/html"; |
| 342 } | 314 } |
| 343 | 315 |
| 344 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { | 316 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { |
| 345 return false; | 317 return false; |
| 346 } | 318 } |
| OLD | NEW |