| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/animation.h" | 11 #include "app/animation.h" |
| 12 #include "app/l10n_util.h" | 12 #include "app/l10n_util.h" |
| 13 #include "app/resource_bundle.h" | 13 #include "app/resource_bundle.h" |
| 14 #include "app/theme_provider.h" | 14 #include "app/theme_provider.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
| 17 #include "base/histogram.h" | 17 #include "base/histogram.h" |
| 18 #include "base/string_piece.h" | 18 #include "base/string_piece.h" |
| 19 #include "base/thread.h" | 19 #include "base/thread.h" |
| 20 #include "chrome/browser/browser.h" | 20 #include "chrome/browser/browser.h" |
| 21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/chrome_thread.h" |
| 22 #include "chrome/browser/dom_ui/dom_ui_theme_source.h" | 22 #include "chrome/browser/dom_ui/dom_ui_theme_source.h" |
| 23 #include "chrome/browser/dom_ui/most_visited_handler.h" | 23 #include "chrome/browser/dom_ui/most_visited_handler.h" |
| 24 #include "chrome/browser/dom_ui/new_tab_page_sync_handler.h" | 24 #include "chrome/browser/dom_ui/new_tab_page_sync_handler.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" | 26 #include "chrome/browser/dom_ui/tips_handler.h" |
| 27 #include "chrome/browser/metrics/user_metrics.h" | 27 #include "chrome/browser/metrics/user_metrics.h" |
| 28 #include "chrome/browser/profile.h" | 28 #include "chrome/browser/profile.h" |
| 29 #include "chrome/browser/renderer_host/render_view_host.h" | 29 #include "chrome/browser/renderer_host/render_view_host.h" |
| 30 #include "chrome/browser/sessions/session_types.h" | 30 #include "chrome/browser/sessions/session_types.h" |
| 31 #include "chrome/browser/tab_contents/tab_contents.h" | 31 #include "chrome/browser/tab_contents/tab_contents.h" |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 } | 541 } |
| 542 | 542 |
| 543 if (NewTabUI::FirstRunDisabled()) | 543 if (NewTabUI::FirstRunDisabled()) |
| 544 NewTabHTMLSource::set_first_run(false); | 544 NewTabHTMLSource::set_first_run(false); |
| 545 | 545 |
| 546 if (GetProfile()->IsOffTheRecord()) { | 546 if (GetProfile()->IsOffTheRecord()) { |
| 547 incognito_ = true; | 547 incognito_ = true; |
| 548 | 548 |
| 549 IncognitoTabHTMLSource* html_source = new IncognitoTabHTMLSource( | 549 IncognitoTabHTMLSource* html_source = new IncognitoTabHTMLSource( |
| 550 GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar)); | 550 GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar)); |
| 551 | 551 ChromeThread::PostTask( |
| 552 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | 552 ChromeThread::IO, FROM_HERE, |
| 553 NewRunnableMethod(&chrome_url_data_manager, | 553 NewRunnableMethod( |
| 554 &chrome_url_data_manager, |
| 554 &ChromeURLDataManager::AddDataSource, | 555 &ChromeURLDataManager::AddDataSource, |
| 555 html_source)); | 556 html_source)); |
| 556 } else { | 557 } else { |
| 557 AddMessageHandler((new ShownSectionsHandler())->Attach(this)); | 558 AddMessageHandler((new ShownSectionsHandler())->Attach(this)); |
| 558 AddMessageHandler((new MostVisitedHandler())->Attach(this)); | 559 AddMessageHandler((new MostVisitedHandler())->Attach(this)); |
| 559 AddMessageHandler((new RecentlyClosedTabsHandler())->Attach(this)); | 560 AddMessageHandler((new RecentlyClosedTabsHandler())->Attach(this)); |
| 560 AddMessageHandler((new MetricsHandler())->Attach(this)); | 561 AddMessageHandler((new MetricsHandler())->Attach(this)); |
| 561 if (WebResourcesEnabled()) | 562 if (WebResourcesEnabled()) |
| 562 AddMessageHandler((new TipsHandler())->Attach(this)); | 563 AddMessageHandler((new TipsHandler())->Attach(this)); |
| 563 | 564 |
| 564 #if !defined(OS_POSIX) | 565 #if !defined(OS_POSIX) |
| 565 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableSync)) { | 566 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableSync)) { |
| 566 AddMessageHandler((new NewTabPageSyncHandler())->Attach(this)); | 567 AddMessageHandler((new NewTabPageSyncHandler())->Attach(this)); |
| 567 } | 568 } |
| 568 #endif | 569 #endif |
| 569 | 570 |
| 570 AddMessageHandler((new NewTabPageSetHomepageHandler())->Attach(this)); | 571 AddMessageHandler((new NewTabPageSetHomepageHandler())->Attach(this)); |
| 571 | 572 |
| 572 // In testing mode there may not be an I/O thread. | 573 InitializeCSSCaches(); |
| 573 if (g_browser_process->io_thread()) { | 574 NewTabHTMLSource* html_source = new NewTabHTMLSource(GetProfile()); |
| 574 InitializeCSSCaches(); | 575 ChromeThread::PostTask( |
| 575 NewTabHTMLSource* html_source = new NewTabHTMLSource(GetProfile()); | 576 ChromeThread::IO, FROM_HERE, |
| 576 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | 577 NewRunnableMethod( |
| 577 NewRunnableMethod(&chrome_url_data_manager, | 578 &chrome_url_data_manager, |
| 578 &ChromeURLDataManager::AddDataSource, | 579 &ChromeURLDataManager::AddDataSource, |
| 579 html_source)); | 580 html_source)); |
| 580 } | |
| 581 } | 581 } |
| 582 | 582 |
| 583 // Listen for theme installation. | 583 // Listen for theme installation. |
| 584 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | 584 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
| 585 NotificationService::AllSources()); | 585 NotificationService::AllSources()); |
| 586 // Listen for bookmark bar visibility changes. | 586 // Listen for bookmark bar visibility changes. |
| 587 registrar_.Add(this, NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, | 587 registrar_.Add(this, NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, |
| 588 NotificationService::AllSources()); | 588 NotificationService::AllSources()); |
| 589 } | 589 } |
| 590 | 590 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 607 CallJavascriptFunction(L"themeChanged"); | 607 CallJavascriptFunction(L"themeChanged"); |
| 608 } else if (NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED) { | 608 } else if (NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED) { |
| 609 if (GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar)) | 609 if (GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar)) |
| 610 CallJavascriptFunction(L"bookmarkBarAttached"); | 610 CallJavascriptFunction(L"bookmarkBarAttached"); |
| 611 else | 611 else |
| 612 CallJavascriptFunction(L"bookmarkBarDetached"); | 612 CallJavascriptFunction(L"bookmarkBarDetached"); |
| 613 } | 613 } |
| 614 } | 614 } |
| 615 | 615 |
| 616 void NewTabUI::InitializeCSSCaches() { | 616 void NewTabUI::InitializeCSSCaches() { |
| 617 // In testing mode there may not be an I/O thread. | 617 ChromeThread::PostTask( |
| 618 if (g_browser_process->io_thread()) { | 618 ChromeThread::IO, FROM_HERE, |
| 619 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | 619 NewRunnableMethod( |
| 620 NewRunnableMethod(&chrome_url_data_manager, | 620 &chrome_url_data_manager, |
| 621 &ChromeURLDataManager::AddDataSource, | 621 &ChromeURLDataManager::AddDataSource, |
| 622 new DOMUIThemeSource(GetProfile()))); | 622 new DOMUIThemeSource(GetProfile()))); |
| 623 } | |
| 624 } | 623 } |
| 625 | 624 |
| 626 // static | 625 // static |
| 627 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { | 626 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { |
| 628 MostVisitedHandler::RegisterUserPrefs(prefs); | 627 MostVisitedHandler::RegisterUserPrefs(prefs); |
| 629 ShownSectionsHandler::RegisterUserPrefs(prefs); | 628 ShownSectionsHandler::RegisterUserPrefs(prefs); |
| 630 if (NewTabUI::WebResourcesEnabled()) | 629 if (NewTabUI::WebResourcesEnabled()) |
| 631 TipsHandler::RegisterUserPrefs(prefs); | 630 TipsHandler::RegisterUserPrefs(prefs); |
| 632 } | 631 } |
| 633 | 632 |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 std::string json_html; | 905 std::string json_html; |
| 907 jstemplate_builder::AppendJsonHtml(&localized_strings, &json_html); | 906 jstemplate_builder::AppendJsonHtml(&localized_strings, &json_html); |
| 908 | 907 |
| 909 static const std::string template_data_placeholder = | 908 static const std::string template_data_placeholder = |
| 910 "<!-- template data placeholder -->"; | 909 "<!-- template data placeholder -->"; |
| 911 ReplaceFirstSubstringAfterOffset(&full_html_, 0, template_data_placeholder, | 910 ReplaceFirstSubstringAfterOffset(&full_html_, 0, template_data_placeholder, |
| 912 json_html); | 911 json_html); |
| 913 | 912 |
| 914 jstemplate_builder::AppendI18nTemplateProcessHtml(&full_html_); | 913 jstemplate_builder::AppendI18nTemplateProcessHtml(&full_html_); |
| 915 } | 914 } |
| OLD | NEW |