| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 #include "content/public/browser/browser_thread.h" | 46 #include "content/public/browser/browser_thread.h" |
| 47 #include "content/public/browser/notification_service.h" | 47 #include "content/public/browser/notification_service.h" |
| 48 #include "content/public/browser/render_process_host.h" | 48 #include "content/public/browser/render_process_host.h" |
| 49 #include "extensions/common/extension.h" | 49 #include "extensions/common/extension.h" |
| 50 #include "extensions/common/extension_urls.h" | 50 #include "extensions/common/extension_urls.h" |
| 51 #include "grit/browser_resources.h" | 51 #include "grit/browser_resources.h" |
| 52 #include "grit/components_strings.h" | 52 #include "grit/components_strings.h" |
| 53 #include "grit/theme_resources.h" | 53 #include "grit/theme_resources.h" |
| 54 #include "ui/base/l10n/l10n_util.h" | 54 #include "ui/base/l10n/l10n_util.h" |
| 55 #include "ui/base/resource/resource_bundle.h" | 55 #include "ui/base/resource/resource_bundle.h" |
| 56 #include "ui/base/template_expressions.h" |
| 56 #include "ui/base/theme_provider.h" | 57 #include "ui/base/theme_provider.h" |
| 57 #include "ui/base/webui/jstemplate_builder.h" | 58 #include "ui/base/webui/jstemplate_builder.h" |
| 58 #include "ui/base/webui/web_ui_util.h" | 59 #include "ui/base/webui/web_ui_util.h" |
| 59 #include "ui/gfx/animation/animation.h" | 60 #include "ui/gfx/animation/animation.h" |
| 60 #include "ui/gfx/color_utils.h" | 61 #include "ui/gfx/color_utils.h" |
| 61 | 62 |
| 62 #if defined(OS_CHROMEOS) | 63 #if defined(OS_CHROMEOS) |
| 63 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 64 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 64 #include "chromeos/chromeos_switches.h" | 65 #include "chromeos/chromeos_switches.h" |
| 65 #endif | 66 #endif |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 | 539 |
| 539 void NTPResourceCache::CreateNewTabIncognitoCSS() { | 540 void NTPResourceCache::CreateNewTabIncognitoCSS() { |
| 540 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); | 541 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); |
| 541 DCHECK(tp); | 542 DCHECK(tp); |
| 542 | 543 |
| 543 // Get our theme colors | 544 // Get our theme colors |
| 544 SkColor color_background = | 545 SkColor color_background = |
| 545 GetThemeColor(tp, ThemeProperties::COLOR_NTP_BACKGROUND); | 546 GetThemeColor(tp, ThemeProperties::COLOR_NTP_BACKGROUND); |
| 546 | 547 |
| 547 // Generate the replacements. | 548 // Generate the replacements. |
| 548 std::vector<std::string> subst; | 549 std::map<base::StringPiece, std::string> substitutions; |
| 549 | 550 |
| 550 // Cache-buster for background. | 551 // Cache-buster for background. |
| 551 subst.push_back( | 552 substitutions["themeId"] = |
| 552 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID)); // $1 | 553 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); |
| 553 | 554 |
| 554 // Colors. | 555 // Colors. |
| 555 subst.push_back(SkColorToRGBAString(color_background)); // $2 | 556 substitutions["colorBackground"] = SkColorToRGBAString(color_background); |
| 556 subst.push_back(GetNewTabBackgroundCSS(tp, false)); // $3 | 557 substitutions["backgroundBarDetached"] = GetNewTabBackgroundCSS(tp, false); |
| 557 subst.push_back(GetNewTabBackgroundCSS(tp, true)); // $4 | 558 substitutions["backgroundBarAttached"] = GetNewTabBackgroundCSS(tp, true); |
| 558 subst.push_back(GetNewTabBackgroundTilingCSS(tp)); // $5 | 559 substitutions["backgroundTiling"] = GetNewTabBackgroundTilingCSS(tp); |
| 559 | 560 |
| 560 // Get our template. | 561 // Get our template. |
| 561 static const base::StringPiece new_tab_theme_css( | 562 static const base::StringPiece new_tab_theme_css( |
| 562 ResourceBundle::GetSharedInstance().GetRawDataResource( | 563 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 563 IDR_NEW_INCOGNITO_TAB_THEME_CSS)); | 564 IDR_NEW_INCOGNITO_TAB_THEME_CSS)); |
| 564 | 565 |
| 565 // Create the string from our template and the replacements. | 566 // Create the string from our template and the replacements. |
| 566 std::string full_css = base::ReplaceStringPlaceholders( | 567 std::string full_css = |
| 567 new_tab_theme_css, subst, NULL); | 568 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); |
| 568 | 569 |
| 569 new_tab_incognito_css_ = base::RefCountedString::TakeString(&full_css); | 570 new_tab_incognito_css_ = base::RefCountedString::TakeString(&full_css); |
| 570 } | 571 } |
| 571 | 572 |
| 572 void NTPResourceCache::CreateNewTabGuestCSS() { | 573 void NTPResourceCache::CreateNewTabGuestCSS() { |
| 573 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); | 574 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); |
| 574 DCHECK(tp); | 575 DCHECK(tp); |
| 575 | 576 |
| 576 // Get our theme colors | 577 // Get our theme colors |
| 577 SkColor color_background = | 578 SkColor color_background = |
| 578 GetThemeColor(tp, ThemeProperties::COLOR_NTP_BACKGROUND); | 579 GetThemeColor(tp, ThemeProperties::COLOR_NTP_BACKGROUND); |
| 579 | 580 |
| 580 // Generate the replacements. | 581 // Generate the replacements. |
| 581 std::vector<std::string> subst; | 582 std::map<base::StringPiece, std::string> substitutions; |
| 582 | 583 |
| 583 // Cache-buster for background. | 584 // Cache-buster for background. |
| 584 subst.push_back( | 585 substitutions["themeId"] = |
| 585 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID)); // $1 | 586 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); |
| 586 | 587 |
| 587 // Colors. | 588 // Colors. |
| 588 subst.push_back(SkColorToRGBAString(color_background)); // $2 | 589 substitutions["colorBackground"] = SkColorToRGBAString(color_background); |
| 589 subst.push_back(GetNewTabBackgroundCSS(tp, false)); // $3 | 590 substitutions["backgroundBarDetached"] = GetNewTabBackgroundCSS(tp, false); |
| 590 subst.push_back(GetNewTabBackgroundCSS(tp, true)); // $4 | 591 substitutions["backgroundBarAttached"] = GetNewTabBackgroundCSS(tp, true); |
| 591 subst.push_back(GetNewTabBackgroundTilingCSS(tp)); // $5 | 592 substitutions["backgroundTiling"] = GetNewTabBackgroundTilingCSS(tp); |
| 592 | 593 |
| 593 // Get our template. | 594 // Get our template. |
| 594 static const base::StringPiece new_tab_theme_css( | 595 static const base::StringPiece new_tab_theme_css( |
| 595 ResourceBundle::GetSharedInstance().GetRawDataResource( | 596 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 596 IDR_NEW_INCOGNITO_TAB_THEME_CSS)); | 597 IDR_NEW_INCOGNITO_TAB_THEME_CSS)); |
| 597 | 598 |
| 598 // Create the string from our template and the replacements. | 599 // Create the string from our template and the replacements. |
| 599 std::string full_css = base::ReplaceStringPlaceholders( | 600 std::string full_css = |
| 600 new_tab_theme_css, subst, NULL); | 601 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); |
| 601 | 602 |
| 602 new_tab_guest_css_ = base::RefCountedString::TakeString(&full_css); | 603 new_tab_guest_css_ = base::RefCountedString::TakeString(&full_css); |
| 603 } | 604 } |
| 604 | 605 |
| 605 void NTPResourceCache::CreateNewTabCSS() { | 606 void NTPResourceCache::CreateNewTabCSS() { |
| 606 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); | 607 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); |
| 607 DCHECK(tp); | 608 DCHECK(tp); |
| 608 | 609 |
| 609 // Get our theme colors | 610 // Get our theme colors |
| 610 SkColor color_background = | 611 SkColor color_background = |
| 611 GetThemeColor(tp, ThemeProperties::COLOR_NTP_BACKGROUND); | 612 GetThemeColor(tp, ThemeProperties::COLOR_NTP_BACKGROUND); |
| 612 SkColor color_text = GetThemeColor(tp, ThemeProperties::COLOR_NTP_TEXT); | 613 SkColor color_text = GetThemeColor(tp, ThemeProperties::COLOR_NTP_TEXT); |
| 613 SkColor color_link = GetThemeColor(tp, ThemeProperties::COLOR_NTP_LINK); | |
| 614 SkColor color_link_underline = | |
| 615 GetThemeColor(tp, ThemeProperties::COLOR_NTP_LINK_UNDERLINE); | |
| 616 | |
| 617 SkColor color_section = | |
| 618 GetThemeColor(tp, ThemeProperties::COLOR_NTP_SECTION); | |
| 619 SkColor color_section_text = | |
| 620 GetThemeColor(tp, ThemeProperties::COLOR_NTP_SECTION_TEXT); | |
| 621 SkColor color_section_link = | |
| 622 GetThemeColor(tp, ThemeProperties::COLOR_NTP_SECTION_LINK); | |
| 623 SkColor color_section_link_underline = | |
| 624 GetThemeColor(tp, ThemeProperties::COLOR_NTP_SECTION_LINK_UNDERLINE); | |
| 625 SkColor color_section_header_text = | |
| 626 GetThemeColor(tp, ThemeProperties::COLOR_NTP_SECTION_HEADER_TEXT); | |
| 627 SkColor color_section_header_text_hover = | |
| 628 GetThemeColor(tp, ThemeProperties::COLOR_NTP_SECTION_HEADER_TEXT_HOVER); | |
| 629 SkColor color_section_header_rule = | |
| 630 GetThemeColor(tp, ThemeProperties::COLOR_NTP_SECTION_HEADER_RULE); | |
| 631 SkColor color_section_header_rule_light = | |
| 632 GetThemeColor(tp, ThemeProperties::COLOR_NTP_SECTION_HEADER_RULE_LIGHT); | |
| 633 SkColor color_text_light = | 614 SkColor color_text_light = |
| 634 GetThemeColor(tp, ThemeProperties::COLOR_NTP_TEXT_LIGHT); | 615 GetThemeColor(tp, ThemeProperties::COLOR_NTP_TEXT_LIGHT); |
| 635 | 616 |
| 636 SkColor color_header = | 617 SkColor color_header = |
| 637 GetThemeColor(tp, ThemeProperties::COLOR_NTP_HEADER); | 618 GetThemeColor(tp, ThemeProperties::COLOR_NTP_HEADER); |
| 638 // Generate a lighter color for the header gradients. | 619 // Generate a lighter color for the header gradients. |
| 639 color_utils::HSL header_lighter; | 620 color_utils::HSL header_lighter; |
| 640 color_utils::SkColorToHSL(color_header, &header_lighter); | 621 color_utils::SkColorToHSL(color_header, &header_lighter); |
| 641 header_lighter.l += (1 - header_lighter.l) * 0.33; | 622 header_lighter.l += (1 - header_lighter.l) * 0.33; |
| 642 SkColor color_header_gradient_light = | |
| 643 color_utils::HSLToSkColor(header_lighter, SkColorGetA(color_header)); | |
| 644 | 623 |
| 645 // Generate section border color from the header color. See | 624 // Generate section border color from the header color. See |
| 646 // BookmarkBarView::Paint for how we do this for the bookmark bar | 625 // BookmarkBarView::Paint for how we do this for the bookmark bar |
| 647 // borders. | 626 // borders. |
| 648 SkColor color_section_border = | 627 SkColor color_section_border = |
| 649 SkColorSetARGB(80, | 628 SkColorSetARGB(80, |
| 650 SkColorGetR(color_header), | 629 SkColorGetR(color_header), |
| 651 SkColorGetG(color_header), | 630 SkColorGetG(color_header), |
| 652 SkColorGetB(color_header)); | 631 SkColorGetB(color_header)); |
| 653 | 632 |
| 654 // Generate the replacements. | 633 // Generate the replacements. |
| 655 std::vector<std::string> subst; | 634 std::map<base::StringPiece, std::string> substitutions; |
| 656 | 635 |
| 657 // Cache-buster for background. | 636 // Cache-buster for background. |
| 658 subst.push_back( | 637 substitutions["themeId"] = |
| 659 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID)); // $1 | 638 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); |
| 660 | 639 |
| 661 // Colors. | 640 // Colors. |
| 662 subst.push_back(SkColorToRGBAString(color_background)); // $2 | 641 substitutions["colorBackground"] = SkColorToRGBAString(color_background); |
| 663 subst.push_back(GetNewTabBackgroundCSS(tp, false)); // $3 | 642 substitutions["backgroundBarDetached"] = GetNewTabBackgroundCSS(tp, false); |
| 664 subst.push_back(GetNewTabBackgroundCSS(tp, true)); // $4 | 643 substitutions["backgroundBarAttached"] = GetNewTabBackgroundCSS(tp, true); |
| 665 subst.push_back(GetNewTabBackgroundTilingCSS(tp)); // $5 | 644 substitutions["backgroundTiling"] = GetNewTabBackgroundTilingCSS(tp); |
| 666 subst.push_back(SkColorToRGBAString(color_header)); // $6 | 645 substitutions["colorTextRgba"] = SkColorToRGBAString(color_text); |
| 667 subst.push_back(SkColorToRGBAString(color_header_gradient_light)); // $7 | 646 substitutions["colorSectionBorder"] = |
| 668 subst.push_back(SkColorToRGBAString(color_text)); // $8 | 647 SkColorToRGBAString(color_section_border); |
| 669 subst.push_back(SkColorToRGBAString(color_link)); // $9 | 648 substitutions["colorTextLight"] = SkColorToRGBAString(color_text_light); |
| 670 subst.push_back(SkColorToRGBAString(color_section)); // $10 | 649 substitutions["colorSectionBorder"] = |
| 671 subst.push_back(SkColorToRGBAString(color_section_border)); // $11 | 650 SkColorToRGBComponents(color_section_border); |
| 672 subst.push_back(SkColorToRGBAString(color_section_text)); // $12 | 651 substitutions["colorText"] = SkColorToRGBComponents(color_text); |
| 673 subst.push_back(SkColorToRGBAString(color_section_link)); // $13 | |
| 674 subst.push_back(SkColorToRGBAString(color_link_underline)); // $14 | |
| 675 subst.push_back(SkColorToRGBAString(color_section_link_underline)); // $15 | |
| 676 subst.push_back(SkColorToRGBAString(color_section_header_text)); // $16 | |
| 677 subst.push_back(SkColorToRGBAString( | |
| 678 color_section_header_text_hover)); // $17 | |
| 679 subst.push_back(SkColorToRGBAString(color_section_header_rule)); // $18 | |
| 680 subst.push_back(SkColorToRGBAString( | |
| 681 color_section_header_rule_light)); // $19 | |
| 682 subst.push_back(SkColorToRGBAString( | |
| 683 SkColorSetA(color_section_header_rule, 0))); // $20 | |
| 684 subst.push_back(SkColorToRGBAString(color_text_light)); // $21 | |
| 685 subst.push_back(SkColorToRGBComponents(color_section_border)); // $22 | |
| 686 subst.push_back(SkColorToRGBComponents(color_text)); // $23 | |
| 687 | 652 |
| 688 // Get our template. | 653 // Get our template. |
| 689 static const base::StringPiece new_tab_theme_css( | 654 static const base::StringPiece new_tab_theme_css( |
| 690 ResourceBundle::GetSharedInstance().GetRawDataResource( | 655 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 691 IDR_NEW_TAB_4_THEME_CSS)); | 656 IDR_NEW_TAB_4_THEME_CSS)); |
| 692 | 657 |
| 693 // Create the string from our template and the replacements. | 658 // Create the string from our template and the replacements. |
| 694 std::string css_string; | 659 std::string css_string = |
| 695 css_string = base::ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); | 660 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); |
| 696 new_tab_css_ = base::RefCountedString::TakeString(&css_string); | 661 new_tab_css_ = base::RefCountedString::TakeString(&css_string); |
| 697 } | 662 } |
| OLD | NEW |