| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 130 |
| 130 void SetLoadTimeDataDefaults(const std::string& app_locale, | 131 void SetLoadTimeDataDefaults(const std::string& app_locale, |
| 131 base::DictionaryValue* localized_strings) { | 132 base::DictionaryValue* localized_strings) { |
| 132 localized_strings->SetString("fontfamily", GetFontFamily()); | 133 localized_strings->SetString("fontfamily", GetFontFamily()); |
| 133 localized_strings->SetString("fontsize", GetFontSize()); | 134 localized_strings->SetString("fontsize", GetFontSize()); |
| 134 localized_strings->SetString("language", l10n_util::GetLanguage(app_locale)); | 135 localized_strings->SetString("language", l10n_util::GetLanguage(app_locale)); |
| 135 localized_strings->SetString("textdirection", GetTextDirection()); | 136 localized_strings->SetString("textdirection", GetTextDirection()); |
| 136 } | 137 } |
| 137 | 138 |
| 138 std::string GetWebUiCssTextDefaults() { | 139 std::string GetWebUiCssTextDefaults() { |
| 139 std::vector<std::string> placeholders; | 140 std::map<std::string, std::string> placeholders; |
| 140 placeholders.push_back(GetTextDirection()); // $1 | 141 placeholders["textDirection"] = GetTextDirection(); |
| 141 placeholders.push_back(GetFontFamily()); // $2 | 142 placeholders["fontFamily"] = GetFontFamily(); |
| 142 placeholders.push_back(GetFontSize()); // $3 | 143 placeholders["fontSize"] = GetFontSize(); |
| 143 | 144 |
| 144 const ui::ResourceBundle& resource_bundle = | 145 const ui::ResourceBundle& resource_bundle = |
| 145 ui::ResourceBundle::GetSharedInstance(); | 146 ui::ResourceBundle::GetSharedInstance(); |
| 146 const std::string& css_template = | 147 const std::string& css_template = |
| 147 resource_bundle.GetRawDataResource(IDR_WEBUI_CSS_TEXT_DEFAULTS) | 148 resource_bundle.GetRawDataResource(IDR_WEBUI_CSS_TEXT_DEFAULTS) |
| 148 .as_string(); | 149 .as_string(); |
| 149 | 150 |
| 150 return ReplaceStringPlaceholders(css_template, placeholders, nullptr); | 151 return ui::ReplaceTemplateExpressions(css_template, placeholders); |
| 151 } | 152 } |
| 152 | 153 |
| 153 void AppendWebUiCssTextDefaults(std::string* html) { | 154 void AppendWebUiCssTextDefaults(std::string* html) { |
| 154 html->append("<style>"); | 155 html->append("<style>"); |
| 155 html->append(GetWebUiCssTextDefaults()); | 156 html->append(GetWebUiCssTextDefaults()); |
| 156 html->append("</style>"); | 157 html->append("</style>"); |
| 157 } | 158 } |
| 158 | 159 |
| 159 std::string GetFontFamily() { | 160 std::string GetFontFamily() { |
| 160 std::string font_family = l10n_util::GetStringUTF8( | 161 std::string font_family = l10n_util::GetStringUTF8( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 181 IDS_WEB_FONT_SIZE_XP : | 182 IDS_WEB_FONT_SIZE_XP : |
| 182 #endif | 183 #endif |
| 183 IDS_WEB_FONT_SIZE); | 184 IDS_WEB_FONT_SIZE); |
| 184 } | 185 } |
| 185 | 186 |
| 186 std::string GetTextDirection() { | 187 std::string GetTextDirection() { |
| 187 return base::i18n::IsRTL() ? "rtl" : "ltr"; | 188 return base::i18n::IsRTL() ? "rtl" : "ltr"; |
| 188 } | 189 } |
| 189 | 190 |
| 190 } // namespace webui | 191 } // namespace webui |
| OLD | NEW |