Chromium Code Reviews| 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 |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 536 | 536 |
| 537 if (NewTabHTMLSource::first_view() && | 537 if (NewTabHTMLSource::first_view() && |
| 538 (GetProfile()->GetPrefs()->GetInteger(prefs::kRestoreOnStartup) != 0 || | 538 (GetProfile()->GetPrefs()->GetInteger(prefs::kRestoreOnStartup) != 0 || |
| 539 !GetProfile()->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage))) { | 539 !GetProfile()->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage))) { |
| 540 NewTabHTMLSource::set_first_view(false); | 540 NewTabHTMLSource::set_first_view(false); |
| 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 InitializeCSSCaches(); | |
| 546 if (GetProfile()->IsOffTheRecord()) { | 547 if (GetProfile()->IsOffTheRecord()) { |
| 547 incognito_ = true; | 548 incognito_ = true; |
| 548 | 549 |
| 549 IncognitoTabHTMLSource* html_source = new IncognitoTabHTMLSource( | 550 IncognitoTabHTMLSource* html_source = new IncognitoTabHTMLSource( |
| 550 GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar)); | 551 GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar)); |
| 551 ChromeThread::PostTask( | 552 ChromeThread::PostTask( |
| 552 ChromeThread::IO, FROM_HERE, | 553 ChromeThread::IO, FROM_HERE, |
| 553 NewRunnableMethod( | 554 NewRunnableMethod( |
| 554 &chrome_url_data_manager, | 555 &chrome_url_data_manager, |
| 555 &ChromeURLDataManager::AddDataSource, | 556 &ChromeURLDataManager::AddDataSource, |
| 556 html_source)); | 557 html_source)); |
| 557 } else { | 558 } else { |
| 558 AddMessageHandler((new ShownSectionsHandler())->Attach(this)); | 559 AddMessageHandler((new ShownSectionsHandler())->Attach(this)); |
| 559 AddMessageHandler((new MostVisitedHandler())->Attach(this)); | 560 AddMessageHandler((new MostVisitedHandler())->Attach(this)); |
| 560 AddMessageHandler((new RecentlyClosedTabsHandler())->Attach(this)); | 561 AddMessageHandler((new RecentlyClosedTabsHandler())->Attach(this)); |
| 561 AddMessageHandler((new MetricsHandler())->Attach(this)); | 562 AddMessageHandler((new MetricsHandler())->Attach(this)); |
| 562 if (WebResourcesEnabled()) | 563 if (WebResourcesEnabled()) |
| 563 AddMessageHandler((new TipsHandler())->Attach(this)); | 564 AddMessageHandler((new TipsHandler())->Attach(this)); |
| 564 | 565 |
| 565 #if !defined(OS_POSIX) | 566 #if !defined(OS_POSIX) |
| 566 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableSync)) { | 567 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableSync)) { |
| 567 AddMessageHandler((new NewTabPageSyncHandler())->Attach(this)); | 568 AddMessageHandler((new NewTabPageSyncHandler())->Attach(this)); |
| 568 } | 569 } |
| 569 #endif | 570 #endif |
| 570 | 571 |
| 571 AddMessageHandler((new NewTabPageSetHomepageHandler())->Attach(this)); | 572 AddMessageHandler((new NewTabPageSetHomepageHandler())->Attach(this)); |
| 572 | 573 |
| 573 InitializeCSSCaches(); | |
| 574 NewTabHTMLSource* html_source = new NewTabHTMLSource(GetProfile()); | 574 NewTabHTMLSource* html_source = new NewTabHTMLSource(GetProfile()); |
| 575 bool posted = ChromeThread::PostTask( | 575 bool posted = ChromeThread::PostTask( |
| 576 ChromeThread::IO, FROM_HERE, | 576 ChromeThread::IO, FROM_HERE, |
| 577 NewRunnableMethod( | 577 NewRunnableMethod( |
| 578 &chrome_url_data_manager, | 578 &chrome_url_data_manager, |
| 579 &ChromeURLDataManager::AddDataSource, | 579 &ChromeURLDataManager::AddDataSource, |
| 580 html_source)); | 580 html_source)); |
| 581 if (!posted) { | 581 if (!posted) { |
| 582 html_source->AddRef(); | 582 html_source->AddRef(); |
| 583 html_source->Release(); // Keep Valgrind happy in tests. | 583 html_source->Release(); // Keep Valgrind happy in tests. |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 | 901 |
| 902 if (!new_tab_html_str.empty()) { | 902 if (!new_tab_html_str.empty()) { |
| 903 new_tab_html = base::StringPiece(new_tab_html_str); | 903 new_tab_html = base::StringPiece(new_tab_html_str); |
| 904 } | 904 } |
| 905 | 905 |
| 906 if (new_tab_html.empty()) { | 906 if (new_tab_html.empty()) { |
| 907 new_tab_html = ResourceBundle::GetSharedInstance().GetRawDataResource( | 907 new_tab_html = ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 908 IDR_NEW_NEW_TAB_HTML); | 908 IDR_NEW_NEW_TAB_HTML); |
| 909 } | 909 } |
| 910 | 910 |
| 911 full_html_.assign(new_tab_html.data(), new_tab_html.size()); | |
| 912 | |
| 913 // Inject the template data into the HTML so that it is available before any | 911 // Inject the template data into the HTML so that it is available before any |
| 914 // layout is needed. | 912 // layout is needed. |
| 915 std::string json_html; | 913 std::string json_html; |
| 916 jstemplate_builder::AppendJsonHtml(&localized_strings, &json_html); | 914 jstemplate_builder::AppendJsonHtml(&localized_strings, &json_html); |
| 917 | 915 |
| 918 static const std::string template_data_placeholder = | 916 static const base::StringPiece template_data_placeholder( |
| 919 "<!-- template data placeholder -->"; | 917 "<!-- template data placeholder -->"); |
|
Evan Martin
2009/10/29 22:27:28
FWIW, if you want to get really anal about this, t
| |
| 920 ReplaceFirstSubstringAfterOffset(&full_html_, 0, template_data_placeholder, | 918 size_t pos = new_tab_html.find(template_data_placeholder); |
| 921 json_html); | |
| 922 | 919 |
| 920 if (pos != base::StringPiece::npos) { | |
| 921 full_html_.assign(new_tab_html.data(), pos); | |
| 922 full_html_.append(json_html); | |
| 923 size_t after_offset = pos + template_data_placeholder.size(); | |
| 924 full_html_.append(new_tab_html.data() + after_offset, | |
| 925 new_tab_html.size() - after_offset); | |
| 926 } else { | |
| 927 NOTREACHED(); | |
| 928 full_html_.assign(new_tab_html.data(), new_tab_html.size()); | |
| 929 } | |
| 923 jstemplate_builder::AppendI18nTemplateProcessHtml(&full_html_); | 930 jstemplate_builder::AppendI18nTemplateProcessHtml(&full_html_); |
| 924 } | 931 } |
| OLD | NEW |