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

Side by Side Diff: chrome/browser/ui/webui/options/options_ui.cc

Issue 2607843002: [MD settings] i18n template replacements in shared HTML resources (Closed)
Patch Set: removed TemplateReplacementsSetBool Created 3 years, 11 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 (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/options/options_ui.h" 5 #include "chrome/browser/ui/webui/options/options_ui.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 void StartDataRequest( 168 void StartDataRequest(
169 const std::string& path, 169 const std::string& path,
170 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, 170 const content::ResourceRequestInfo::WebContentsGetter& wc_getter,
171 const content::URLDataSource::GotDataCallback& callback) override; 171 const content::URLDataSource::GotDataCallback& callback) override;
172 std::string GetMimeType(const std::string&) const override; 172 std::string GetMimeType(const std::string&) const override;
173 bool ShouldDenyXFrameOptions() const override; 173 bool ShouldDenyXFrameOptions() const override;
174 174
175 private: 175 private:
176 ~OptionsUIHTMLSource() override; 176 ~OptionsUIHTMLSource() override;
177 void CreateDataSourceMap(); 177 void CreateDataSourceMap();
178 void AddReplacements(base::DictionaryValue* localized_strings);
179 178
180 // Localized strings collection. 179 // Localized strings collection.
181 std::unique_ptr<base::DictionaryValue> localized_strings_; 180 std::unique_ptr<base::DictionaryValue> localized_strings_;
182 std::map<std::string, int> path_to_idr_map_; 181 std::map<std::string, int> path_to_idr_map_;
183 ui::TemplateReplacements replacements_; 182 ui::TemplateReplacements replacements_;
184 183
185 DISALLOW_COPY_AND_ASSIGN(OptionsUIHTMLSource); 184 DISALLOW_COPY_AND_ASSIGN(OptionsUIHTMLSource);
186 }; 185 };
187 186
188 OptionsUIHTMLSource::OptionsUIHTMLSource( 187 OptionsUIHTMLSource::OptionsUIHTMLSource(
189 base::DictionaryValue* localized_strings) { 188 base::DictionaryValue* localized_strings) {
190 DCHECK(localized_strings); 189 DCHECK(localized_strings);
191 AddReplacements(localized_strings);
192 localized_strings_.reset(localized_strings); 190 localized_strings_.reset(localized_strings);
193 CreateDataSourceMap(); 191 CreateDataSourceMap();
194 } 192 }
195 193
196 std::string OptionsUIHTMLSource::GetSource() const { 194 std::string OptionsUIHTMLSource::GetSource() const {
197 return chrome::kChromeUISettingsFrameHost; 195 return chrome::kChromeUISettingsFrameHost;
198 } 196 }
199 197
200 void OptionsUIHTMLSource::StartDataRequest( 198 void OptionsUIHTMLSource::StartDataRequest(
201 const std::string& path, 199 const std::string& path,
202 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, 200 const content::ResourceRequestInfo::WebContentsGetter& wc_getter,
203 const content::URLDataSource::GotDataCallback& callback) { 201 const content::URLDataSource::GotDataCallback& callback) {
204 scoped_refptr<base::RefCountedMemory> response_bytes; 202 scoped_refptr<base::RefCountedMemory> response_bytes;
205 const std::string& app_locale = g_browser_process->GetApplicationLocale(); 203 const std::string& app_locale = g_browser_process->GetApplicationLocale();
206 webui::SetLoadTimeDataDefaults(app_locale, localized_strings_.get()); 204 webui::SetLoadTimeDataDefaults(app_locale, localized_strings_.get());
205 ui::TemplateReplacementsFromDictionaryValue(*(localized_strings_.get()),
Dan Beam 2017/01/04 22:41:20 nit: just *localized_strings_
dschuyler 2017/01/04 23:18:29 Done.
206 &replacements_);
207 207
208 std::map<std::string, int>::iterator result; 208 std::map<std::string, int>::iterator result;
209 result = path_to_idr_map_.find(path); 209 result = path_to_idr_map_.find(path);
210 210
211 if (path == kLocalizedStringsFile) { 211 if (path == kLocalizedStringsFile) {
212 // Return dynamically-generated strings from memory. 212 // Return dynamically-generated strings from memory.
213 std::string strings_js; 213 std::string strings_js;
214 webui::AppendJsonJS(localized_strings_.get(), &strings_js); 214 webui::AppendJsonJS(localized_strings_.get(), &strings_js);
215 response_bytes = base::RefCountedString::TakeString(&strings_js); 215 response_bytes = base::RefCountedString::TakeString(&strings_js);
216 } else if (path == kOptionsBundleJsFile) { 216 } else if (path == kOptionsBundleJsFile) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 path_to_idr_map_[kSettingsPrefsBehaviorHTMLPath] = 280 path_to_idr_map_[kSettingsPrefsBehaviorHTMLPath] =
281 IDR_SETTINGS_PREFS_BEHAVIOR_HTML; 281 IDR_SETTINGS_PREFS_BEHAVIOR_HTML;
282 path_to_idr_map_[kSettingsPrefsBehaviorJSPath] = 282 path_to_idr_map_[kSettingsPrefsBehaviorJSPath] =
283 IDR_SETTINGS_PREFS_BEHAVIOR_JS; 283 IDR_SETTINGS_PREFS_BEHAVIOR_JS;
284 path_to_idr_map_[kSettingsPrefsTypesHTMLPath] = IDR_SETTINGS_PREFS_TYPES_HTML; 284 path_to_idr_map_[kSettingsPrefsTypesHTMLPath] = IDR_SETTINGS_PREFS_TYPES_HTML;
285 path_to_idr_map_[kSettingsPrefsTypesJSPath] = IDR_SETTINGS_PREFS_TYPES_JS; 285 path_to_idr_map_[kSettingsPrefsTypesJSPath] = IDR_SETTINGS_PREFS_TYPES_JS;
286 path_to_idr_map_[kOptionsPolymerHTMLPath] = IDR_OPTIONS_POLYMER_ELEMENTS_HTML; 286 path_to_idr_map_[kOptionsPolymerHTMLPath] = IDR_OPTIONS_POLYMER_ELEMENTS_HTML;
287 #endif 287 #endif
288 } 288 }
289 289
290 void OptionsUIHTMLSource::AddReplacements(
291 base::DictionaryValue* localized_strings) {
292 for (auto it = base::DictionaryValue::Iterator(*localized_strings);
293 !it.IsAtEnd(); it.Advance()) {
294 std::string str_value;
295 if (!it.value().GetAsString(&str_value)) {
296 continue;
297 }
298 replacements_[it.key()] = str_value;
299 }
300 }
301
302 //////////////////////////////////////////////////////////////////////////////// 290 ////////////////////////////////////////////////////////////////////////////////
303 // 291 //
304 // OptionsPageUIHandler 292 // OptionsPageUIHandler
305 // 293 //
306 //////////////////////////////////////////////////////////////////////////////// 294 ////////////////////////////////////////////////////////////////////////////////
307 295
308 OptionsPageUIHandler::OptionsPageUIHandler() { 296 OptionsPageUIHandler::OptionsPageUIHandler() {
309 } 297 }
310 298
311 OptionsPageUIHandler::~OptionsPageUIHandler() { 299 OptionsPageUIHandler::~OptionsPageUIHandler() {
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 // Add only if handler's service is enabled. 564 // Add only if handler's service is enabled.
577 if (handler->IsEnabled()) { 565 if (handler->IsEnabled()) {
578 // Add handler to the list and also pass the ownership. 566 // Add handler to the list and also pass the ownership.
579 web_ui()->AddMessageHandler(handler.release()); 567 web_ui()->AddMessageHandler(handler.release());
580 handler_raw->GetLocalizedValues(localized_strings); 568 handler_raw->GetLocalizedValues(localized_strings);
581 handlers_.push_back(handler_raw); 569 handlers_.push_back(handler_raw);
582 } 570 }
583 } 571 }
584 572
585 } // namespace options 573 } // namespace options
OLDNEW
« no previous file with comments | « no previous file | content/browser/webui/web_ui_data_source_impl.cc » ('j') | ui/base/template_expressions.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698