| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ui/base/webui/web_ui_util.h" | 5 #include "ui/base/webui/web_ui_util.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 16 #include "net/base/escape.h" | 16 #include "net/base/escape.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/base/template_expressions.h" |
| 19 #include "ui/base/window_open_disposition.h" | 20 #include "ui/base/window_open_disposition.h" |
| 20 #include "ui/gfx/codec/png_codec.h" | 21 #include "ui/gfx/codec/png_codec.h" |
| 21 #include "ui/gfx/font.h" | 22 #include "ui/gfx/font.h" |
| 22 #include "ui/gfx/image/image_skia.h" | 23 #include "ui/gfx/image/image_skia.h" |
| 23 #include "ui/resources/grit/webui_resources.h" | 24 #include "ui/resources/grit/webui_resources.h" |
| 24 #include "ui/strings/grit/app_locale_settings.h" | 25 #include "ui/strings/grit/app_locale_settings.h" |
| 25 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 26 | 27 |
| 27 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
| 28 #include "base/win/windows_version.h" | 29 #include "base/win/windows_version.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 113 |
| 113 void SetLoadTimeDataDefaults(const std::string& app_locale, | 114 void SetLoadTimeDataDefaults(const std::string& app_locale, |
| 114 base::DictionaryValue* localized_strings) { | 115 base::DictionaryValue* localized_strings) { |
| 115 localized_strings->SetString("fontfamily", GetFontFamily()); | 116 localized_strings->SetString("fontfamily", GetFontFamily()); |
| 116 localized_strings->SetString("fontsize", GetFontSize()); | 117 localized_strings->SetString("fontsize", GetFontSize()); |
| 117 localized_strings->SetString("language", l10n_util::GetLanguage(app_locale)); | 118 localized_strings->SetString("language", l10n_util::GetLanguage(app_locale)); |
| 118 localized_strings->SetString("textdirection", GetTextDirection()); | 119 localized_strings->SetString("textdirection", GetTextDirection()); |
| 119 } | 120 } |
| 120 | 121 |
| 121 std::string GetWebUiCssTextDefaults() { | 122 std::string GetWebUiCssTextDefaults() { |
| 122 std::vector<std::string> placeholders; | 123 std::map<base::StringPiece, std::string> placeholders; |
| 123 placeholders.push_back(GetTextDirection()); // $1 | 124 placeholders["textDirection"] = GetTextDirection(); |
| 124 placeholders.push_back(GetFontFamily()); // $2 | 125 placeholders["fontFamily"] = GetFontFamily(); |
| 125 placeholders.push_back(GetFontSize()); // $3 | 126 placeholders["fontSize"] = GetFontSize(); |
| 126 | 127 |
| 127 const ui::ResourceBundle& resource_bundle = | 128 const ui::ResourceBundle& resource_bundle = |
| 128 ui::ResourceBundle::GetSharedInstance(); | 129 ui::ResourceBundle::GetSharedInstance(); |
| 129 const std::string& css_template = | 130 const std::string& css_template = |
| 130 resource_bundle.GetRawDataResource(IDR_WEBUI_CSS_TEXT_DEFAULTS) | 131 resource_bundle.GetRawDataResource(IDR_WEBUI_CSS_TEXT_DEFAULTS) |
| 131 .as_string(); | 132 .as_string(); |
| 132 | 133 |
| 133 return base::ReplaceStringPlaceholders(css_template, placeholders, nullptr); | 134 return ui::ReplaceTemplateExpressions(css_template, placeholders); |
| 134 } | 135 } |
| 135 | 136 |
| 136 void AppendWebUiCssTextDefaults(std::string* html) { | 137 void AppendWebUiCssTextDefaults(std::string* html) { |
| 137 html->append("<style>"); | 138 html->append("<style>"); |
| 138 html->append(GetWebUiCssTextDefaults()); | 139 html->append(GetWebUiCssTextDefaults()); |
| 139 html->append("</style>"); | 140 html->append("</style>"); |
| 140 } | 141 } |
| 141 | 142 |
| 142 std::string GetFontFamily() { | 143 std::string GetFontFamily() { |
| 143 std::string font_family = l10n_util::GetStringUTF8( | 144 std::string font_family = l10n_util::GetStringUTF8( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 164 IDS_WEB_FONT_SIZE_XP : | 165 IDS_WEB_FONT_SIZE_XP : |
| 165 #endif | 166 #endif |
| 166 IDS_WEB_FONT_SIZE); | 167 IDS_WEB_FONT_SIZE); |
| 167 } | 168 } |
| 168 | 169 |
| 169 std::string GetTextDirection() { | 170 std::string GetTextDirection() { |
| 170 return base::i18n::IsRTL() ? "rtl" : "ltr"; | 171 return base::i18n::IsRTL() ? "rtl" : "ltr"; |
| 171 } | 172 } |
| 172 | 173 |
| 173 } // namespace webui | 174 } // namespace webui |
| OLD | NEW |