| 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/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 |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 AddMessageHandler((new NewTabPageSetHomePageHandler())->Attach(this)); | 325 AddMessageHandler((new NewTabPageSetHomePageHandler())->Attach(this)); |
| 326 AddMessageHandler((new NewTabPageClosePromoHandler())->Attach(this)); | 326 AddMessageHandler((new NewTabPageClosePromoHandler())->Attach(this)); |
| 327 } | 327 } |
| 328 | 328 |
| 329 // Initializing the CSS and HTML can require some CPU, so do it after | 329 // Initializing the CSS and HTML can require some CPU, so do it after |
| 330 // we've hooked up the most visited handler. This allows the DB query | 330 // we've hooked up the most visited handler. This allows the DB query |
| 331 // for the new tab thumbs to happen earlier. | 331 // for the new tab thumbs to happen earlier. |
| 332 InitializeCSSCaches(); | 332 InitializeCSSCaches(); |
| 333 NewTabHTMLSource* html_source = | 333 NewTabHTMLSource* html_source = |
| 334 new NewTabHTMLSource(GetProfile()->GetOriginalProfile()); | 334 new NewTabHTMLSource(GetProfile()->GetOriginalProfile()); |
| 335 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); | 335 BrowserThread::PostTask( |
| 336 BrowserThread::IO, FROM_HERE, |
| 337 NewRunnableMethod( |
| 338 ChromeURLDataManager::GetInstance(), |
| 339 &ChromeURLDataManager::AddDataSource, |
| 340 make_scoped_refptr(html_source))); |
| 336 | 341 |
| 337 // Listen for theme installation. | 342 // Listen for theme installation. |
| 338 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | 343 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
| 339 NotificationService::AllSources()); | 344 NotificationService::AllSources()); |
| 340 // Listen for bookmark bar visibility changes. | 345 // Listen for bookmark bar visibility changes. |
| 341 registrar_.Add(this, NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, | 346 registrar_.Add(this, NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, |
| 342 NotificationService::AllSources()); | 347 NotificationService::AllSources()); |
| 343 } | 348 } |
| 344 | 349 |
| 345 NewTabUI::~NewTabUI() { | 350 NewTabUI::~NewTabUI() { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 case NotificationType::RENDER_WIDGET_HOST_DID_PAINT: { | 415 case NotificationType::RENDER_WIDGET_HOST_DID_PAINT: { |
| 411 last_paint_ = base::TimeTicks::Now(); | 416 last_paint_ = base::TimeTicks::Now(); |
| 412 break; | 417 break; |
| 413 } | 418 } |
| 414 default: | 419 default: |
| 415 CHECK(false) << "Unexpected notification: " << type.value; | 420 CHECK(false) << "Unexpected notification: " << type.value; |
| 416 } | 421 } |
| 417 } | 422 } |
| 418 | 423 |
| 419 void NewTabUI::InitializeCSSCaches() { | 424 void NewTabUI::InitializeCSSCaches() { |
| 420 Profile* profile = GetProfile(); | 425 WebUIThemeSource* theme = new WebUIThemeSource(GetProfile()); |
| 421 WebUIThemeSource* theme = new WebUIThemeSource(profile); | 426 BrowserThread::PostTask( |
| 422 profile->GetChromeURLDataManager()->AddDataSource(theme); | 427 BrowserThread::IO, FROM_HERE, |
| 428 NewRunnableMethod( |
| 429 ChromeURLDataManager::GetInstance(), |
| 430 &ChromeURLDataManager::AddDataSource, |
| 431 make_scoped_refptr(theme))); |
| 423 } | 432 } |
| 424 | 433 |
| 425 // static | 434 // static |
| 426 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { | 435 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { |
| 427 prefs->RegisterIntegerPref(prefs::kNTPPrefVersion, 0); | 436 prefs->RegisterIntegerPref(prefs::kNTPPrefVersion, 0); |
| 428 | 437 |
| 429 MostVisitedHandler::RegisterUserPrefs(prefs); | 438 MostVisitedHandler::RegisterUserPrefs(prefs); |
| 430 ShownSectionsHandler::RegisterUserPrefs(prefs); | 439 ShownSectionsHandler::RegisterUserPrefs(prefs); |
| 431 if (NewTabUI::WebResourcesEnabled()) | 440 if (NewTabUI::WebResourcesEnabled()) |
| 432 TipsHandler::RegisterUserPrefs(prefs); | 441 TipsHandler::RegisterUserPrefs(prefs); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 | 600 |
| 592 scoped_refptr<RefCountedBytes> html_bytes( | 601 scoped_refptr<RefCountedBytes> html_bytes( |
| 593 profile_->GetNTPResourceCache()->GetNewTabHTML(is_off_the_record)); | 602 profile_->GetNTPResourceCache()->GetNewTabHTML(is_off_the_record)); |
| 594 | 603 |
| 595 SendResponse(request_id, html_bytes); | 604 SendResponse(request_id, html_bytes); |
| 596 } | 605 } |
| 597 | 606 |
| 598 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { | 607 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { |
| 599 return "text/html"; | 608 return "text/html"; |
| 600 } | 609 } |
| OLD | NEW |