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

Side by Side Diff: chrome/common/jstemplate_builder.cc

Issue 10387010: Select theme resources from ResourceBundle at requested scale factor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with master. Created 8 years, 7 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 | Annotate | Revision Log
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 // 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 "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/common_resources.h" 14 #include "grit/common_resources.h"
15 #include "ui/base/layout.h"
15 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
16 17
17 namespace { 18 namespace {
18 19
19 // Non-zero when building version 2 templates. See UseVersion2 class. 20 // Non-zero when building version 2 templates. See UseVersion2 class.
20 int g_version2 = 0; 21 int g_version2 = 0;
21 22
22 } // namespace 23 } // namespace
23 24
24 namespace jstemplate_builder { 25 namespace jstemplate_builder {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 serializer.Serialize(*json); 85 serializer.Serialize(*json);
85 output->append(g_version2 ? "loadTimeData.data = " : "var templateData = "); 86 output->append(g_version2 ? "loadTimeData.data = " : "var templateData = ");
86 output->append(jstext); 87 output->append(jstext);
87 output->append(";"); 88 output->append(";");
88 } 89 }
89 90
90 void AppendJsTemplateSourceHtml(std::string* output) { 91 void AppendJsTemplateSourceHtml(std::string* output) {
91 // fetch and cache the pointer of the jstemplate resource source text. 92 // fetch and cache the pointer of the jstemplate resource source text.
92 static const base::StringPiece jstemplate_src( 93 static const base::StringPiece jstemplate_src(
93 ResourceBundle::GetSharedInstance().GetRawDataResource( 94 ResourceBundle::GetSharedInstance().GetRawDataResource(
94 IDR_JSTEMPLATE_JS)); 95 IDR_JSTEMPLATE_JS, ui::SCALE_FACTOR_NONE));
95 96
96 if (jstemplate_src.empty()) { 97 if (jstemplate_src.empty()) {
97 NOTREACHED() << "Unable to get jstemplate src"; 98 NOTREACHED() << "Unable to get jstemplate src";
98 return; 99 return;
99 } 100 }
100 101
101 output->append("<script>"); 102 output->append("<script>");
102 output->append(jstemplate_src.data(), jstemplate_src.size()); 103 output->append(jstemplate_src.data(), jstemplate_src.size());
103 output->append("</script>"); 104 output->append("</script>");
104 } 105 }
105 106
106 void AppendJsTemplateProcessHtml(const base::StringPiece& template_id, 107 void AppendJsTemplateProcessHtml(const base::StringPiece& template_id,
107 std::string* output) { 108 std::string* output) {
108 output->append("<script>"); 109 output->append("<script>");
109 output->append("var tp = document.getElementById('"); 110 output->append("var tp = document.getElementById('");
110 output->append(template_id.data(), template_id.size()); 111 output->append(template_id.data(), template_id.size());
111 output->append("');"); 112 output->append("');");
112 output->append("jstProcess(new JsEvalContext(templateData), tp);"); 113 output->append("jstProcess(new JsEvalContext(templateData), tp);");
113 output->append("</script>"); 114 output->append("</script>");
114 } 115 }
115 116
116 void AppendI18nTemplateSourceHtml(std::string* output) { 117 void AppendI18nTemplateSourceHtml(std::string* output) {
117 // fetch and cache the pointer of the jstemplate resource source text. 118 // fetch and cache the pointer of the jstemplate resource source text.
118 static const base::StringPiece i18n_template_src( 119 static const base::StringPiece i18n_template_src(
119 ResourceBundle::GetSharedInstance().GetRawDataResource( 120 ResourceBundle::GetSharedInstance().GetRawDataResource(
120 IDR_I18N_TEMPLATE_JS)); 121 IDR_I18N_TEMPLATE_JS, ui::SCALE_FACTOR_NONE));
121 static const base::StringPiece i18n_template2_src( 122 static const base::StringPiece i18n_template2_src(
122 ResourceBundle::GetSharedInstance().GetRawDataResource( 123 ResourceBundle::GetSharedInstance().GetRawDataResource(
123 IDR_I18N_TEMPLATE2_JS)); 124 IDR_I18N_TEMPLATE2_JS, ui::SCALE_FACTOR_NONE));
124 const base::StringPiece* template_src = g_version2 ? 125 const base::StringPiece* template_src = g_version2 ?
125 &i18n_template2_src : &i18n_template_src; 126 &i18n_template2_src : &i18n_template_src;
126 127
127 if (template_src->empty()) { 128 if (template_src->empty()) {
128 NOTREACHED() << "Unable to get i18n template src"; 129 NOTREACHED() << "Unable to get i18n template src";
129 return; 130 return;
130 } 131 }
131 132
132 output->append("<script>"); 133 output->append("<script>");
133 output->append(template_src->data(), template_src->size()); 134 output->append(template_src->data(), template_src->size());
134 output->append("</script>"); 135 output->append("</script>");
135 } 136 }
136 137
137 void AppendI18nTemplateProcessHtml(std::string* output) { 138 void AppendI18nTemplateProcessHtml(std::string* output) {
138 if (g_version2) 139 if (g_version2)
139 return; 140 return;
140 141
141 static const base::StringPiece i18n_process_src( 142 static const base::StringPiece i18n_process_src(
142 ResourceBundle::GetSharedInstance().GetRawDataResource( 143 ResourceBundle::GetSharedInstance().GetRawDataResource(
143 IDR_I18N_PROCESS_JS)); 144 IDR_I18N_PROCESS_JS, ui::SCALE_FACTOR_NONE));
144 145
145 if (i18n_process_src.empty()) { 146 if (i18n_process_src.empty()) {
146 NOTREACHED() << "Unable to get i18n process src"; 147 NOTREACHED() << "Unable to get i18n process src";
147 return; 148 return;
148 } 149 }
149 150
150 output->append("<script>"); 151 output->append("<script>");
151 output->append(i18n_process_src.data(), i18n_process_src.size()); 152 output->append(i18n_process_src.data(), i18n_process_src.size());
152 output->append("</script>"); 153 output->append("</script>");
153 } 154 }
154 155
155 } // namespace jstemplate_builder 156 } // namespace jstemplate_builder
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698