Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: chrome/browser/ui/webui/ntp/ntp_resource_cache.cc

Issue 2714633003: Adds more metadata to the about:webapks page (Closed)
Patch Set: Adds more metadata to the about:webapks page Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 12 matching lines...) Expand all
23 #include "chrome/browser/signin/signin_manager_factory.h" 23 #include "chrome/browser/signin/signin_manager_factory.h"
24 #include "chrome/browser/sync/profile_sync_service_factory.h" 24 #include "chrome/browser/sync/profile_sync_service_factory.h"
25 #include "chrome/browser/themes/theme_properties.h" 25 #include "chrome/browser/themes/theme_properties.h"
26 #include "chrome/browser/themes/theme_service.h" 26 #include "chrome/browser/themes/theme_service.h"
27 #include "chrome/browser/themes/theme_service_factory.h" 27 #include "chrome/browser/themes/theme_service_factory.h"
28 #include "chrome/browser/ui/app_list/app_list_util.h" 28 #include "chrome/browser/ui/app_list/app_list_util.h"
29 #include "chrome/browser/ui/apps/app_info_dialog.h" 29 #include "chrome/browser/ui/apps/app_info_dialog.h"
30 #include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h" 30 #include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h"
31 #include "chrome/browser/ui/sync/sync_promo_ui.h" 31 #include "chrome/browser/ui/sync/sync_promo_ui.h"
32 #include "chrome/browser/ui/webui/app_launcher_login_handler.h" 32 #include "chrome/browser/ui/webui/app_launcher_login_handler.h"
33 #include "chrome/browser/ui/webui/color_utils.h"
33 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" 34 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
34 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 35 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
35 #include "chrome/common/chrome_switches.h" 36 #include "chrome/common/chrome_switches.h"
36 #include "chrome/common/features.h" 37 #include "chrome/common/features.h"
37 #include "chrome/common/pref_names.h" 38 #include "chrome/common/pref_names.h"
38 #include "chrome/common/url_constants.h" 39 #include "chrome/common/url_constants.h"
39 #include "chrome/grit/browser_resources.h" 40 #include "chrome/grit/browser_resources.h"
40 #include "chrome/grit/chromium_strings.h" 41 #include "chrome/grit/chromium_strings.h"
41 #include "chrome/grit/generated_resources.h" 42 #include "chrome/grit/generated_resources.h"
42 #include "chrome/grit/locale_settings.h" 43 #include "chrome/grit/locale_settings.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 #endif 84 #endif
84 85
85 // The URL for the Learn More page shown on guest session new tab. 86 // The URL for the Learn More page shown on guest session new tab.
86 const char kLearnMoreGuestSessionUrl[] = 87 const char kLearnMoreGuestSessionUrl[] =
87 #if defined(OS_CHROMEOS) 88 #if defined(OS_CHROMEOS)
88 "https://support.google.com/chromebook/?p=chromebook_guest"; 89 "https://support.google.com/chromebook/?p=chromebook_guest";
89 #else 90 #else
90 "https://support.google.com/chrome/?p=ui_guest"; 91 "https://support.google.com/chrome/?p=ui_guest";
91 #endif 92 #endif
92 93
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) { 94 SkColor GetThemeColor(const ui::ThemeProvider& tp, int id) {
115 SkColor color = tp.GetColor(id); 95 SkColor color = tp.GetColor(id);
116 // If web contents are being inverted because the system is in high-contrast 96 // 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. 97 // mode, any system theme colors we use must be inverted too to cancel out.
118 return color_utils::IsInvertedColorScheme() ? 98 return color_utils::IsInvertedColorScheme() ?
119 color_utils::InvertColor(color) : color; 99 color_utils::InvertColor(color) : color;
120 } 100 }
121 101
122 // Get the CSS string for the background position on the new tab page for the 102 // Get the CSS string for the background position on the new tab page for the
123 // states when the bar is attached or detached. 103 // states when the bar is attached or detached.
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 : SkColorSetRGB(0x32, 0x32, 0x32); 493 : SkColorSetRGB(0x32, 0x32, 0x32);
514 494
515 // Generate the replacements. 495 // Generate the replacements.
516 ui::TemplateReplacements substitutions; 496 ui::TemplateReplacements substitutions;
517 497
518 // Cache-buster for background. 498 // Cache-buster for background.
519 substitutions["themeId"] = 499 substitutions["themeId"] =
520 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); 500 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID);
521 501
522 // Colors. 502 // Colors.
523 substitutions["colorBackground"] = SkColorToRGBAString(color_background); 503 substitutions["colorBackground"] =
504 ColorUtils::SkColorToRGBAString(color_background);
524 substitutions["backgroundBarDetached"] = GetNewTabBackgroundCSS(tp, false); 505 substitutions["backgroundBarDetached"] = GetNewTabBackgroundCSS(tp, false);
525 substitutions["backgroundBarAttached"] = GetNewTabBackgroundCSS(tp, true); 506 substitutions["backgroundBarAttached"] = GetNewTabBackgroundCSS(tp, true);
526 substitutions["backgroundTiling"] = GetNewTabBackgroundTilingCSS(tp); 507 substitutions["backgroundTiling"] = GetNewTabBackgroundTilingCSS(tp);
527 508
528 // Get our template. 509 // Get our template.
529 static const base::StringPiece new_tab_theme_css( 510 static const base::StringPiece new_tab_theme_css(
530 ResourceBundle::GetSharedInstance().GetRawDataResource( 511 ResourceBundle::GetSharedInstance().GetRawDataResource(
531 IDR_NEW_INCOGNITO_TAB_THEME_CSS)); 512 IDR_NEW_INCOGNITO_TAB_THEME_CSS));
532 513
533 // Create the string from our template and the replacements. 514 // Create the string from our template and the replacements.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 SkColorGetB(color_header)); 546 SkColorGetB(color_header));
566 547
567 // Generate the replacements. 548 // Generate the replacements.
568 ui::TemplateReplacements substitutions; 549 ui::TemplateReplacements substitutions;
569 550
570 // Cache-buster for background. 551 // Cache-buster for background.
571 substitutions["themeId"] = 552 substitutions["themeId"] =
572 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); 553 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID);
573 554
574 // Colors. 555 // Colors.
575 substitutions["colorBackground"] = SkColorToRGBAString(color_background); 556 substitutions["colorBackground"] =
557 ColorUtils::SkColorToRGBAString(color_background);
576 substitutions["backgroundBarDetached"] = GetNewTabBackgroundCSS(tp, false); 558 substitutions["backgroundBarDetached"] = GetNewTabBackgroundCSS(tp, false);
577 substitutions["backgroundBarAttached"] = GetNewTabBackgroundCSS(tp, true); 559 substitutions["backgroundBarAttached"] = GetNewTabBackgroundCSS(tp, true);
578 substitutions["backgroundTiling"] = GetNewTabBackgroundTilingCSS(tp); 560 substitutions["backgroundTiling"] = GetNewTabBackgroundTilingCSS(tp);
579 substitutions["colorTextRgba"] = SkColorToRGBAString(color_text); 561 substitutions["colorTextRgba"] = ColorUtils::SkColorToRGBAString(color_text);
580 substitutions["colorTextLight"] = SkColorToRGBAString(color_text_light); 562 substitutions["colorTextLight"] =
563 ColorUtils::SkColorToRGBAString(color_text_light);
581 substitutions["colorSectionBorder"] = 564 substitutions["colorSectionBorder"] =
582 SkColorToRGBComponents(color_section_border); 565 ColorUtils::SkColorToRGBComponents(color_section_border);
583 substitutions["colorText"] = SkColorToRGBComponents(color_text); 566 substitutions["colorText"] = ColorUtils::SkColorToRGBComponents(color_text);
584 567
585 // For themes that right-align the background, we flip the attribution to the 568 // For themes that right-align the background, we flip the attribution to the
586 // left to avoid conflicts. 569 // left to avoid conflicts.
587 int alignment = 570 int alignment =
588 tp.GetDisplayProperty(ThemeProperties::NTP_BACKGROUND_ALIGNMENT); 571 tp.GetDisplayProperty(ThemeProperties::NTP_BACKGROUND_ALIGNMENT);
589 if (alignment & ThemeProperties::ALIGN_RIGHT) { 572 if (alignment & ThemeProperties::ALIGN_RIGHT) {
590 substitutions["leftAlignAttribution"] = "0"; 573 substitutions["leftAlignAttribution"] = "0";
591 substitutions["rightAlignAttribution"] = "auto"; 574 substitutions["rightAlignAttribution"] = "auto";
592 substitutions["textAlignAttribution"] = "right"; 575 substitutions["textAlignAttribution"] = "right";
593 } else { 576 } else {
594 substitutions["leftAlignAttribution"] = "auto"; 577 substitutions["leftAlignAttribution"] = "auto";
595 substitutions["rightAlignAttribution"] = "0"; 578 substitutions["rightAlignAttribution"] = "0";
596 substitutions["textAlignAttribution"] = "left"; 579 substitutions["textAlignAttribution"] = "left";
597 } 580 }
598 581
599 substitutions["displayAttribution"] = 582 substitutions["displayAttribution"] =
600 tp.HasCustomImage(IDR_THEME_NTP_ATTRIBUTION) ? "inline" : "none"; 583 tp.HasCustomImage(IDR_THEME_NTP_ATTRIBUTION) ? "inline" : "none";
601 584
602 // Get our template. 585 // Get our template.
603 static const base::StringPiece new_tab_theme_css( 586 static const base::StringPiece new_tab_theme_css(
604 ResourceBundle::GetSharedInstance().GetRawDataResource( 587 ResourceBundle::GetSharedInstance().GetRawDataResource(
605 IDR_NEW_TAB_4_THEME_CSS)); 588 IDR_NEW_TAB_4_THEME_CSS));
606 589
607 // Create the string from our template and the replacements. 590 // Create the string from our template and the replacements.
608 std::string css_string = 591 std::string css_string =
609 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions); 592 ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions);
610 new_tab_css_ = base::RefCountedString::TakeString(&css_string); 593 new_tab_css_ = base::RefCountedString::TakeString(&css_string);
611 } 594 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698