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

Side by Side Diff: ui/base/webui/jstemplate_builder.cc

Issue 1200393002: Add more string_util functions to base namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@string
Patch Set: Android Created 5 years, 5 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
« no previous file with comments | « tools/gn/setup.cc ('k') | ui/gfx/text_elider_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // A helper function for using JsTemplate. See jstemplate_builder.h for more 5 // A helper function for using JsTemplate. See jstemplate_builder.h for more
6 // info. 6 // info.
7 7
8 #include "ui/base/webui/jstemplate_builder.h" 8 #include "ui/base/webui/jstemplate_builder.h"
9 9
10 #include "base/json/json_file_value_serializer.h" 10 #include "base/json/json_file_value_serializer.h"
11 #include "base/json/json_string_value_serializer.h" 11 #include "base/json/json_string_value_serializer.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "ui/base/layout.h" 14 #include "ui/base/layout.h"
15 #include "ui/base/resource/resource_bundle.h" 15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/resources/grit/webui_resources.h" 16 #include "ui/resources/grit/webui_resources.h"
17 17
18 namespace webui { 18 namespace webui {
19 19
20 namespace { 20 namespace {
21 21
22 // Appends a script tag with a variable name |templateData| that has the JSON 22 // Appends a script tag with a variable name |templateData| that has the JSON
23 // assigned to it. 23 // assigned to it.
24 void AppendJsonHtml(const base::DictionaryValue* json, std::string* output) { 24 void AppendJsonHtml(const base::DictionaryValue* json, std::string* output) {
25 std::string javascript_string; 25 std::string javascript_string;
26 AppendJsonJS(json, &javascript_string); 26 AppendJsonJS(json, &javascript_string);
27 27
28 // </ confuses the HTML parser because it could be a </script> tag. So we 28 // </ confuses the HTML parser because it could be a </script> tag. So we
29 // replace </ with <\/. The extra \ will be ignored by the JS engine. 29 // replace </ with <\/. The extra \ will be ignored by the JS engine.
30 ReplaceSubstringsAfterOffset(&javascript_string, 0, "</", "<\\/"); 30 base::ReplaceSubstringsAfterOffset(&javascript_string, 0, "</", "<\\/");
31 31
32 output->append("<script>"); 32 output->append("<script>");
33 output->append(javascript_string); 33 output->append(javascript_string);
34 output->append("</script>"); 34 output->append("</script>");
35 } 35 }
36 36
37 // Appends the source for load_time_data.js in a script tag. 37 // Appends the source for load_time_data.js in a script tag.
38 void AppendLoadTimeData(std::string* output) { 38 void AppendLoadTimeData(std::string* output) {
39 // fetch and cache the pointer of the jstemplate resource source text. 39 // fetch and cache the pointer of the jstemplate resource source text.
40 base::StringPiece load_time_data_src( 40 base::StringPiece load_time_data_src(
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 126
127 std::string jstext; 127 std::string jstext;
128 JSONStringValueSerializer serializer(&jstext); 128 JSONStringValueSerializer serializer(&jstext);
129 serializer.Serialize(*json); 129 serializer.Serialize(*json);
130 output->append("loadTimeData.data = "); 130 output->append("loadTimeData.data = ");
131 output->append(jstext); 131 output->append(jstext);
132 output->append(";"); 132 output->append(";");
133 } 133 }
134 134
135 } // namespace webui 135 } // namespace webui
OLDNEW
« no previous file with comments | « tools/gn/setup.cc ('k') | ui/gfx/text_elider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698