| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/dom_ui/new_tab_ui.h" | 7 #include "chrome/browser/dom_ui/new_tab_ui.h" |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/histogram.h" | 14 #include "base/histogram.h" |
| 15 #include "base/i18n/rtl.h" | 15 #include "base/i18n/rtl.h" |
| 16 #include "base/singleton.h" | 16 #include "base/singleton.h" |
| 17 #include "base/thread.h" | 17 #include "base/thread.h" |
| 18 #include "chrome/browser/browser.h" | 18 #include "chrome/browser/browser.h" |
| 19 #include "chrome/browser/chrome_thread.h" | 19 #include "chrome/browser/chrome_thread.h" |
| 20 #include "chrome/browser/dom_ui/app_launcher_handler.h" | 20 #include "chrome/browser/dom_ui/app_launcher_handler.h" |
| 21 #include "chrome/browser/dom_ui/dom_ui_theme_source.h" | 21 #include "chrome/browser/dom_ui/dom_ui_theme_source.h" |
| 22 #include "chrome/browser/dom_ui/most_visited_handler.h" | 22 #include "chrome/browser/dom_ui/most_visited_handler.h" |
| 23 #include "chrome/browser/dom_ui/new_tab_page_sync_handler.h" | 23 #include "chrome/browser/dom_ui/new_tab_page_sync_handler.h" |
| 24 #include "chrome/browser/dom_ui/ntp_resource_cache.h" | 24 #include "chrome/browser/dom_ui/ntp_resource_cache.h" |
| 25 #include "chrome/browser/dom_ui/shown_sections_handler.h" | 25 #include "chrome/browser/dom_ui/shown_sections_handler.h" |
| 26 #include "chrome/browser/dom_ui/tips_handler.h" | |
| 27 #include "chrome/browser/metrics/user_metrics.h" | 26 #include "chrome/browser/metrics/user_metrics.h" |
| 28 #include "chrome/browser/pref_service.h" | 27 #include "chrome/browser/pref_service.h" |
| 29 #include "chrome/browser/profile.h" | 28 #include "chrome/browser/profile.h" |
| 30 #include "chrome/browser/renderer_host/render_view_host.h" | 29 #include "chrome/browser/renderer_host/render_view_host.h" |
| 31 #include "chrome/browser/sessions/session_types.h" | 30 #include "chrome/browser/sessions/session_types.h" |
| 32 #include "chrome/browser/sessions/tab_restore_service.h" | 31 #include "chrome/browser/sessions/tab_restore_service.h" |
| 33 #include "chrome/browser/sync/profile_sync_service.h" | 32 #include "chrome/browser/sync/profile_sync_service.h" |
| 34 #include "chrome/browser/tab_contents/tab_contents.h" | 33 #include "chrome/browser/tab_contents/tab_contents.h" |
| 35 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
| 36 #include "chrome/common/notification_service.h" | 35 #include "chrome/common/notification_service.h" |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 if (first_view) { | 455 if (first_view) { |
| 457 first_view = false; | 456 first_view = false; |
| 458 } | 457 } |
| 459 | 458 |
| 460 if (!GetProfile()->IsOffTheRecord()) { | 459 if (!GetProfile()->IsOffTheRecord()) { |
| 461 PrefService* pref_service = GetProfile()->GetPrefs(); | 460 PrefService* pref_service = GetProfile()->GetPrefs(); |
| 462 AddMessageHandler((new ShownSectionsHandler(pref_service))->Attach(this)); | 461 AddMessageHandler((new ShownSectionsHandler(pref_service))->Attach(this)); |
| 463 AddMessageHandler((new MostVisitedHandler())->Attach(this)); | 462 AddMessageHandler((new MostVisitedHandler())->Attach(this)); |
| 464 AddMessageHandler((new RecentlyClosedTabsHandler())->Attach(this)); | 463 AddMessageHandler((new RecentlyClosedTabsHandler())->Attach(this)); |
| 465 AddMessageHandler((new MetricsHandler())->Attach(this)); | 464 AddMessageHandler((new MetricsHandler())->Attach(this)); |
| 466 if (WebResourcesEnabled()) | |
| 467 AddMessageHandler((new TipsHandler())->Attach(this)); | |
| 468 if (GetProfile()->IsSyncAccessible()) | 465 if (GetProfile()->IsSyncAccessible()) |
| 469 AddMessageHandler((new NewTabPageSyncHandler())->Attach(this)); | 466 AddMessageHandler((new NewTabPageSyncHandler())->Attach(this)); |
| 470 if (Extension::AppsAreEnabled()) { | 467 if (Extension::AppsAreEnabled()) { |
| 471 ExtensionsService* service = GetProfile()->GetExtensionsService(); | 468 ExtensionsService* service = GetProfile()->GetExtensionsService(); |
| 472 // We might not have an ExtensionsService (on ChromeOS when not logged in | 469 // We might not have an ExtensionsService (on ChromeOS when not logged in |
| 473 // for example). | 470 // for example). |
| 474 if (service) | 471 if (service) |
| 475 AddMessageHandler((new AppLauncherHandler(service))->Attach(this)); | 472 AddMessageHandler((new AppLauncherHandler(service))->Attach(this)); |
| 476 } | 473 } |
| 477 | 474 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 &ChromeURLDataManager::AddDataSource, | 530 &ChromeURLDataManager::AddDataSource, |
| 534 make_scoped_refptr(theme))); | 531 make_scoped_refptr(theme))); |
| 535 } | 532 } |
| 536 | 533 |
| 537 // static | 534 // static |
| 538 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { | 535 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { |
| 539 prefs->RegisterIntegerPref(prefs::kNTPPrefVersion, 0); | 536 prefs->RegisterIntegerPref(prefs::kNTPPrefVersion, 0); |
| 540 | 537 |
| 541 MostVisitedHandler::RegisterUserPrefs(prefs); | 538 MostVisitedHandler::RegisterUserPrefs(prefs); |
| 542 ShownSectionsHandler::RegisterUserPrefs(prefs); | 539 ShownSectionsHandler::RegisterUserPrefs(prefs); |
| 543 if (NewTabUI::WebResourcesEnabled()) | |
| 544 TipsHandler::RegisterUserPrefs(prefs); | |
| 545 | 540 |
| 546 UpdateUserPrefsVersion(prefs); | 541 UpdateUserPrefsVersion(prefs); |
| 547 } | 542 } |
| 548 | 543 |
| 549 // static | 544 // static |
| 550 bool NewTabUI::UpdateUserPrefsVersion(PrefService* prefs) { | 545 bool NewTabUI::UpdateUserPrefsVersion(PrefService* prefs) { |
| 551 const int old_pref_version = prefs->GetInteger(prefs::kNTPPrefVersion); | 546 const int old_pref_version = prefs->GetInteger(prefs::kNTPPrefVersion); |
| 552 if (old_pref_version != current_pref_version()) { | 547 if (old_pref_version != current_pref_version()) { |
| 553 MigrateUserPrefs(prefs, old_pref_version, current_pref_version()); | 548 MigrateUserPrefs(prefs, old_pref_version, current_pref_version()); |
| 554 prefs->SetInteger(prefs::kNTPPrefVersion, current_pref_version()); | 549 prefs->SetInteger(prefs::kNTPPrefVersion, current_pref_version()); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 | 648 |
| 654 scoped_refptr<RefCountedBytes> html_bytes = | 649 scoped_refptr<RefCountedBytes> html_bytes = |
| 655 profile_->GetNTPResourceCache()->GetNewTabHTML(is_off_the_record); | 650 profile_->GetNTPResourceCache()->GetNewTabHTML(is_off_the_record); |
| 656 | 651 |
| 657 SendResponse(request_id, html_bytes); | 652 SendResponse(request_id, html_bytes); |
| 658 } | 653 } |
| 659 | 654 |
| 660 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { | 655 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { |
| 661 return "text/html"; | 656 return "text/html"; |
| 662 } | 657 } |
| OLD | NEW |