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

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

Issue 639823008: Include load_time_data.js automatically with GetI18nTemplateHtml (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix comment Created 6 years, 2 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 | « chrome/browser/resources/supervised_user_block_interstitial.html ('k') | no next file » | 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"
(...skipping 16 matching lines...) Expand all
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 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 JsTemplates 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(
41 ResourceBundle::GetSharedInstance().GetRawDataResource( 41 ResourceBundle::GetSharedInstance().GetRawDataResource(
42 IDR_WEBUI_JS_LOAD_TIME_DATA)); 42 IDR_WEBUI_JS_LOAD_TIME_DATA));
43 43
44 if (load_time_data_src.empty()) { 44 if (load_time_data_src.empty()) {
45 NOTREACHED() << "Unable to get loadTimeData src"; 45 NOTREACHED() << "Unable to get loadTimeData src";
46 return; 46 return;
47 } 47 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 output->append("<script>"); 95 output->append("<script>");
96 i18n_template_src.AppendToString(output); 96 i18n_template_src.AppendToString(output);
97 output->append("</script>"); 97 output->append("</script>");
98 } 98 }
99 99
100 } // namespace 100 } // namespace
101 101
102 std::string GetI18nTemplateHtml(const base::StringPiece& html_template, 102 std::string GetI18nTemplateHtml(const base::StringPiece& html_template,
103 const base::DictionaryValue* json) { 103 const base::DictionaryValue* json) {
104 std::string output(html_template.data(), html_template.size()); 104 std::string output(html_template.data(), html_template.size());
105 AppendLoadTimeData(&output);
105 AppendJsonHtml(json, &output); 106 AppendJsonHtml(json, &output);
106 AppendI18nTemplateSourceHtml(&output); 107 AppendI18nTemplateSourceHtml(&output);
107 return output; 108 return output;
108 } 109 }
109 110
110 std::string GetTemplatesHtml(const base::StringPiece& html_template, 111 std::string GetTemplatesHtml(const base::StringPiece& html_template,
111 const base::DictionaryValue* json, 112 const base::DictionaryValue* json,
112 const base::StringPiece& template_id) { 113 const base::StringPiece& template_id) {
113 std::string output(html_template.data(), html_template.size()); 114 std::string output(html_template.data(), html_template.size());
114 AppendLoadTimeData(&output); 115 AppendLoadTimeData(&output);
(...skipping 10 matching lines...) Expand all
125 126
126 std::string jstext; 127 std::string jstext;
127 JSONStringValueSerializer serializer(&jstext); 128 JSONStringValueSerializer serializer(&jstext);
128 serializer.Serialize(*json); 129 serializer.Serialize(*json);
129 output->append("loadTimeData.data = "); 130 output->append("loadTimeData.data = ");
130 output->append(jstext); 131 output->append(jstext);
131 output->append(";"); 132 output->append(";");
132 } 133 }
133 134
134 } // namespace webui 135 } // namespace webui
OLDNEW
« no previous file with comments | « chrome/browser/resources/supervised_user_block_interstitial.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698