| 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 // 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/webui/jstemplate_builder.h" | 8 #include "ui/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/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "grit/webui_resources.h" | 14 #include "grit/webui_resources.h" |
| 15 #include "ui/base/layout.h" | 15 #include "ui/base/layout.h" |
| 16 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // Non-zero when building version 2 templates. See UseVersion2 class. | 20 // Non-zero when building version 2 templates. See UseVersion2 class. |
| 21 int g_version2 = 0; | 21 int g_version2 = 0; |
| 22 | 22 |
| 23 } // namespace | 23 } // namespace |
| 24 | 24 |
| 25 namespace jstemplate_builder { | 25 namespace webui { |
| 26 | 26 |
| 27 UseVersion2::UseVersion2() { | 27 UseVersion2::UseVersion2() { |
| 28 g_version2++; | 28 g_version2++; |
| 29 } | 29 } |
| 30 | 30 |
| 31 UseVersion2::~UseVersion2() { | 31 UseVersion2::~UseVersion2() { |
| 32 g_version2--; | 32 g_version2--; |
| 33 } | 33 } |
| 34 | 34 |
| 35 std::string GetTemplateHtml(const base::StringPiece& html_template, | 35 std::string GetTemplateHtml(const base::StringPiece& html_template, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 58 AppendI18nTemplateSourceHtml(&output); | 58 AppendI18nTemplateSourceHtml(&output); |
| 59 AppendJsTemplateSourceHtml(&output); | 59 AppendJsTemplateSourceHtml(&output); |
| 60 AppendJsonHtml(json, &output); | 60 AppendJsonHtml(json, &output); |
| 61 AppendI18nTemplateProcessHtml(&output); | 61 AppendI18nTemplateProcessHtml(&output); |
| 62 AppendJsTemplateProcessHtml(template_id, &output); | 62 AppendJsTemplateProcessHtml(template_id, &output); |
| 63 return output; | 63 return output; |
| 64 } | 64 } |
| 65 | 65 |
| 66 void AppendJsonHtml(const DictionaryValue* json, std::string* output) { | 66 void AppendJsonHtml(const DictionaryValue* json, std::string* output) { |
| 67 std::string javascript_string; | 67 std::string javascript_string; |
| 68 jstemplate_builder::AppendJsonJS(json, &javascript_string); | 68 AppendJsonJS(json, &javascript_string); |
| 69 | 69 |
| 70 // </ confuses the HTML parser because it could be a </script> tag. So we | 70 // </ confuses the HTML parser because it could be a </script> tag. So we |
| 71 // replace </ with <\/. The extra \ will be ignored by the JS engine. | 71 // replace </ with <\/. The extra \ will be ignored by the JS engine. |
| 72 ReplaceSubstringsAfterOffset(&javascript_string, 0, "</", "<\\/"); | 72 ReplaceSubstringsAfterOffset(&javascript_string, 0, "</", "<\\/"); |
| 73 | 73 |
| 74 output->append("<script>"); | 74 output->append("<script>"); |
| 75 output->append(javascript_string); | 75 output->append(javascript_string); |
| 76 output->append("</script>"); | 76 output->append("</script>"); |
| 77 } | 77 } |
| 78 | 78 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 if (i18n_process_src.empty()) { | 146 if (i18n_process_src.empty()) { |
| 147 NOTREACHED() << "Unable to get i18n process src"; | 147 NOTREACHED() << "Unable to get i18n process src"; |
| 148 return; | 148 return; |
| 149 } | 149 } |
| 150 | 150 |
| 151 output->append("<script>"); | 151 output->append("<script>"); |
| 152 output->append(i18n_process_src.data(), i18n_process_src.size()); | 152 output->append(i18n_process_src.data(), i18n_process_src.size()); |
| 153 output->append("</script>"); | 153 output->append("</script>"); |
| 154 } | 154 } |
| 155 | 155 |
| 156 } // namespace jstemplate_builder | 156 } // namespace webui |
| OLD | NEW |