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

Side by Side Diff: chrome/renderer/localized_error.cc

Issue 3033050: Rename DictionaryValue's SetStringFromUTF16() to SetString() (and overload). (Closed)
Patch Set: There shouldn't be wstrings in platform-ind. code. Created 10 years, 4 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/renderer/blocked_plugin.cc ('k') | net/proxy/proxy_resolver_js_bindings.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 (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #include "chrome/renderer/localized_error.h" 5 #include "chrome/renderer/localized_error.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string16.h" 10 #include "base/string16.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 125 }
126 126
127 } // namespace 127 } // namespace
128 128
129 void GetLocalizedErrorValues(const WebURLError& error, 129 void GetLocalizedErrorValues(const WebURLError& error,
130 DictionaryValue* error_strings) { 130 DictionaryValue* error_strings) {
131 bool rtl = LocaleIsRTL(); 131 bool rtl = LocaleIsRTL();
132 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr"); 132 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr");
133 133
134 // Grab strings that are applicable to all error pages 134 // Grab strings that are applicable to all error pages
135 error_strings->SetStringFromUTF16("detailsLink", 135 error_strings->SetString("detailsLink",
136 l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_LINK)); 136 l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_LINK));
137 error_strings->SetStringFromUTF16("detailsHeading", 137 error_strings->SetString("detailsHeading",
138 l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_HEADING)); 138 l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_HEADING));
139 139
140 // Grab the strings and settings that depend on the error type. Init 140 // Grab the strings and settings that depend on the error type. Init
141 // options with default values. 141 // options with default values.
142 WebErrorNetErrorMap options = { 142 WebErrorNetErrorMap options = {
143 0, 143 0,
144 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, 144 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
145 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, 145 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
146 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE, 146 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
147 IDS_ERRORPAGES_DETAILS_UNKNOWN, 147 IDS_ERRORPAGES_DETAILS_UNKNOWN,
148 SUGGEST_NONE, 148 SUGGEST_NONE,
149 }; 149 };
150 int error_code = error.reason; 150 int error_code = error.reason;
151 for (size_t i = 0; i < arraysize(net_error_options); ++i) { 151 for (size_t i = 0; i < arraysize(net_error_options); ++i) {
152 if (net_error_options[i].error_code == error_code) { 152 if (net_error_options[i].error_code == error_code) {
153 memcpy(&options, &net_error_options[i], sizeof(WebErrorNetErrorMap)); 153 memcpy(&options, &net_error_options[i], sizeof(WebErrorNetErrorMap));
154 break; 154 break;
155 } 155 }
156 } 156 }
157 157
158 string16 suggestions_heading; 158 string16 suggestions_heading;
159 if (options.suggestions != SUGGEST_NONE) { 159 if (options.suggestions != SUGGEST_NONE) {
160 suggestions_heading = 160 suggestions_heading =
161 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_HEADING); 161 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_HEADING);
162 } 162 }
163 error_strings->SetStringFromUTF16("suggestionsHeading", suggestions_heading); 163 error_strings->SetString("suggestionsHeading", suggestions_heading);
164 164
165 string16 failed_url(ASCIIToUTF16(error.unreachableURL.spec())); 165 string16 failed_url(ASCIIToUTF16(error.unreachableURL.spec()));
166 // URLs are always LTR. 166 // URLs are always LTR.
167 if (rtl) 167 if (rtl)
168 base::i18n::WrapStringWithLTRFormatting(&failed_url); 168 base::i18n::WrapStringWithLTRFormatting(&failed_url);
169 error_strings->SetStringFromUTF16("title", 169 error_strings->SetString("title",
170 l10n_util::GetStringFUTF16(options.title_resource_id, failed_url)); 170 l10n_util::GetStringFUTF16(options.title_resource_id, failed_url));
171 error_strings->SetStringFromUTF16("heading", 171 error_strings->SetString("heading",
172 l10n_util::GetStringUTF16(options.heading_resource_id)); 172 l10n_util::GetStringUTF16(options.heading_resource_id));
173 173
174 DictionaryValue* summary = new DictionaryValue; 174 DictionaryValue* summary = new DictionaryValue;
175 summary->SetStringFromUTF16("msg", 175 summary->SetString("msg",
176 l10n_util::GetStringUTF16(options.summary_resource_id)); 176 l10n_util::GetStringUTF16(options.summary_resource_id));
177 // TODO(tc): we want the unicode url here since it's being displayed 177 // TODO(tc): we want the unicode url here since it's being displayed
178 summary->SetStringFromUTF16("failedUrl", failed_url); 178 summary->SetString("failedUrl", failed_url);
179 error_strings->Set("summary", summary); 179 error_strings->Set("summary", summary);
180 180
181 // Error codes are expected to be negative 181 // Error codes are expected to be negative
182 DCHECK(error_code < 0); 182 DCHECK(error_code < 0);
183 string16 details = l10n_util::GetStringUTF16(options.details_resource_id); 183 string16 details = l10n_util::GetStringUTF16(options.details_resource_id);
184 error_strings->SetStringFromUTF16("details", 184 error_strings->SetString("details",
185 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_DETAILS_TEMPLATE, 185 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_DETAILS_TEMPLATE,
186 base::IntToString16(-error_code), 186 base::IntToString16(-error_code),
187 ASCIIToUTF16(net::ErrorToString(error_code)), 187 ASCIIToUTF16(net::ErrorToString(error_code)),
188 details)); 188 details));
189 189
190 if (options.suggestions & SUGGEST_RELOAD) { 190 if (options.suggestions & SUGGEST_RELOAD) {
191 DictionaryValue* suggest_reload = new DictionaryValue; 191 DictionaryValue* suggest_reload = new DictionaryValue;
192 suggest_reload->SetStringFromUTF16("msg", 192 suggest_reload->SetString("msg",
193 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_RELOAD)); 193 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_RELOAD));
194 suggest_reload->SetStringFromUTF16("reloadUrl", failed_url); 194 suggest_reload->SetString("reloadUrl", failed_url);
195 error_strings->Set("suggestionsReload", suggest_reload); 195 error_strings->Set("suggestionsReload", suggest_reload);
196 } 196 }
197 197
198 if (options.suggestions & SUGGEST_HOSTNAME) { 198 if (options.suggestions & SUGGEST_HOSTNAME) {
199 // Only show the "Go to hostname" suggestion if the failed_url has a path. 199 // Only show the "Go to hostname" suggestion if the failed_url has a path.
200 const GURL& failed_url = error.unreachableURL; 200 const GURL& failed_url = error.unreachableURL;
201 if (std::string() == failed_url.path()) { 201 if (std::string() == failed_url.path()) {
202 DictionaryValue* suggest_home_page = new DictionaryValue; 202 DictionaryValue* suggest_home_page = new DictionaryValue;
203 suggest_home_page->SetStringFromUTF16("suggestionsHomepageMsg", 203 suggest_home_page->SetString("suggestionsHomepageMsg",
204 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_HOMEPAGE)); 204 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_HOMEPAGE));
205 string16 homepage(ASCIIToUTF16(failed_url.GetWithEmptyPath().spec())); 205 string16 homepage(ASCIIToUTF16(failed_url.GetWithEmptyPath().spec()));
206 // URLs are always LTR. 206 // URLs are always LTR.
207 if (rtl) 207 if (rtl)
208 base::i18n::WrapStringWithLTRFormatting(&homepage); 208 base::i18n::WrapStringWithLTRFormatting(&homepage);
209 suggest_home_page->SetStringFromUTF16("homePage", homepage); 209 suggest_home_page->SetString("homePage", homepage);
210 // TODO(tc): we actually want the unicode hostname 210 // TODO(tc): we actually want the unicode hostname
211 suggest_home_page->SetString("hostName", failed_url.host()); 211 suggest_home_page->SetString("hostName", failed_url.host());
212 error_strings->Set("suggestionsHomepage", suggest_home_page); 212 error_strings->Set("suggestionsHomepage", suggest_home_page);
213 } 213 }
214 } 214 }
215 215
216 if (options.suggestions & SUGGEST_LEARNMORE) { 216 if (options.suggestions & SUGGEST_LEARNMORE) {
217 GURL learn_more_url; 217 GURL learn_more_url;
218 switch (options.error_code) { 218 switch (options.error_code) {
219 case net::ERR_TOO_MANY_REDIRECTS: 219 case net::ERR_TOO_MANY_REDIRECTS:
220 learn_more_url = GURL(kRedirectLoopLearnMoreUrl); 220 learn_more_url = GURL(kRedirectLoopLearnMoreUrl);
221 break; 221 break;
222 default: 222 default:
223 break; 223 break;
224 } 224 }
225 225
226 if (learn_more_url.is_valid()) { 226 if (learn_more_url.is_valid()) {
227 // Add the language parameter to the URL. 227 // Add the language parameter to the URL.
228 std::string query = learn_more_url.query() + "&hl=" + 228 std::string query = learn_more_url.query() + "&hl=" +
229 WideToASCII(webkit_glue::GetWebKitLocale()); 229 WideToASCII(webkit_glue::GetWebKitLocale());
230 GURL::Replacements repl; 230 GURL::Replacements repl;
231 repl.SetQueryStr(query); 231 repl.SetQueryStr(query);
232 learn_more_url = learn_more_url.ReplaceComponents(repl); 232 learn_more_url = learn_more_url.ReplaceComponents(repl);
233 233
234 DictionaryValue* suggest_learn_more = new DictionaryValue; 234 DictionaryValue* suggest_learn_more = new DictionaryValue;
235 suggest_learn_more->SetStringFromUTF16("msg", 235 suggest_learn_more->SetString("msg",
236 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE)); 236 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE));
237 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); 237 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec());
238 error_strings->Set("suggestionsLearnMore", suggest_learn_more); 238 error_strings->Set("suggestionsLearnMore", suggest_learn_more);
239 } 239 }
240 } 240 }
241 } 241 }
242 242
243 void GetFormRepostErrorValues(const GURL& display_url, 243 void GetFormRepostErrorValues(const GURL& display_url,
244 DictionaryValue* error_strings) { 244 DictionaryValue* error_strings) {
245 bool rtl = LocaleIsRTL(); 245 bool rtl = LocaleIsRTL();
246 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr"); 246 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr");
247 247
248 string16 failed_url(ASCIIToUTF16(display_url.spec())); 248 string16 failed_url(ASCIIToUTF16(display_url.spec()));
249 // URLs are always LTR. 249 // URLs are always LTR.
250 if (rtl) 250 if (rtl)
251 base::i18n::WrapStringWithLTRFormatting(&failed_url); 251 base::i18n::WrapStringWithLTRFormatting(&failed_url);
252 error_strings->SetStringFromUTF16( 252 error_strings->SetString(
253 "title", l10n_util::GetStringFUTF16(IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, 253 "title", l10n_util::GetStringFUTF16(IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
254 failed_url)); 254 failed_url));
255 error_strings->SetStringFromUTF16( 255 error_strings->SetString(
256 "heading", l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_TITLE)); 256 "heading", l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_TITLE));
257 error_strings->SetString("suggestionsHeading", ""); 257 error_strings->SetString("suggestionsHeading", "");
258 DictionaryValue* summary = new DictionaryValue; 258 DictionaryValue* summary = new DictionaryValue;
259 summary->SetStringFromUTF16( 259 summary->SetString(
260 "msg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_HTTP_POST_WARNING)); 260 "msg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_HTTP_POST_WARNING));
261 error_strings->Set("summary", summary); 261 error_strings->Set("summary", summary);
262 } 262 }
OLDNEW
« no previous file with comments | « chrome/renderer/blocked_plugin.cc ('k') | net/proxy/proxy_resolver_js_bindings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698