| 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/singleton.h" |
| 18 #include "base/string_piece.h" | 19 #include "base/string_piece.h" |
| 19 #include "base/thread.h" | 20 #include "base/thread.h" |
| 20 #include "chrome/browser/browser.h" | 21 #include "chrome/browser/browser.h" |
| 21 #include "chrome/browser/chrome_thread.h" | 22 #include "chrome/browser/chrome_thread.h" |
| 22 #include "chrome/browser/dom_ui/dom_ui_theme_source.h" | 23 #include "chrome/browser/dom_ui/dom_ui_theme_source.h" |
| 23 #include "chrome/browser/dom_ui/most_visited_handler.h" | 24 #include "chrome/browser/dom_ui/most_visited_handler.h" |
| 24 #include "chrome/browser/dom_ui/new_tab_page_sync_handler.h" | 25 #include "chrome/browser/dom_ui/new_tab_page_sync_handler.h" |
| 25 #include "chrome/browser/dom_ui/shown_sections_handler.h" | 26 #include "chrome/browser/dom_ui/shown_sections_handler.h" |
| 26 #include "chrome/browser/dom_ui/tips_handler.h" | 27 #include "chrome/browser/dom_ui/tips_handler.h" |
| 27 #include "chrome/browser/metrics/user_metrics.h" | 28 #include "chrome/browser/metrics/user_metrics.h" |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 | 546 |
| 546 InitializeCSSCaches(); | 547 InitializeCSSCaches(); |
| 547 if (GetProfile()->IsOffTheRecord()) { | 548 if (GetProfile()->IsOffTheRecord()) { |
| 548 incognito_ = true; | 549 incognito_ = true; |
| 549 | 550 |
| 550 IncognitoTabHTMLSource* html_source = new IncognitoTabHTMLSource( | 551 IncognitoTabHTMLSource* html_source = new IncognitoTabHTMLSource( |
| 551 GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar)); | 552 GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar)); |
| 552 ChromeThread::PostTask( | 553 ChromeThread::PostTask( |
| 553 ChromeThread::IO, FROM_HERE, | 554 ChromeThread::IO, FROM_HERE, |
| 554 NewRunnableMethod( | 555 NewRunnableMethod( |
| 555 &chrome_url_data_manager, | 556 Singleton<ChromeURLDataManager>().get(), |
| 556 &ChromeURLDataManager::AddDataSource, | 557 &ChromeURLDataManager::AddDataSource, |
| 557 html_source)); | 558 html_source)); |
| 558 } else { | 559 } else { |
| 559 AddMessageHandler((new ShownSectionsHandler())->Attach(this)); | 560 AddMessageHandler((new ShownSectionsHandler())->Attach(this)); |
| 560 AddMessageHandler((new MostVisitedHandler())->Attach(this)); | 561 AddMessageHandler((new MostVisitedHandler())->Attach(this)); |
| 561 AddMessageHandler((new RecentlyClosedTabsHandler())->Attach(this)); | 562 AddMessageHandler((new RecentlyClosedTabsHandler())->Attach(this)); |
| 562 AddMessageHandler((new MetricsHandler())->Attach(this)); | 563 AddMessageHandler((new MetricsHandler())->Attach(this)); |
| 563 if (WebResourcesEnabled()) | 564 if (WebResourcesEnabled()) |
| 564 AddMessageHandler((new TipsHandler())->Attach(this)); | 565 AddMessageHandler((new TipsHandler())->Attach(this)); |
| 565 | 566 |
| 566 #if !defined(OS_POSIX) | 567 #if !defined(OS_POSIX) |
| 567 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableSync)) { | 568 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableSync)) { |
| 568 AddMessageHandler((new NewTabPageSyncHandler())->Attach(this)); | 569 AddMessageHandler((new NewTabPageSyncHandler())->Attach(this)); |
| 569 } | 570 } |
| 570 #endif | 571 #endif |
| 571 | 572 |
| 572 AddMessageHandler((new NewTabPageSetHomepageHandler())->Attach(this)); | 573 AddMessageHandler((new NewTabPageSetHomepageHandler())->Attach(this)); |
| 573 | 574 |
| 574 NewTabHTMLSource* html_source = new NewTabHTMLSource(GetProfile()); | 575 NewTabHTMLSource* html_source = new NewTabHTMLSource(GetProfile()); |
| 575 bool posted = ChromeThread::PostTask( | 576 bool posted = ChromeThread::PostTask( |
| 576 ChromeThread::IO, FROM_HERE, | 577 ChromeThread::IO, FROM_HERE, |
| 577 NewRunnableMethod( | 578 NewRunnableMethod( |
| 578 &chrome_url_data_manager, | 579 Singleton<ChromeURLDataManager>().get(), |
| 579 &ChromeURLDataManager::AddDataSource, | 580 &ChromeURLDataManager::AddDataSource, |
| 580 html_source)); | 581 html_source)); |
| 581 if (!posted) { | 582 if (!posted) { |
| 582 html_source->AddRef(); | 583 html_source->AddRef(); |
| 583 html_source->Release(); // Keep Valgrind happy in tests. | 584 html_source->Release(); // Keep Valgrind happy in tests. |
| 584 } | 585 } |
| 585 } | 586 } |
| 586 | 587 |
| 587 // Listen for theme installation. | 588 // Listen for theme installation. |
| 588 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | 589 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 615 else | 616 else |
| 616 CallJavascriptFunction(L"bookmarkBarDetached"); | 617 CallJavascriptFunction(L"bookmarkBarDetached"); |
| 617 } | 618 } |
| 618 } | 619 } |
| 619 | 620 |
| 620 void NewTabUI::InitializeCSSCaches() { | 621 void NewTabUI::InitializeCSSCaches() { |
| 621 DOMUIThemeSource* theme = new DOMUIThemeSource(GetProfile()); | 622 DOMUIThemeSource* theme = new DOMUIThemeSource(GetProfile()); |
| 622 bool posted = ChromeThread::PostTask( | 623 bool posted = ChromeThread::PostTask( |
| 623 ChromeThread::IO, FROM_HERE, | 624 ChromeThread::IO, FROM_HERE, |
| 624 NewRunnableMethod( | 625 NewRunnableMethod( |
| 625 &chrome_url_data_manager, | 626 Singleton<ChromeURLDataManager>().get(), |
| 626 &ChromeURLDataManager::AddDataSource, | 627 &ChromeURLDataManager::AddDataSource, |
| 627 theme)); | 628 theme)); |
| 628 if (!posted) { | 629 if (!posted) { |
| 629 theme->AddRef(); | 630 theme->AddRef(); |
| 630 theme->Release(); // Keep Valgrind happy in tests. | 631 theme->Release(); // Keep Valgrind happy in tests. |
| 631 } | 632 } |
| 632 } | 633 } |
| 633 | 634 |
| 634 // static | 635 // static |
| 635 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { | 636 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 full_html_.append(json_html); | 950 full_html_.append(json_html); |
| 950 size_t after_offset = pos + template_data_placeholder.size(); | 951 size_t after_offset = pos + template_data_placeholder.size(); |
| 951 full_html_.append(new_tab_html.data() + after_offset, | 952 full_html_.append(new_tab_html.data() + after_offset, |
| 952 new_tab_html.size() - after_offset); | 953 new_tab_html.size() - after_offset); |
| 953 } else { | 954 } else { |
| 954 NOTREACHED(); | 955 NOTREACHED(); |
| 955 full_html_.assign(new_tab_html.data(), new_tab_html.size()); | 956 full_html_.assign(new_tab_html.data(), new_tab_html.size()); |
| 956 } | 957 } |
| 957 jstemplate_builder::AppendI18nTemplateProcessHtml(&full_html_); | 958 jstemplate_builder::AppendI18nTemplateProcessHtml(&full_html_); |
| 958 } | 959 } |
| OLD | NEW |