diff options
author | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-29 22:25:36 +0000 |
---|---|---|
committer | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-29 22:25:36 +0000 |
commit | 4ccbf84e99431fbe87a68dca1c850b4e74beb530 (patch) | |
tree | 2cbfb07138f9c09f947227e8c241bdb3ea162210 /chrome/browser/dom_ui | |
parent | 7f200a025bc53c1900ab7a4b0fd2e369b0b4aa0a (diff) | |
download | chromium_src-4ccbf84e99431fbe87a68dca1c850b4e74beb530.zip chromium_src-4ccbf84e99431fbe87a68dca1c850b4e74beb530.tar.gz chromium_src-4ccbf84e99431fbe87a68dca1c850b4e74beb530.tar.bz2 |
Some new tab ui fixes.
1) Always intialize the css cache. Previously we were only
initializing if not in incognito mode. If the first NTP was an
incognito page, it wouldn't be styled.
2) Small optimization in generating the HTML to avoid calling
ReplaceFirstSubstringAfterOffset which would need to move the
bytes after the placeholder.
3) Only generate the css for the incognito or normal mode. Since
the NTP only needs one, we only need to generate one.
BUG=26228
Review URL: http://codereview.chromium.org/344027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30527 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_theme_source.cc | 6 | ||||
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.cc | 21 |
2 files changed, 18 insertions, 9 deletions
diff --git a/chrome/browser/dom_ui/dom_ui_theme_source.cc b/chrome/browser/dom_ui/dom_ui_theme_source.cc index 49e227f..8361198 100644 --- a/chrome/browser/dom_ui/dom_ui_theme_source.cc +++ b/chrome/browser/dom_ui/dom_ui_theme_source.cc @@ -53,8 +53,10 @@ static std::string StripQueryParams(const std::string& path) { DOMUIThemeSource::DOMUIThemeSource(Profile* profile) : DataSource(chrome::kChromeUIThemePath, MessageLoop::current()), profile_(profile) { - InitNewTabCSS(); - InitNewIncognitoTabCSS(); + if (profile->IsOffTheRecord()) + InitNewIncognitoTabCSS(); + else + InitNewTabCSS(); } void DOMUIThemeSource::StartDataRequest(const std::string& path, diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc index 0e53325..02594fe 100644 --- a/chrome/browser/dom_ui/new_tab_ui.cc +++ b/chrome/browser/dom_ui/new_tab_ui.cc @@ -543,6 +543,7 @@ NewTabUI::NewTabUI(TabContents* contents) if (NewTabUI::FirstRunDisabled()) NewTabHTMLSource::set_first_run(false); + InitializeCSSCaches(); if (GetProfile()->IsOffTheRecord()) { incognito_ = true; @@ -570,7 +571,6 @@ NewTabUI::NewTabUI(TabContents* contents) AddMessageHandler((new NewTabPageSetHomepageHandler())->Attach(this)); - InitializeCSSCaches(); NewTabHTMLSource* html_source = new NewTabHTMLSource(GetProfile()); bool posted = ChromeThread::PostTask( ChromeThread::IO, FROM_HERE, @@ -935,17 +935,24 @@ void NewTabUI::NewTabHTMLSource::InitFullHTML() { IDR_NEW_NEW_TAB_HTML); } - full_html_.assign(new_tab_html.data(), new_tab_html.size()); - // Inject the template data into the HTML so that it is available before any // layout is needed. std::string json_html; jstemplate_builder::AppendJsonHtml(&localized_strings, &json_html); - static const std::string template_data_placeholder = - "<!-- template data placeholder -->"; - ReplaceFirstSubstringAfterOffset(&full_html_, 0, template_data_placeholder, - json_html); + static const base::StringPiece template_data_placeholder( + "<!-- template data placeholder -->"); + size_t pos = new_tab_html.find(template_data_placeholder); + if (pos != base::StringPiece::npos) { + full_html_.assign(new_tab_html.data(), pos); + full_html_.append(json_html); + size_t after_offset = pos + template_data_placeholder.size(); + full_html_.append(new_tab_html.data() + after_offset, + new_tab_html.size() - after_offset); + } else { + NOTREACHED(); + full_html_.assign(new_tab_html.data(), new_tab_html.size()); + } jstemplate_builder::AppendI18nTemplateProcessHtml(&full_html_); } |