| 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 "content/browser/webui/web_ui_data_source_impl.h" | 5 #include "content/browser/webui/web_ui_data_source_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 int ids) { | 129 int ids) { |
| 130 localized_strings_.SetString( | 130 localized_strings_.SetString( |
| 131 name, GetContentClient()->GetLocalizedString(ids)); | 131 name, GetContentClient()->GetLocalizedString(ids)); |
| 132 replacements_[name] = | 132 replacements_[name] = |
| 133 base::UTF16ToUTF8(GetContentClient()->GetLocalizedString(ids)); | 133 base::UTF16ToUTF8(GetContentClient()->GetLocalizedString(ids)); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void WebUIDataSourceImpl::AddLocalizedStrings( | 136 void WebUIDataSourceImpl::AddLocalizedStrings( |
| 137 const base::DictionaryValue& localized_strings) { | 137 const base::DictionaryValue& localized_strings) { |
| 138 localized_strings_.MergeDictionary(&localized_strings); | 138 localized_strings_.MergeDictionary(&localized_strings); |
| 139 | 139 ui::TemplateReplacementsFromDictionaryValue(localized_strings, |
| 140 for (base::DictionaryValue::Iterator it(localized_strings); !it.IsAtEnd(); | 140 &replacements_); |
| 141 it.Advance()) { | |
| 142 if (it.value().IsType(base::Value::Type::STRING)) { | |
| 143 std::string value; | |
| 144 it.value().GetAsString(&value); | |
| 145 replacements_[it.key()] = value; | |
| 146 } | |
| 147 } | |
| 148 } | 141 } |
| 149 | 142 |
| 150 void WebUIDataSourceImpl::AddBoolean(const std::string& name, bool value) { | 143 void WebUIDataSourceImpl::AddBoolean(const std::string& name, bool value) { |
| 151 localized_strings_.SetBoolean(name, value); | 144 localized_strings_.SetBoolean(name, value); |
| 152 // TODO(dschuyler): Change name of |localized_strings_| to |load_time_data_| | 145 ui::TemplateReplacementsSetBool(name, value, &replacements_); |
| 153 // or similar. These values haven't been found as strings for | |
| 154 // localization. The boolean values are not added to |replacements_| | |
| 155 // for the same reason, that they are used as flags, rather than string | |
| 156 // replacements. | |
| 157 } | 146 } |
| 158 | 147 |
| 159 void WebUIDataSourceImpl::AddInteger(const std::string& name, int32_t value) { | 148 void WebUIDataSourceImpl::AddInteger(const std::string& name, int32_t value) { |
| 160 localized_strings_.SetInteger(name, value); | 149 localized_strings_.SetInteger(name, value); |
| 161 } | 150 } |
| 162 | 151 |
| 163 void WebUIDataSourceImpl::SetJsonPath(const std::string& path) { | 152 void WebUIDataSourceImpl::SetJsonPath(const std::string& path) { |
| 164 DCHECK(json_path_.empty()); | 153 DCHECK(json_path_.empty()); |
| 165 DCHECK(!path.empty()); | 154 DCHECK(!path.empty()); |
| 166 | 155 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 } | 284 } |
| 296 | 285 |
| 297 void WebUIDataSourceImpl::SendLocalizedStringsAsJSON( | 286 void WebUIDataSourceImpl::SendLocalizedStringsAsJSON( |
| 298 const URLDataSource::GotDataCallback& callback) { | 287 const URLDataSource::GotDataCallback& callback) { |
| 299 std::string template_data; | 288 std::string template_data; |
| 300 webui::AppendJsonJS(&localized_strings_, &template_data); | 289 webui::AppendJsonJS(&localized_strings_, &template_data); |
| 301 callback.Run(base::RefCountedString::TakeString(&template_data)); | 290 callback.Run(base::RefCountedString::TakeString(&template_data)); |
| 302 } | 291 } |
| 303 | 292 |
| 304 } // namespace content | 293 } // namespace content |
| OLD | NEW |