| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/common/jstemplate_builder.h" | 8 #include "chrome/common/jstemplate_builder.h" |
| 9 | 9 |
| 10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 serializer.Serialize(*json); | 36 serializer.Serialize(*json); |
| 37 // </ confuses the HTML parser because it could be a </script> tag. So we | 37 // </ confuses the HTML parser because it could be a </script> tag. So we |
| 38 // replace </ with <\/. The extra \ will be ignored by the JS engine. | 38 // replace </ with <\/. The extra \ will be ignored by the JS engine. |
| 39 ReplaceSubstringsAfterOffset(&jstext, 0, "</", "<\\/"); | 39 ReplaceSubstringsAfterOffset(&jstext, 0, "</", "<\\/"); |
| 40 | 40 |
| 41 std::string output(html_template.data(), html_template.size()); | 41 std::string output(html_template.data(), html_template.size()); |
| 42 output.append("<script>"); | 42 output.append("<script>"); |
| 43 output.append(jstemplate_src.data(), jstemplate_src.size()); | 43 output.append(jstemplate_src.data(), jstemplate_src.size()); |
| 44 output.append("var tp = document.getElementById('"); | 44 output.append("var tp = document.getElementById('"); |
| 45 output.append(template_id.data(), template_id.size()); | 45 output.append(template_id.data(), template_id.size()); |
| 46 output.append("'); var cx = new JsExprContext("); | 46 output.append("'); var cx = new JsEvalContext("); |
| 47 output.append(jstext); | 47 output.append(jstext); |
| 48 output.append("); jstProcess(cx, tp);</script>"); | 48 output.append("); jstProcess(cx, tp);</script>"); |
| 49 | 49 |
| 50 return output; | 50 return output; |
| 51 } | 51 } |
| 52 | 52 |
| 53 } // namespace jstemplate_builder | 53 } // namespace jstemplate_builder |
| OLD | NEW |