Chromium Code Reviews| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 // Creates an rgb string for an SkColor, but leaves the alpha blank so that the | 105 // Creates an rgb string for an SkColor, but leaves the alpha blank so that the |
| 106 // css can fill it in. | 106 // css can fill it in. |
| 107 std::string SkColorToRGBComponents(SkColor color) { | 107 std::string SkColorToRGBComponents(SkColor color) { |
| 108 return base::StringPrintf( | 108 return base::StringPrintf( |
| 109 "%d,%d,%d", | 109 "%d,%d,%d", |
| 110 SkColorGetR(color), | 110 SkColorGetR(color), |
| 111 SkColorGetG(color), | 111 SkColorGetG(color), |
| 112 SkColorGetB(color)); | 112 SkColorGetB(color)); |
| 113 } | 113 } |
| 114 | 114 |
| 115 SkColor GetThemeColor(ui::ThemeProvider* tp, int id) { | 115 SkColor GetThemeColor(const ui::ThemeProvider& tp, int id) { |
| 116 SkColor color = tp->GetColor(id); | 116 SkColor color = tp.GetColor(id); |
| 117 // If web contents are being inverted because the system is in high-contrast | 117 // If web contents are being inverted because the system is in high-contrast |
| 118 // mode, any system theme colors we use must be inverted too to cancel out. | 118 // mode, any system theme colors we use must be inverted too to cancel out. |
| 119 return color_utils::IsInvertedColorScheme() ? | 119 return color_utils::IsInvertedColorScheme() ? |
| 120 color_utils::InvertColor(color) : color; | 120 color_utils::InvertColor(color) : color; |
| 121 } | 121 } |
| 122 | 122 |
| 123 // Get the CSS string for the background position on the new tab page for the | 123 // Get the CSS string for the background position on the new tab page for the |
| 124 // states when the bar is attached or detached. | 124 // states when the bar is attached or detached. |
| 125 std::string GetNewTabBackgroundCSS(const ui::ThemeProvider* theme_provider, | 125 std::string GetNewTabBackgroundCSS(const ui::ThemeProvider& theme_provider, |
| 126 bool bar_attached) { | 126 bool bar_attached) { |
| 127 // TODO(glen): This is a quick workaround to hide the notused.png image when | 127 // TODO(glen): This is a quick workaround to hide the notused.png image when |
| 128 // no image is provided - we don't have time right now to figure out why | 128 // no image is provided - we don't have time right now to figure out why |
| 129 // this is painting as white. | 129 // this is painting as white. |
| 130 // http://crbug.com/17593 | 130 // http://crbug.com/17593 |
| 131 if (!theme_provider->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) { | 131 if (!theme_provider.HasCustomImage(IDR_THEME_NTP_BACKGROUND)) { |
| 132 return "-64px"; | 132 return "-64px"; |
| 133 } | 133 } |
| 134 | 134 |
| 135 int alignment = theme_provider->GetDisplayProperty( | 135 int alignment = theme_provider.GetDisplayProperty( |
| 136 ThemeProperties::NTP_BACKGROUND_ALIGNMENT); | 136 ThemeProperties::NTP_BACKGROUND_ALIGNMENT); |
| 137 | 137 |
| 138 if (bar_attached) | 138 if (bar_attached) |
| 139 return ThemeProperties::AlignmentToString(alignment); | 139 return ThemeProperties::AlignmentToString(alignment); |
| 140 | 140 |
| 141 if (alignment & ThemeProperties::ALIGN_TOP) { | 141 if (alignment & ThemeProperties::ALIGN_TOP) { |
| 142 // The bar is detached, so we must offset the background by the bar size | 142 // The bar is detached, so we must offset the background by the bar size |
| 143 // if it's a top-aligned bar. | 143 // if it's a top-aligned bar. |
| 144 int offset = chrome::kNTPBookmarkBarHeight; | 144 int offset = chrome::kNTPBookmarkBarHeight; |
| 145 | 145 |
| 146 if (alignment & ThemeProperties::ALIGN_LEFT) | 146 if (alignment & ThemeProperties::ALIGN_LEFT) |
| 147 return "left " + base::IntToString(-offset) + "px"; | 147 return "left " + base::IntToString(-offset) + "px"; |
| 148 else if (alignment & ThemeProperties::ALIGN_RIGHT) | 148 else if (alignment & ThemeProperties::ALIGN_RIGHT) |
| 149 return "right " + base::IntToString(-offset) + "px"; | 149 return "right " + base::IntToString(-offset) + "px"; |
| 150 return "center " + base::IntToString(-offset) + "px"; | 150 return "center " + base::IntToString(-offset) + "px"; |
| 151 } | 151 } |
| 152 | 152 |
| 153 return ThemeProperties::AlignmentToString(alignment); | 153 return ThemeProperties::AlignmentToString(alignment); |
| 154 } | 154 } |
| 155 | 155 |
| 156 // How the background image on the new tab page should be tiled (see tiling | 156 // How the background image on the new tab page should be tiled (see tiling |
| 157 // masks in theme_service.h). | 157 // masks in theme_service.h). |
| 158 std::string GetNewTabBackgroundTilingCSS( | 158 std::string GetNewTabBackgroundTilingCSS( |
| 159 const ui::ThemeProvider* theme_provider) { | 159 const ui::ThemeProvider& theme_provider) { |
| 160 int repeat_mode = theme_provider->GetDisplayProperty( | 160 int repeat_mode = |
| 161 ThemeProperties::NTP_BACKGROUND_TILING); | 161 theme_provider.GetDisplayProperty(ThemeProperties::NTP_BACKGROUND_TILING); |
| 162 return ThemeProperties::TilingToString(repeat_mode); | 162 return ThemeProperties::TilingToString(repeat_mode); |
| 163 } | 163 } |
| 164 | 164 |
| 165 } // namespace | 165 } // namespace |
| 166 | 166 |
| 167 NTPResourceCache::NTPResourceCache(Profile* profile) | 167 NTPResourceCache::NTPResourceCache(Profile* profile) |
| 168 : profile_(profile), is_swipe_tracking_from_scroll_events_enabled_(false), | 168 : profile_(profile), is_swipe_tracking_from_scroll_events_enabled_(false), |
| 169 should_show_apps_page_(NewTabUI::ShouldShowApps()), | 169 should_show_apps_page_(NewTabUI::ShouldShowApps()), |
| 170 should_show_other_devices_menu_(true) { | 170 should_show_other_devices_menu_(true) { |
| 171 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 171 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 } | 331 } |
| 332 | 332 |
| 333 localized_strings.SetString("learnMore", | 333 localized_strings.SetString("learnMore", |
| 334 l10n_util::GetStringUTF16(new_tab_link_ids)); | 334 l10n_util::GetStringUTF16(new_tab_link_ids)); |
| 335 localized_strings.SetString("learnMoreLink", new_tab_link); | 335 localized_strings.SetString("learnMoreLink", new_tab_link); |
| 336 | 336 |
| 337 bool bookmark_bar_attached = | 337 bool bookmark_bar_attached = |
| 338 profile_->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar); | 338 profile_->GetPrefs()->GetBoolean(bookmarks::prefs::kShowBookmarkBar); |
| 339 localized_strings.SetBoolean("bookmarkbarattached", bookmark_bar_attached); | 339 localized_strings.SetBoolean("bookmarkbarattached", bookmark_bar_attached); |
| 340 | 340 |
| 341 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); | 341 const ui::ThemeProvider& tp = |
| 342 ThemeService::GetThemeProviderForProfile(profile_); | |
|
pkotwicz
2015/12/04 23:16:50
This looks like |profile_| is always the non-OTR p
Evan Stade
2015/12/09 00:57:11
well, I suppose we might need to change that in th
pkotwicz
2015/12/09 02:08:29
This class fetches colors as well using the ThemeP
Evan Stade
2015/12/09 23:38:40
are you asking me to fix that right now, or pointi
pkotwicz
2015/12/10 01:02:02
I am asking you to fix this right now or to commit
Evan Stade
2015/12/10 01:31:17
I don't understand the urgency. There are no speci
| |
| 342 localized_strings.SetBoolean("hasCustomBackground", | 343 localized_strings.SetBoolean("hasCustomBackground", |
| 343 tp->HasCustomImage(IDR_THEME_NTP_BACKGROUND)); | 344 tp.HasCustomImage(IDR_THEME_NTP_BACKGROUND)); |
| 344 | 345 |
| 345 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 346 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
| 346 webui::SetLoadTimeDataDefaults(app_locale, &localized_strings); | 347 webui::SetLoadTimeDataDefaults(app_locale, &localized_strings); |
| 347 | 348 |
| 348 static const base::StringPiece incognito_tab_html( | 349 static const base::StringPiece incognito_tab_html( |
| 349 ResourceBundle::GetSharedInstance().GetRawDataResource( | 350 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 350 new_tab_html_idr)); | 351 new_tab_html_idr)); |
| 351 | 352 |
| 352 std::string full_html = webui::GetI18nTemplateHtml( | 353 std::string full_html = webui::GetI18nTemplateHtml( |
| 353 incognito_tab_html, &localized_strings); | 354 incognito_tab_html, &localized_strings); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 532 | 533 |
| 533 // Load the new tab page appropriate for this build. | 534 // Load the new tab page appropriate for this build. |
| 534 base::StringPiece new_tab_html(ResourceBundle::GetSharedInstance(). | 535 base::StringPiece new_tab_html(ResourceBundle::GetSharedInstance(). |
| 535 GetRawDataResource(IDR_NEW_TAB_4_HTML)); | 536 GetRawDataResource(IDR_NEW_TAB_4_HTML)); |
| 536 std::string full_html = | 537 std::string full_html = |
| 537 webui::GetI18nTemplateHtml(new_tab_html, &load_time_data); | 538 webui::GetI18nTemplateHtml(new_tab_html, &load_time_data); |
| 538 new_tab_html_ = base::RefCountedString::TakeString(&full_html); | 539 new_tab_html_ = base::RefCountedString::TakeString(&full_html); |
| 539 } | 540 } |
| 540 | 541 |
| 541 void NTPResourceCache::CreateNewTabIncognitoCSS() { | 542 void NTPResourceCache::CreateNewTabIncognitoCSS() { |
| 542 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); | 543 const ui::ThemeProvider& tp = |
| 543 DCHECK(tp); | 544 ThemeService::GetThemeProviderForProfile(profile_); |
| 544 | 545 |
| 545 // Get our theme colors | 546 // Get our theme colors |
| 546 SkColor color_background = | 547 SkColor color_background = |
| 547 tp->HasCustomImage(IDR_THEME_NTP_BACKGROUND) | 548 tp.HasCustomImage(IDR_THEME_NTP_BACKGROUND) |
| 548 ? GetThemeColor(tp, ThemeProperties::COLOR_NTP_BACKGROUND) | 549 ? GetThemeColor(tp, ThemeProperties::COLOR_NTP_BACKGROUND) |
| 549 : SkColorSetRGB(0x32, 0x32, 0x32); | 550 : SkColorSetRGB(0x32, 0x32, 0x32); |
| 550 | 551 |
| 551 // Generate the replacements. | 552 // Generate the replacements. |
| 552 std::map<base::StringPiece, std::string> substitutions; | 553 std::map<base::StringPiece, std::string> substitutions; |
| 553 | 554 |
| 554 // Cache-buster for background. | 555 // Cache-buster for background. |
| 555 substitutions["themeId"] = | 556 substitutions["themeId"] = |
| 556 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); | 557 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); |
| 557 | 558 |
| 558 // Colors. | 559 // Colors. |
| 559 substitutions["colorBackground"] = SkColorToRGBAString(color_background); | 560 substitutions["colorBackground"] = SkColorToRGBAString(color_background); |
| 560 substitutions["backgroundBarDetached"] = GetNewTabBackgroundCSS(tp, false); | 561 substitutions["backgroundBarDetached"] = GetNewTabBackgroundCSS(tp, false); |
| 561 substitutions["backgroundBarAttached"] = GetNewTabBackgroundCSS(tp, true); | 562 substitutions["backgroundBarAttached"] = GetNewTabBackgroundCSS(tp, true); |
| 562 substitutions["backgroundTiling"] = GetNewTabBackgroundTilingCSS(tp); | 563 substitutions["backgroundTiling"] = GetNewTabBackgroundTilingCSS(tp); |
| 563 | 564 |
| 564 // Get our template. | 565 // Get our template. |
| 565 static const base::StringPiece new_tab_theme_css( | 566 static const base::StringPiece new_tab_theme_css( |
| 566 ResourceBundle::GetSharedInstance().GetRawDataResource( | 567 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 567 IDR_NEW_INCOGNITO_TAB_THEME_CSS)); | 568 IDR_NEW_INCOGNITO_TAB_THEME_CSS)); |
| 568 | 569 |
| 569 // Create the string from our template and the replacements. | 570 // Create the string from our template and the replacements. |
| 570 std::string full_css = | 571 std::string full_css = |
| 571 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); | 572 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); |
| 572 | 573 |
| 573 new_tab_incognito_css_ = base::RefCountedString::TakeString(&full_css); | 574 new_tab_incognito_css_ = base::RefCountedString::TakeString(&full_css); |
| 574 } | 575 } |
| 575 | 576 |
| 576 void NTPResourceCache::CreateNewTabCSS() { | 577 void NTPResourceCache::CreateNewTabCSS() { |
| 577 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); | 578 const ui::ThemeProvider& tp = |
| 578 DCHECK(tp); | 579 ThemeService::GetThemeProviderForProfile(profile_); |
| 579 | 580 |
| 580 // Get our theme colors | 581 // Get our theme colors |
| 581 SkColor color_background = | 582 SkColor color_background = |
| 582 GetThemeColor(tp, ThemeProperties::COLOR_NTP_BACKGROUND); | 583 GetThemeColor(tp, ThemeProperties::COLOR_NTP_BACKGROUND); |
| 583 SkColor color_text = GetThemeColor(tp, ThemeProperties::COLOR_NTP_TEXT); | 584 SkColor color_text = GetThemeColor(tp, ThemeProperties::COLOR_NTP_TEXT); |
| 584 SkColor color_text_light = | 585 SkColor color_text_light = |
| 585 GetThemeColor(tp, ThemeProperties::COLOR_NTP_TEXT_LIGHT); | 586 GetThemeColor(tp, ThemeProperties::COLOR_NTP_TEXT_LIGHT); |
| 586 | 587 |
| 587 SkColor color_header = | 588 SkColor color_header = |
| 588 GetThemeColor(tp, ThemeProperties::COLOR_NTP_HEADER); | 589 GetThemeColor(tp, ThemeProperties::COLOR_NTP_HEADER); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 615 substitutions["colorTextRgba"] = SkColorToRGBAString(color_text); | 616 substitutions["colorTextRgba"] = SkColorToRGBAString(color_text); |
| 616 substitutions["colorSectionBorder"] = | 617 substitutions["colorSectionBorder"] = |
| 617 SkColorToRGBAString(color_section_border); | 618 SkColorToRGBAString(color_section_border); |
| 618 substitutions["colorTextLight"] = SkColorToRGBAString(color_text_light); | 619 substitutions["colorTextLight"] = SkColorToRGBAString(color_text_light); |
| 619 substitutions["colorSectionBorder"] = | 620 substitutions["colorSectionBorder"] = |
| 620 SkColorToRGBComponents(color_section_border); | 621 SkColorToRGBComponents(color_section_border); |
| 621 substitutions["colorText"] = SkColorToRGBComponents(color_text); | 622 substitutions["colorText"] = SkColorToRGBComponents(color_text); |
| 622 | 623 |
| 623 // For themes that right-align the background, we flip the attribution to the | 624 // For themes that right-align the background, we flip the attribution to the |
| 624 // left to avoid conflicts. | 625 // left to avoid conflicts. |
| 625 int alignment = tp->GetDisplayProperty( | 626 int alignment = |
| 626 ThemeProperties::NTP_BACKGROUND_ALIGNMENT); | 627 tp.GetDisplayProperty(ThemeProperties::NTP_BACKGROUND_ALIGNMENT); |
| 627 if (alignment & ThemeProperties::ALIGN_RIGHT) { | 628 if (alignment & ThemeProperties::ALIGN_RIGHT) { |
| 628 substitutions["leftAlignAttribution"] = "0"; | 629 substitutions["leftAlignAttribution"] = "0"; |
| 629 substitutions["rightAlignAttribution"] = "auto"; | 630 substitutions["rightAlignAttribution"] = "auto"; |
| 630 substitutions["textAlignAttribution"] = "right"; | 631 substitutions["textAlignAttribution"] = "right"; |
| 631 } else { | 632 } else { |
| 632 substitutions["leftAlignAttribution"] = "auto"; | 633 substitutions["leftAlignAttribution"] = "auto"; |
| 633 substitutions["rightAlignAttribution"] = "0"; | 634 substitutions["rightAlignAttribution"] = "0"; |
| 634 substitutions["textAlignAttribution"] = "left"; | 635 substitutions["textAlignAttribution"] = "left"; |
| 635 } | 636 } |
| 636 | 637 |
| 637 substitutions["displayAttribution"] = | 638 substitutions["displayAttribution"] = |
| 638 tp->HasCustomImage(IDR_THEME_NTP_ATTRIBUTION) ? "inline" : "none"; | 639 tp.HasCustomImage(IDR_THEME_NTP_ATTRIBUTION) ? "inline" : "none"; |
| 639 | 640 |
| 640 // Get our template. | 641 // Get our template. |
| 641 static const base::StringPiece new_tab_theme_css( | 642 static const base::StringPiece new_tab_theme_css( |
| 642 ResourceBundle::GetSharedInstance().GetRawDataResource( | 643 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 643 IDR_NEW_TAB_4_THEME_CSS)); | 644 IDR_NEW_TAB_4_THEME_CSS)); |
| 644 | 645 |
| 645 // Create the string from our template and the replacements. | 646 // Create the string from our template and the replacements. |
| 646 std::string css_string = | 647 std::string css_string = |
| 647 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); | 648 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); |
| 648 new_tab_css_ = base::RefCountedString::TakeString(&css_string); | 649 new_tab_css_ = base::RefCountedString::TakeString(&css_string); |
| 649 } | 650 } |
| OLD | NEW |