Chromium Code Reviews| 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 "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" | 5 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 } | 416 } |
| 417 | 417 |
| 418 // If the user has preferences for a start and end time for a promo from | 418 // If the user has preferences for a start and end time for a promo from |
| 419 // the server, and this promo string exists, set the localized string. | 419 // the server, and this promo string exists, set the localized string. |
| 420 if (PromoResourceService::CanShowNotificationPromo(profile_)) { | 420 if (PromoResourceService::CanShowNotificationPromo(profile_)) { |
| 421 localized_strings.SetString("serverpromo", | 421 localized_strings.SetString("serverpromo", |
| 422 profile_->GetPrefs()->GetString(prefs::kNTPPromoLine)); | 422 profile_->GetPrefs()->GetString(prefs::kNTPPromoLine)); |
| 423 UserMetrics::RecordAction(UserMetricsAction("NTPPromoShown")); | 423 UserMetrics::RecordAction(UserMetricsAction("NTPPromoShown")); |
| 424 } | 424 } |
| 425 | 425 |
| 426 // Load the new tab page appropriate for this build | 426 // Load the new tab page appropriate for this build. |
| 427 // Note that some builds (eg. TOUCHUI) don't make use of everything we | |
| 428 // do here (all of the template data, etc.), but we keep the back end | |
| 429 // consistent across builds, supporting the union of all NTP front-ends | |
| 430 // for simplicity. | |
| 431 std::string full_html; | 427 std::string full_html; |
| 432 if (NewTabUI::NTP4Enabled()) { | 428 #if defined(TOUCH_UI) |
|
Rick Byers
2011/09/26 16:05:26
Ugh - sure will be nice to move touch_ui to NTP4 a
| |
| 433 base::StringPiece new_tab_html(ResourceBundle::GetSharedInstance(). | 429 base::StringPiece new_tab_html(ResourceBundle::GetSharedInstance(). |
| 434 GetRawDataResource(IDR_NEW_TAB_4_HTML)); | 430 GetRawDataResource(IDR_NEW_TAB_HTML)); |
| 435 full_html = jstemplate_builder::GetI18nTemplateHtml(new_tab_html, | 431 |
| 436 &localized_strings); | 432 // Inject the template data into the HTML so that it is available before any |
| 433 // layout is needed. | |
| 434 std::string json_html; | |
| 435 jstemplate_builder::AppendJsonHtml(&localized_strings, &json_html); | |
| 436 | |
| 437 static const base::StringPiece template_data_placeholder( | |
| 438 "<!-- template data placeholder -->"); | |
| 439 size_t pos = new_tab_html.find(template_data_placeholder); | |
| 440 | |
| 441 if (pos != base::StringPiece::npos) { | |
| 442 full_html.assign(new_tab_html.data(), pos); | |
| 443 full_html.append(json_html); | |
| 444 size_t after_offset = pos + template_data_placeholder.size(); | |
| 445 full_html.append(new_tab_html.data() + after_offset, | |
| 446 new_tab_html.size() - after_offset); | |
| 437 } else { | 447 } else { |
| 438 base::StringPiece new_tab_html(ResourceBundle::GetSharedInstance(). | 448 NOTREACHED(); |
| 439 GetRawDataResource(IDR_NEW_TAB_HTML)); | 449 full_html.assign(new_tab_html.data(), new_tab_html.size()); |
| 440 | |
| 441 // Inject the template data into the HTML so that it is available before any | |
| 442 // layout is needed. | |
| 443 std::string json_html; | |
| 444 jstemplate_builder::AppendJsonHtml(&localized_strings, &json_html); | |
| 445 | |
| 446 static const base::StringPiece template_data_placeholder( | |
| 447 "<!-- template data placeholder -->"); | |
| 448 size_t pos = new_tab_html.find(template_data_placeholder); | |
| 449 | |
| 450 if (pos != base::StringPiece::npos) { | |
| 451 full_html.assign(new_tab_html.data(), pos); | |
| 452 full_html.append(json_html); | |
| 453 size_t after_offset = pos + template_data_placeholder.size(); | |
| 454 full_html.append(new_tab_html.data() + after_offset, | |
| 455 new_tab_html.size() - after_offset); | |
| 456 } else { | |
| 457 NOTREACHED(); | |
| 458 full_html.assign(new_tab_html.data(), new_tab_html.size()); | |
| 459 } | |
| 460 } | 450 } |
| 451 #else | |
| 452 base::StringPiece new_tab_html(ResourceBundle::GetSharedInstance(). | |
| 453 GetRawDataResource(IDR_NEW_TAB_4_HTML)); | |
| 454 full_html = jstemplate_builder::GetI18nTemplateHtml(new_tab_html, | |
| 455 &localized_strings); | |
| 456 #endif | |
| 461 | 457 |
| 462 new_tab_html_ = base::RefCountedString::TakeString(&full_html); | 458 new_tab_html_ = base::RefCountedString::TakeString(&full_html); |
| 463 } | 459 } |
| 464 | 460 |
| 465 void NTPResourceCache::CreateNewTabIncognitoCSS() { | 461 void NTPResourceCache::CreateNewTabIncognitoCSS() { |
| 466 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); | 462 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); |
| 467 DCHECK(tp); | 463 DCHECK(tp); |
| 468 | 464 |
| 469 // Get our theme colors | 465 // Get our theme colors |
| 470 SkColor color_background = | 466 SkColor color_background = |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 color_section_header_text_hover)); // $17 | 567 color_section_header_text_hover)); // $17 |
| 572 subst.push_back(SkColorToRGBAString(color_section_header_rule)); // $18 | 568 subst.push_back(SkColorToRGBAString(color_section_header_rule)); // $18 |
| 573 subst.push_back(SkColorToRGBAString( | 569 subst.push_back(SkColorToRGBAString( |
| 574 color_section_header_rule_light)); // $19 | 570 color_section_header_rule_light)); // $19 |
| 575 subst.push_back(SkColorToRGBAString( | 571 subst.push_back(SkColorToRGBAString( |
| 576 SkColorSetA(color_section_header_rule, 0))); // $20 | 572 SkColorSetA(color_section_header_rule, 0))); // $20 |
| 577 subst.push_back(SkColorToRGBAString(color_text_light)); // $21 | 573 subst.push_back(SkColorToRGBAString(color_text_light)); // $21 |
| 578 subst.push_back(SkColorToRGBComponents(color_section_border)); // $22 | 574 subst.push_back(SkColorToRGBComponents(color_section_border)); // $22 |
| 579 subst.push_back(SkColorToRGBComponents(color_text)); // $23 | 575 subst.push_back(SkColorToRGBComponents(color_text)); // $23 |
| 580 | 576 |
| 577 #if !defined(TOUCH_UI) | |
| 581 // Get our template. | 578 // Get our template. |
| 582 int ntp_css_resource_id = NewTabUI::NTP4Enabled() ? | 579 int ntp_css_resource_id = IDR_NEW_TAB_4_THEME_CSS; |
| 583 IDR_NEW_TAB_4_THEME_CSS : IDR_NEW_TAB_THEME_CSS; | |
| 584 static const base::StringPiece new_tab_theme_css( | 580 static const base::StringPiece new_tab_theme_css( |
| 585 ResourceBundle::GetSharedInstance().GetRawDataResource( | 581 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 586 ntp_css_resource_id)); | 582 ntp_css_resource_id)); |
| 587 | 583 |
| 588 // Create the string from our template and the replacements. | 584 // Create the string from our template and the replacements. |
| 589 std::string css_string; | 585 std::string css_string; |
| 590 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); | 586 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); |
| 591 new_tab_css_ = base::RefCountedString::TakeString(&css_string); | 587 new_tab_css_ = base::RefCountedString::TakeString(&css_string); |
|
Rick Byers
2011/09/26 16:05:26
I know touch_ntp doesn't rely on any of the theme
| |
| 588 #endif | |
| 592 } | 589 } |
| OLD | NEW |