| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 #endif | 83 #endif |
| 84 | 84 |
| 85 // The URL for the Learn More page shown on guest session new tab. | 85 // The URL for the Learn More page shown on guest session new tab. |
| 86 const char kLearnMoreGuestSessionUrl[] = | 86 const char kLearnMoreGuestSessionUrl[] = |
| 87 #if defined(OS_CHROMEOS) | 87 #if defined(OS_CHROMEOS) |
| 88 "https://support.google.com/chromebook/?p=chromebook_guest"; | 88 "https://support.google.com/chromebook/?p=chromebook_guest"; |
| 89 #else | 89 #else |
| 90 "https://support.google.com/chrome/?p=ui_guest"; | 90 "https://support.google.com/chrome/?p=ui_guest"; |
| 91 #endif | 91 #endif |
| 92 | 92 |
| 93 std::string SkColorToRGBAString(SkColor color) { | |
| 94 // We convert the alpha using DoubleToString because StringPrintf will use | |
| 95 // locale specific formatters (e.g., use , instead of . in German). | |
| 96 return base::StringPrintf( | |
| 97 "rgba(%d,%d,%d,%s)", | |
| 98 SkColorGetR(color), | |
| 99 SkColorGetG(color), | |
| 100 SkColorGetB(color), | |
| 101 base::DoubleToString(SkColorGetA(color) / 255.0).c_str()); | |
| 102 } | |
| 103 | |
| 104 // Creates an rgb string for an SkColor, but leaves the alpha blank so that the | |
| 105 // css can fill it in. | |
| 106 std::string SkColorToRGBComponents(SkColor color) { | |
| 107 return base::StringPrintf( | |
| 108 "%d,%d,%d", | |
| 109 SkColorGetR(color), | |
| 110 SkColorGetG(color), | |
| 111 SkColorGetB(color)); | |
| 112 } | |
| 113 | |
| 114 SkColor GetThemeColor(const ui::ThemeProvider& tp, int id) { | 93 SkColor GetThemeColor(const ui::ThemeProvider& tp, int id) { |
| 115 SkColor color = tp.GetColor(id); | 94 SkColor color = tp.GetColor(id); |
| 116 // If web contents are being inverted because the system is in high-contrast | 95 // If web contents are being inverted because the system is in high-contrast |
| 117 // mode, any system theme colors we use must be inverted too to cancel out. | 96 // mode, any system theme colors we use must be inverted too to cancel out. |
| 118 return color_utils::IsInvertedColorScheme() ? | 97 return color_utils::IsInvertedColorScheme() ? |
| 119 color_utils::InvertColor(color) : color; | 98 color_utils::InvertColor(color) : color; |
| 120 } | 99 } |
| 121 | 100 |
| 122 // Get the CSS string for the background position on the new tab page for the | 101 // Get the CSS string for the background position on the new tab page for the |
| 123 // states when the bar is attached or detached. | 102 // states when the bar is attached or detached. |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 : SkColorSetRGB(0x32, 0x32, 0x32); | 492 : SkColorSetRGB(0x32, 0x32, 0x32); |
| 514 | 493 |
| 515 // Generate the replacements. | 494 // Generate the replacements. |
| 516 ui::TemplateReplacements substitutions; | 495 ui::TemplateReplacements substitutions; |
| 517 | 496 |
| 518 // Cache-buster for background. | 497 // Cache-buster for background. |
| 519 substitutions["themeId"] = | 498 substitutions["themeId"] = |
| 520 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); | 499 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); |
| 521 | 500 |
| 522 // Colors. | 501 // Colors. |
| 523 substitutions["colorBackground"] = SkColorToRGBAString(color_background); | 502 substitutions["colorBackground"] = |
| 503 color_utils::SkColorToRgbaString(color_background); |
| 524 substitutions["backgroundBarDetached"] = GetNewTabBackgroundCSS(tp, false); | 504 substitutions["backgroundBarDetached"] = GetNewTabBackgroundCSS(tp, false); |
| 525 substitutions["backgroundBarAttached"] = GetNewTabBackgroundCSS(tp, true); | 505 substitutions["backgroundBarAttached"] = GetNewTabBackgroundCSS(tp, true); |
| 526 substitutions["backgroundTiling"] = GetNewTabBackgroundTilingCSS(tp); | 506 substitutions["backgroundTiling"] = GetNewTabBackgroundTilingCSS(tp); |
| 527 | 507 |
| 528 // Get our template. | 508 // Get our template. |
| 529 static const base::StringPiece new_tab_theme_css( | 509 static const base::StringPiece new_tab_theme_css( |
| 530 ResourceBundle::GetSharedInstance().GetRawDataResource( | 510 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 531 IDR_NEW_INCOGNITO_TAB_THEME_CSS)); | 511 IDR_NEW_INCOGNITO_TAB_THEME_CSS)); |
| 532 | 512 |
| 533 // Create the string from our template and the replacements. | 513 // Create the string from our template and the replacements. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 SkColorGetB(color_header)); | 545 SkColorGetB(color_header)); |
| 566 | 546 |
| 567 // Generate the replacements. | 547 // Generate the replacements. |
| 568 ui::TemplateReplacements substitutions; | 548 ui::TemplateReplacements substitutions; |
| 569 | 549 |
| 570 // Cache-buster for background. | 550 // Cache-buster for background. |
| 571 substitutions["themeId"] = | 551 substitutions["themeId"] = |
| 572 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); | 552 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); |
| 573 | 553 |
| 574 // Colors. | 554 // Colors. |
| 575 substitutions["colorBackground"] = SkColorToRGBAString(color_background); | 555 substitutions["colorBackground"] = |
| 556 color_utils::SkColorToRgbaString(color_background); |
| 576 substitutions["backgroundBarDetached"] = GetNewTabBackgroundCSS(tp, false); | 557 substitutions["backgroundBarDetached"] = GetNewTabBackgroundCSS(tp, false); |
| 577 substitutions["backgroundBarAttached"] = GetNewTabBackgroundCSS(tp, true); | 558 substitutions["backgroundBarAttached"] = GetNewTabBackgroundCSS(tp, true); |
| 578 substitutions["backgroundTiling"] = GetNewTabBackgroundTilingCSS(tp); | 559 substitutions["backgroundTiling"] = GetNewTabBackgroundTilingCSS(tp); |
| 579 substitutions["colorTextRgba"] = SkColorToRGBAString(color_text); | 560 substitutions["colorTextRgba"] = color_utils::SkColorToRgbaString(color_text); |
| 580 substitutions["colorTextLight"] = SkColorToRGBAString(color_text_light); | 561 substitutions["colorTextLight"] = |
| 562 color_utils::SkColorToRgbaString(color_text_light); |
| 581 substitutions["colorSectionBorder"] = | 563 substitutions["colorSectionBorder"] = |
| 582 SkColorToRGBComponents(color_section_border); | 564 color_utils::SkColorToRgbString(color_section_border); |
| 583 substitutions["colorText"] = SkColorToRGBComponents(color_text); | 565 substitutions["colorText"] = color_utils::SkColorToRgbString(color_text); |
| 584 | 566 |
| 585 // For themes that right-align the background, we flip the attribution to the | 567 // For themes that right-align the background, we flip the attribution to the |
| 586 // left to avoid conflicts. | 568 // left to avoid conflicts. |
| 587 int alignment = | 569 int alignment = |
| 588 tp.GetDisplayProperty(ThemeProperties::NTP_BACKGROUND_ALIGNMENT); | 570 tp.GetDisplayProperty(ThemeProperties::NTP_BACKGROUND_ALIGNMENT); |
| 589 if (alignment & ThemeProperties::ALIGN_RIGHT) { | 571 if (alignment & ThemeProperties::ALIGN_RIGHT) { |
| 590 substitutions["leftAlignAttribution"] = "0"; | 572 substitutions["leftAlignAttribution"] = "0"; |
| 591 substitutions["rightAlignAttribution"] = "auto"; | 573 substitutions["rightAlignAttribution"] = "auto"; |
| 592 substitutions["textAlignAttribution"] = "right"; | 574 substitutions["textAlignAttribution"] = "right"; |
| 593 } else { | 575 } else { |
| 594 substitutions["leftAlignAttribution"] = "auto"; | 576 substitutions["leftAlignAttribution"] = "auto"; |
| 595 substitutions["rightAlignAttribution"] = "0"; | 577 substitutions["rightAlignAttribution"] = "0"; |
| 596 substitutions["textAlignAttribution"] = "left"; | 578 substitutions["textAlignAttribution"] = "left"; |
| 597 } | 579 } |
| 598 | 580 |
| 599 substitutions["displayAttribution"] = | 581 substitutions["displayAttribution"] = |
| 600 tp.HasCustomImage(IDR_THEME_NTP_ATTRIBUTION) ? "inline" : "none"; | 582 tp.HasCustomImage(IDR_THEME_NTP_ATTRIBUTION) ? "inline" : "none"; |
| 601 | 583 |
| 602 // Get our template. | 584 // Get our template. |
| 603 static const base::StringPiece new_tab_theme_css( | 585 static const base::StringPiece new_tab_theme_css( |
| 604 ResourceBundle::GetSharedInstance().GetRawDataResource( | 586 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 605 IDR_NEW_TAB_4_THEME_CSS)); | 587 IDR_NEW_TAB_4_THEME_CSS)); |
| 606 | 588 |
| 607 // Create the string from our template and the replacements. | 589 // Create the string from our template and the replacements. |
| 608 std::string css_string = | 590 std::string css_string = |
| 609 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); | 591 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); |
| 610 new_tab_css_ = base::RefCountedString::TakeString(&css_string); | 592 new_tab_css_ = base::RefCountedString::TakeString(&css_string); |
| 611 } | 593 } |
| OLD | NEW |