Changes in whitespace in order to try submitting cl and commiting.
[chromium-blink-merge.git] / chrome / common / localized_error.cc
blob5a969bc5fbe5555f1cbf69ba61171aa0d6e29a6c
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
3 // found in the LICENSE file.
5 #include "chrome/common/localized_error.h"
7 #include "base/i18n/rtl.h"
8 #include "base/logging.h"
9 #include "base/strings/string16.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h"
14 #include "chrome/grit/chromium_strings.h"
15 #include "chrome/grit/generated_resources.h"
16 #include "components/error_page/common/error_page_params.h"
17 #include "components/error_page/common/net_error_info.h"
18 #include "net/base/escape.h"
19 #include "net/base/net_errors.h"
20 #include "net/base/net_util.h"
21 #include "third_party/WebKit/public/platform/WebURLError.h"
22 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/webui/web_ui_util.h"
25 #if defined(OS_WIN)
26 #include "base/win/windows_version.h"
27 #endif
29 #if defined(ENABLE_EXTENSIONS)
30 #include "extensions/common/constants.h"
31 #include "extensions/common/extension_icon_set.h"
32 #include "extensions/common/manifest_handlers/icons_handler.h"
33 #endif
35 using blink::WebURLError;
37 // Some error pages have no details.
38 const unsigned int kErrorPagesNoDetails = 0;
40 namespace {
42 static const char kRedirectLoopLearnMoreUrl[] =
43 "https://www.google.com/support/chrome/bin/answer.py?answer=95626";
44 static const char kWeakDHKeyLearnMoreUrl[] =
45 "http://sites.google.com/a/chromium.org/dev/"
46 "err_ssl_weak_server_ephemeral_dh_key";
47 #if defined(OS_CHROMEOS)
48 static const char kAppWarningLearnMoreUrl[] =
49 "chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"
50 "?answer=1721911";
51 #endif // defined(OS_CHROMEOS)
53 enum NAV_SUGGESTIONS {
54 SUGGEST_NONE = 0,
55 SUGGEST_RELOAD = 1 << 0,
56 SUGGEST_CHECK_CONNECTION = 1 << 1,
57 SUGGEST_DNS_CONFIG = 1 << 2,
58 SUGGEST_FIREWALL_CONFIG = 1 << 3,
59 SUGGEST_PROXY_CONFIG = 1 << 4,
60 SUGGEST_DISABLE_EXTENSION = 1 << 5,
61 SUGGEST_LEARNMORE = 1 << 6,
62 SUGGEST_VIEW_POLICIES = 1 << 7,
63 SUGGEST_CONTACT_ADMINISTRATOR = 1 << 8,
66 struct LocalizedErrorMap {
67 int error_code;
68 unsigned int title_resource_id;
69 unsigned int heading_resource_id;
70 // Detailed summary used when the error is in the main frame.
71 unsigned int summary_resource_id;
72 // Short one sentence description shown on mouse over when the error is in
73 // a frame.
74 unsigned int details_resource_id;
75 int suggestions; // Bitmap of SUGGEST_* values.
78 const LocalizedErrorMap net_error_options[] = {
79 {net::ERR_TIMED_OUT,
80 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
81 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
82 IDS_ERRORPAGES_SUMMARY_TIMED_OUT,
83 IDS_ERRORPAGES_DETAILS_TIMED_OUT,
84 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
85 SUGGEST_PROXY_CONFIG,
87 {net::ERR_CONNECTION_TIMED_OUT,
88 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
89 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
90 IDS_ERRORPAGES_SUMMARY_TIMED_OUT,
91 IDS_ERRORPAGES_DETAILS_TIMED_OUT,
92 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
93 SUGGEST_PROXY_CONFIG,
95 {net::ERR_CONNECTION_CLOSED,
96 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
97 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
98 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
99 IDS_ERRORPAGES_DETAILS_CONNECTION_CLOSED,
100 SUGGEST_RELOAD,
102 {net::ERR_CONNECTION_RESET,
103 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
104 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
105 IDS_ERRORPAGES_SUMMARY_CONNECTION_RESET,
106 IDS_ERRORPAGES_DETAILS_CONNECTION_RESET,
107 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
108 SUGGEST_PROXY_CONFIG,
110 {net::ERR_CONNECTION_REFUSED,
111 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
112 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
113 IDS_ERRORPAGES_SUMMARY_CONNECTION_REFUSED,
114 IDS_ERRORPAGES_DETAILS_CONNECTION_REFUSED,
115 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
116 SUGGEST_PROXY_CONFIG,
118 {net::ERR_CONNECTION_FAILED,
119 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
120 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
121 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
122 IDS_ERRORPAGES_DETAILS_CONNECTION_FAILED,
123 SUGGEST_RELOAD,
125 {net::ERR_NAME_NOT_RESOLVED,
126 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
127 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
128 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED,
129 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED,
130 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_DNS_CONFIG |
131 SUGGEST_FIREWALL_CONFIG | SUGGEST_PROXY_CONFIG,
133 {net::ERR_ADDRESS_UNREACHABLE,
134 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
135 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
136 IDS_ERRORPAGES_SUMMARY_ADDRESS_UNREACHABLE,
137 IDS_ERRORPAGES_DETAILS_ADDRESS_UNREACHABLE,
138 SUGGEST_RELOAD | SUGGEST_FIREWALL_CONFIG | SUGGEST_PROXY_CONFIG,
140 {net::ERR_NETWORK_ACCESS_DENIED,
141 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
142 IDS_ERRORPAGES_HEADING_NETWORK_ACCESS_DENIED,
143 IDS_ERRORPAGES_SUMMARY_NETWORK_ACCESS_DENIED,
144 IDS_ERRORPAGES_DETAILS_NETWORK_ACCESS_DENIED,
145 SUGGEST_FIREWALL_CONFIG,
147 {net::ERR_PROXY_CONNECTION_FAILED,
148 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
149 IDS_ERRORPAGES_HEADING_PROXY_CONNECTION_FAILED,
150 IDS_ERRORPAGES_SUMMARY_PROXY_CONNECTION_FAILED,
151 IDS_ERRORPAGES_DETAILS_PROXY_CONNECTION_FAILED,
152 SUGGEST_PROXY_CONFIG,
154 {net::ERR_INTERNET_DISCONNECTED,
155 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
156 IDS_ERRORPAGES_HEADING_INTERNET_DISCONNECTED,
157 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED,
158 IDS_ERRORPAGES_DETAILS_INTERNET_DISCONNECTED,
159 SUGGEST_NONE,
161 {net::ERR_FILE_NOT_FOUND,
162 IDS_ERRORPAGES_TITLE_NOT_FOUND,
163 IDS_ERRORPAGES_HEADING_NOT_FOUND,
164 IDS_ERRORPAGES_SUMMARY_NOT_FOUND,
165 IDS_ERRORPAGES_DETAILS_FILE_NOT_FOUND,
166 SUGGEST_NONE,
168 {net::ERR_CACHE_MISS,
169 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
170 IDS_ERRORPAGES_HEADING_CACHE_MISS,
171 IDS_ERRORPAGES_SUMMARY_CACHE_MISS,
172 IDS_ERRORPAGES_DETAILS_CACHE_MISS,
173 SUGGEST_RELOAD,
175 {net::ERR_CACHE_READ_FAILURE,
176 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
177 IDS_ERRORPAGES_HEADING_CACHE_READ_FAILURE,
178 IDS_ERRORPAGES_SUMMARY_CACHE_READ_FAILURE,
179 IDS_ERRORPAGES_DETAILS_CACHE_READ_FAILURE,
180 SUGGEST_RELOAD,
182 {net::ERR_NETWORK_IO_SUSPENDED,
183 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
184 IDS_ERRORPAGES_HEADING_NETWORK_IO_SUSPENDED,
185 IDS_ERRORPAGES_SUMMARY_NETWORK_IO_SUSPENDED,
186 IDS_ERRORPAGES_DETAILS_NETWORK_IO_SUSPENDED,
187 SUGGEST_RELOAD,
189 {net::ERR_TOO_MANY_REDIRECTS,
190 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
191 IDS_ERRORPAGES_HEADING_TOO_MANY_REDIRECTS,
192 IDS_ERRORPAGES_SUMMARY_TOO_MANY_REDIRECTS,
193 IDS_ERRORPAGES_DETAILS_TOO_MANY_REDIRECTS,
194 SUGGEST_RELOAD | SUGGEST_LEARNMORE,
196 {net::ERR_EMPTY_RESPONSE,
197 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
198 IDS_ERRORPAGES_HEADING_EMPTY_RESPONSE,
199 IDS_ERRORPAGES_SUMMARY_EMPTY_RESPONSE,
200 IDS_ERRORPAGES_DETAILS_EMPTY_RESPONSE,
201 SUGGEST_RELOAD,
203 {net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH,
204 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
205 IDS_ERRORPAGES_HEADING_DUPLICATE_HEADERS,
206 IDS_ERRORPAGES_SUMMARY_DUPLICATE_HEADERS,
207 IDS_ERRORPAGES_DETAILS_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH,
208 SUGGEST_NONE,
210 {net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION,
211 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
212 IDS_ERRORPAGES_HEADING_DUPLICATE_HEADERS,
213 IDS_ERRORPAGES_SUMMARY_DUPLICATE_HEADERS,
214 IDS_ERRORPAGES_DETAILS_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION,
215 SUGGEST_NONE,
217 {net::ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION,
218 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
219 IDS_ERRORPAGES_HEADING_DUPLICATE_HEADERS,
220 IDS_ERRORPAGES_SUMMARY_DUPLICATE_HEADERS,
221 IDS_ERRORPAGES_DETAILS_RESPONSE_HEADERS_MULTIPLE_LOCATION,
222 SUGGEST_NONE,
224 {net::ERR_CONTENT_LENGTH_MISMATCH,
225 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
226 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
227 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
228 IDS_ERRORPAGES_DETAILS_CONNECTION_CLOSED,
229 SUGGEST_RELOAD,
231 {net::ERR_INCOMPLETE_CHUNKED_ENCODING,
232 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
233 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
234 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
235 IDS_ERRORPAGES_DETAILS_CONNECTION_CLOSED,
236 SUGGEST_RELOAD,
238 {net::ERR_SSL_PROTOCOL_ERROR,
239 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
240 IDS_ERRORPAGES_HEADING_SSL_PROTOCOL_ERROR,
241 IDS_ERRORPAGES_SUMMARY_SSL_PROTOCOL_ERROR,
242 IDS_ERRORPAGES_DETAILS_SSL_PROTOCOL_ERROR,
243 SUGGEST_NONE,
245 {net::ERR_SSL_UNSAFE_NEGOTIATION,
246 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
247 IDS_ERRORPAGES_HEADING_SSL_PROTOCOL_ERROR,
248 IDS_ERRORPAGES_SUMMARY_SSL_PROTOCOL_ERROR,
249 IDS_ERRORPAGES_DETAILS_SSL_UNSAFE_NEGOTIATION,
250 SUGGEST_NONE,
252 {net::ERR_BAD_SSL_CLIENT_AUTH_CERT,
253 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
254 IDS_ERRORPAGES_HEADING_BAD_SSL_CLIENT_AUTH_CERT,
255 IDS_ERRORPAGES_SUMMARY_BAD_SSL_CLIENT_AUTH_CERT,
256 IDS_ERRORPAGES_DETAILS_BAD_SSL_CLIENT_AUTH_CERT,
257 SUGGEST_NONE,
259 {net::ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY,
260 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
261 IDS_ERRORPAGES_HEADING_WEAK_SERVER_EPHEMERAL_DH_KEY,
262 IDS_ERRORPAGES_SUMMARY_WEAK_SERVER_EPHEMERAL_DH_KEY,
263 IDS_ERRORPAGES_DETAILS_SSL_PROTOCOL_ERROR,
264 SUGGEST_LEARNMORE,
266 {net::ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN,
267 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
268 IDS_ERRORPAGES_HEADING_PINNING_FAILURE,
269 IDS_ERRORPAGES_SUMMARY_PINNING_FAILURE,
270 IDS_ERRORPAGES_DETAILS_PINNING_FAILURE,
271 SUGGEST_NONE,
273 {net::ERR_TEMPORARILY_THROTTLED,
274 IDS_ERRORPAGES_TITLE_ACCESS_DENIED,
275 IDS_ERRORPAGES_HEADING_ACCESS_DENIED,
276 IDS_ERRORPAGES_SUMMARY_TEMPORARILY_THROTTLED,
277 IDS_ERRORPAGES_DETAILS_TEMPORARILY_THROTTLED,
278 SUGGEST_NONE,
280 {net::ERR_BLOCKED_BY_CLIENT,
281 IDS_ERRORPAGES_TITLE_BLOCKED,
282 IDS_ERRORPAGES_HEADING_BLOCKED,
283 IDS_ERRORPAGES_SUMMARY_BLOCKED,
284 IDS_ERRORPAGES_DETAILS_BLOCKED,
285 SUGGEST_RELOAD | SUGGEST_DISABLE_EXTENSION,
287 {net::ERR_NETWORK_CHANGED,
288 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
289 IDS_ERRORPAGES_HEADING_NETWORK_ACCESS_DENIED,
290 IDS_ERRORPAGES_SUMMARY_NETWORK_CHANGED,
291 IDS_ERRORPAGES_DETAILS_NETWORK_CHANGED,
292 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION,
294 {net::ERR_BLOCKED_BY_ADMINISTRATOR,
295 IDS_ERRORPAGES_TITLE_BLOCKED,
296 IDS_ERRORPAGES_HEADING_BLOCKED_BY_ADMINISTRATOR,
297 IDS_ERRORPAGES_SUMMARY_BLOCKED_BY_ADMINISTRATOR,
298 IDS_ERRORPAGES_DETAILS_BLOCKED_BY_ADMINISTRATOR,
299 SUGGEST_VIEW_POLICIES | SUGGEST_CONTACT_ADMINISTRATOR,
301 {net::ERR_BLOCKED_ENROLLMENT_CHECK_PENDING,
302 IDS_ERRORPAGES_TITLE_BLOCKED,
303 IDS_ERRORPAGES_HEADING_BLOCKED_BY_ADMINISTRATOR,
304 IDS_ERRORPAGES_SUMMARY_BLOCKED_ENROLLMENT_CHECK_PENDING,
305 IDS_ERRORPAGES_DETAILS_BLOCKED_ENROLLMENT_CHECK_PENDING,
306 SUGGEST_CHECK_CONNECTION,
308 {net::ERR_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
309 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
310 IDS_ERRORPAGES_HEADING_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
311 IDS_ERRORPAGES_SUMMARY_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
312 IDS_ERRORPAGES_DETAILS_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
313 SUGGEST_NONE,
315 {net::ERR_SSL_VERSION_OR_CIPHER_MISMATCH,
316 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
317 IDS_ERRORPAGES_HEADING_SSL_VERSION_OR_CIPHER_MISMATCH,
318 IDS_ERRORPAGES_SUMMARY_SSL_VERSION_OR_CIPHER_MISMATCH,
319 IDS_ERRORPAGES_DETAILS_SSL_VERSION_OR_CIPHER_MISMATCH,
320 SUGGEST_NONE,
324 // Special error page to be used in the case of navigating back to a page
325 // generated by a POST. LocalizedError::HasStrings expects this net error code
326 // to also appear in the array above.
327 const LocalizedErrorMap repost_error = {
328 net::ERR_CACHE_MISS,
329 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
330 IDS_HTTP_POST_WARNING_TITLE,
331 IDS_ERRORPAGES_HTTP_POST_WARNING,
332 IDS_ERRORPAGES_DETAILS_CACHE_MISS,
333 SUGGEST_RELOAD,
336 const LocalizedErrorMap http_error_options[] = {
337 {403,
338 IDS_ERRORPAGES_TITLE_ACCESS_DENIED,
339 IDS_ERRORPAGES_HEADING_ACCESS_DENIED,
340 IDS_ERRORPAGES_SUMMARY_FORBIDDEN,
341 IDS_ERRORPAGES_DETAILS_FORBIDDEN,
342 SUGGEST_NONE,
344 {410,
345 IDS_ERRORPAGES_TITLE_NOT_FOUND,
346 IDS_ERRORPAGES_HEADING_NOT_FOUND,
347 IDS_ERRORPAGES_SUMMARY_GONE,
348 IDS_ERRORPAGES_DETAILS_GONE,
349 SUGGEST_NONE,
352 {500,
353 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
354 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
355 IDS_ERRORPAGES_SUMMARY_INTERNAL_SERVER_ERROR,
356 IDS_ERRORPAGES_DETAILS_INTERNAL_SERVER_ERROR,
357 SUGGEST_RELOAD,
359 {501,
360 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
361 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
362 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE,
363 IDS_ERRORPAGES_DETAILS_NOT_IMPLEMENTED,
364 SUGGEST_NONE,
366 {502,
367 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
368 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
369 IDS_ERRORPAGES_SUMMARY_BAD_GATEWAY,
370 IDS_ERRORPAGES_DETAILS_BAD_GATEWAY,
371 SUGGEST_RELOAD,
373 {503,
374 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
375 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
376 IDS_ERRORPAGES_SUMMARY_SERVICE_UNAVAILABLE,
377 IDS_ERRORPAGES_DETAILS_SERVICE_UNAVAILABLE,
378 SUGGEST_RELOAD,
380 {504,
381 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
382 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
383 IDS_ERRORPAGES_SUMMARY_GATEWAY_TIMEOUT,
384 IDS_ERRORPAGES_DETAILS_GATEWAY_TIMEOUT,
385 SUGGEST_RELOAD,
387 {505,
388 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
389 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
390 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE,
391 IDS_ERRORPAGES_DETAILS_HTTP_VERSION_NOT_SUPPORTED,
392 SUGGEST_NONE,
396 const LocalizedErrorMap dns_probe_error_options[] = {
397 {chrome_common_net::DNS_PROBE_POSSIBLE,
398 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
399 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
400 IDS_ERRORPAGES_SUMMARY_DNS_PROBE_RUNNING,
401 IDS_ERRORPAGES_DETAILS_DNS_PROBE_RUNNING,
402 SUGGEST_RELOAD,
405 // DNS_PROBE_NOT_RUN is not here; NetErrorHelper will restore the original
406 // error, which might be one of several DNS-related errors.
408 {chrome_common_net::DNS_PROBE_STARTED,
409 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
410 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
411 IDS_ERRORPAGES_SUMMARY_DNS_PROBE_RUNNING,
412 IDS_ERRORPAGES_DETAILS_DNS_PROBE_RUNNING,
413 // Include SUGGEST_RELOAD so the More button doesn't jump when we update.
414 SUGGEST_RELOAD,
417 // DNS_PROBE_FINISHED_UNKNOWN is not here; NetErrorHelper will restore the
418 // original error, which might be one of several DNS-related errors.
420 {chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET,
421 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
422 IDS_ERRORPAGES_HEADING_INTERNET_DISCONNECTED,
423 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED,
424 IDS_ERRORPAGES_DETAILS_INTERNET_DISCONNECTED,
425 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG,
427 {chrome_common_net::DNS_PROBE_FINISHED_BAD_CONFIG,
428 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
429 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
430 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED,
431 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED,
432 SUGGEST_RELOAD | SUGGEST_DNS_CONFIG | SUGGEST_FIREWALL_CONFIG,
434 {chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN,
435 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
436 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
437 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED,
438 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED,
439 SUGGEST_RELOAD,
443 const LocalizedErrorMap* FindErrorMapInArray(const LocalizedErrorMap* maps,
444 size_t num_maps,
445 int error_code) {
446 for (size_t i = 0; i < num_maps; ++i) {
447 if (maps[i].error_code == error_code)
448 return &maps[i];
450 return NULL;
453 const LocalizedErrorMap* LookupErrorMap(const std::string& error_domain,
454 int error_code, bool is_post) {
455 if (error_domain == net::kErrorDomain) {
456 // Display a different page in the special case of navigating through the
457 // history to an uncached page created by a POST.
458 if (is_post && error_code == net::ERR_CACHE_MISS)
459 return &repost_error;
460 return FindErrorMapInArray(net_error_options,
461 arraysize(net_error_options),
462 error_code);
463 } else if (error_domain == LocalizedError::kHttpErrorDomain) {
464 return FindErrorMapInArray(http_error_options,
465 arraysize(http_error_options),
466 error_code);
467 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) {
468 const LocalizedErrorMap* map =
469 FindErrorMapInArray(dns_probe_error_options,
470 arraysize(dns_probe_error_options),
471 error_code);
472 DCHECK(map);
473 return map;
474 } else {
475 NOTREACHED();
476 return NULL;
480 bool LocaleIsRTL() {
481 return base::i18n::IsRTL();
484 // Returns a dictionary containing the strings for the settings menu under the
485 // wrench, and the advanced settings button.
486 base::DictionaryValue* GetStandardMenuItemsText() {
487 base::DictionaryValue* standard_menu_items_text = new base::DictionaryValue();
488 standard_menu_items_text->SetString("settingsTitle",
489 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE));
490 standard_menu_items_text->SetString("advancedTitle",
491 l10n_util::GetStringUTF16(IDS_SETTINGS_SHOW_ADVANCED_SETTINGS));
492 return standard_menu_items_text;
495 // Gets the icon class for a given |error_domain| and |error_code|.
496 const char* GetIconClassForError(const std::string& error_domain,
497 int error_code) {
498 if ((error_code == net::ERR_INTERNET_DISCONNECTED &&
499 error_domain == net::kErrorDomain) ||
500 (error_code == chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET &&
501 error_domain == chrome_common_net::kDnsProbeErrorDomain))
502 return "icon-offline";
504 return "icon-generic";
507 } // namespace
509 const char LocalizedError::kHttpErrorDomain[] = "http";
511 void LocalizedError::GetStrings(int error_code,
512 const std::string& error_domain,
513 const GURL& failed_url,
514 bool is_post,
515 bool show_stale_load_button,
516 const std::string& locale,
517 const std::string& accept_languages,
518 scoped_ptr<error_page::ErrorPageParams> params,
519 base::DictionaryValue* error_strings) {
520 bool rtl = LocaleIsRTL();
521 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr");
522 webui::SetFontAndTextDirection(error_strings);
524 // Grab the strings and settings that depend on the error type. Init
525 // options with default values.
526 LocalizedErrorMap options = {
528 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
529 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
530 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
531 kErrorPagesNoDetails,
532 SUGGEST_NONE,
535 const LocalizedErrorMap* error_map = LookupErrorMap(error_domain, error_code,
536 is_post);
537 if (error_map)
538 options = *error_map;
540 // If we got "access denied" but the url was a file URL, then we say it was a
541 // file instead of just using the "not available" default message. Just adding
542 // ERR_ACCESS_DENIED to the map isn't sufficient, since that message may be
543 // generated by some OSs when the operation doesn't involve a file URL.
544 if (error_domain == net::kErrorDomain &&
545 error_code == net::ERR_ACCESS_DENIED &&
546 failed_url.scheme() == "file") {
547 options.title_resource_id = IDS_ERRORPAGES_TITLE_ACCESS_DENIED;
548 options.heading_resource_id = IDS_ERRORPAGES_HEADING_FILE_ACCESS_DENIED;
549 options.summary_resource_id = IDS_ERRORPAGES_SUMMARY_FILE_ACCESS_DENIED;
550 options.details_resource_id = IDS_ERRORPAGES_DETAILS_FILE_ACCESS_DENIED;
551 options.suggestions = SUGGEST_NONE;
554 base::string16 failed_url_string(net::FormatUrl(
555 failed_url, accept_languages, net::kFormatUrlOmitNothing,
556 net::UnescapeRule::NORMAL, NULL, NULL, NULL));
557 // URLs are always LTR.
558 if (rtl)
559 base::i18n::WrapStringWithLTRFormatting(&failed_url_string);
560 error_strings->SetString("title",
561 l10n_util::GetStringFUTF16(options.title_resource_id, failed_url_string));
562 error_strings->SetString("heading",
563 l10n_util::GetStringUTF16(options.heading_resource_id));
565 std::string icon_class = GetIconClassForError(error_domain, error_code);
566 error_strings->SetString("iconClass", icon_class);
568 base::DictionaryValue* summary = new base::DictionaryValue;
570 // For offline show a summary message underneath the heading.
571 if (error_code == net::ERR_INTERNET_DISCONNECTED ||
572 error_code == chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET) {
573 error_strings->SetString("primaryParagraph",
574 l10n_util::GetStringUTF16(options.summary_resource_id));
575 } else {
576 // Set summary message in the details.
577 summary->SetString("msg",
578 l10n_util::GetStringUTF16(options.summary_resource_id));
580 summary->SetString("failedUrl", failed_url_string);
581 summary->SetString("hostName", net::IDNToUnicode(failed_url.host(),
582 accept_languages));
583 summary->SetString("productName",
584 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
586 error_strings->SetString(
587 "details", l10n_util::GetStringUTF16(IDS_ERRORPAGE_NET_BUTTON_DETAILS));
588 error_strings->SetString(
589 "hideDetails", l10n_util::GetStringUTF16(
590 IDS_ERRORPAGE_NET_BUTTON_HIDE_DETAILS));
591 error_strings->Set("summary", summary);
593 if (options.details_resource_id != kErrorPagesNoDetails) {
594 error_strings->SetString(
595 "errorDetails", l10n_util::GetStringUTF16(options.details_resource_id));
598 base::string16 error_string;
599 if (error_domain == net::kErrorDomain) {
600 // Non-internationalized error string, for debugging Chrome itself.
601 error_string = base::ASCIIToUTF16(net::ErrorToShortString(error_code));
602 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) {
603 std::string ascii_error_string =
604 chrome_common_net::DnsProbeStatusToString(error_code);
605 error_string = base::ASCIIToUTF16(ascii_error_string);
606 } else {
607 DCHECK_EQ(LocalizedError::kHttpErrorDomain, error_domain);
608 error_string = base::IntToString16(error_code);
610 error_strings->SetString("errorCode",
611 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_ERROR_CODE, error_string));
613 // Platform specific information for diagnosing network issues on OSX and
614 // Windows.
615 #if defined(OS_MACOSX) || defined(OS_WIN)
616 if (error_domain == net::kErrorDomain &&
617 error_code == net::ERR_INTERNET_DISCONNECTED) {
618 int platform_string_id =
619 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM;
620 #if defined(OS_WIN)
621 // Different versions of Windows have different instructions.
622 base::win::Version windows_version = base::win::GetVersion();
623 if (windows_version < base::win::VERSION_VISTA) {
624 // XP, XP64, and Server 2003.
625 platform_string_id =
626 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_XP;
627 } else if (windows_version == base::win::VERSION_VISTA) {
628 // Vista
629 platform_string_id =
630 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_VISTA;
632 #endif // defined(OS_WIN)
633 // Platform dependent portion of the summary section.
634 summary->SetString("msg",
635 l10n_util::GetStringFUTF16(
636 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_INSTRUCTIONS_TEMPLATE,
637 l10n_util::GetStringUTF16(platform_string_id)));
639 #endif // defined(OS_MACOSX) || defined(OS_WIN)
641 // If no parameters were provided, use the defaults.
642 if (!params) {
643 params.reset(new error_page::ErrorPageParams());
644 params->suggest_reload = !!(options.suggestions & SUGGEST_RELOAD);
647 base::ListValue* suggestions = NULL;
648 bool use_default_suggestions = true;
649 if (!params->override_suggestions) {
650 suggestions = new base::ListValue();
651 } else {
652 suggestions = params->override_suggestions.release();
653 use_default_suggestions = false;
656 error_strings->Set("suggestions", suggestions);
658 if (params->search_url.is_valid()) {
659 error_strings->SetString("searchHeader",
660 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_GOOGLE_SEARCH));
661 error_strings->SetString("searchUrl", params->search_url.spec());
662 error_strings->SetString("searchTerms", params->search_terms);
663 error_strings->SetInteger("searchTrackingId", params->search_tracking_id);
666 // Add the reload suggestion, if needed.
667 if (params->suggest_reload) {
668 if (!is_post) {
669 base::DictionaryValue* reload_button = new base::DictionaryValue;
670 reload_button->SetString(
671 "msg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD));
672 reload_button->SetString("reloadUrl", failed_url.spec());
673 error_strings->Set("reloadButton", reload_button);
674 reload_button->SetInteger("reloadTrackingId", params->reload_tracking_id);
675 } else {
676 // If the page was created by a post, it can't be reloaded in the same
677 // way, so just add a suggestion instead.
678 // TODO(mmenke): Make the reload button bring up the repost confirmation
679 // dialog for pages resulting from posts.
680 base::DictionaryValue* suggest_reload_repost = new base::DictionaryValue;
681 suggest_reload_repost->SetString("header",
682 l10n_util::GetStringUTF16(
683 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_HEADER));
684 suggest_reload_repost->SetString("body",
685 l10n_util::GetStringUTF16(
686 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_BODY));
687 // Add at the front, so it appears before other suggestions, in the case
688 // suggestions are being overridden by |params|.
689 suggestions->Insert(0, suggest_reload_repost);
693 // If not using the default suggestions, nothing else to do.
694 if (!use_default_suggestions)
695 return;
697 if (show_stale_load_button) {
698 base::DictionaryValue* stale_load_button = new base::DictionaryValue;
699 stale_load_button->SetString(
700 "msg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_LOAD_STALE));
701 stale_load_button->SetString(
702 "title",
703 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_LOAD_STALE_HELP));
704 error_strings->Set("staleLoadButton", stale_load_button);
707 #if defined(OS_CHROMEOS)
708 error_strings->SetString(
709 "diagnose", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_DIAGNOSE));
710 #endif // defined(OS_CHROMEOS)
712 if (options.suggestions & SUGGEST_CHECK_CONNECTION) {
713 base::DictionaryValue* suggest_check_connection = new base::DictionaryValue;
714 suggest_check_connection->SetString("header",
715 l10n_util::GetStringUTF16(
716 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER));
717 suggest_check_connection->SetString("body",
718 l10n_util::GetStringUTF16(
719 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_BODY));
720 suggestions->Append(suggest_check_connection);
723 if (options.suggestions & SUGGEST_DNS_CONFIG) {
724 base::DictionaryValue* suggest_dns_config = new base::DictionaryValue;
725 suggest_dns_config->SetString("header",
726 l10n_util::GetStringUTF16(
727 IDS_ERRORPAGES_SUGGESTION_DNS_CONFIG_HEADER));
728 suggest_dns_config->SetString("body",
729 l10n_util::GetStringUTF16(
730 IDS_ERRORPAGES_SUGGESTION_DNS_CONFIG_BODY));
731 suggestions->Append(suggest_dns_config);
733 base::DictionaryValue* suggest_network_prediction =
734 GetStandardMenuItemsText();
735 suggest_network_prediction->SetString("header",
736 l10n_util::GetStringUTF16(
737 IDS_ERRORPAGES_SUGGESTION_NETWORK_PREDICTION_HEADER));
738 suggest_network_prediction->SetString("body",
739 l10n_util::GetStringUTF16(
740 IDS_ERRORPAGES_SUGGESTION_NETWORK_PREDICTION_BODY));
741 suggest_network_prediction->SetString(
742 "noNetworkPredictionTitle",
743 l10n_util::GetStringUTF16(
744 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION));
745 suggestions->Append(suggest_network_prediction);
748 if (options.suggestions & SUGGEST_FIREWALL_CONFIG) {
749 base::DictionaryValue* suggest_firewall_config = new base::DictionaryValue;
750 suggest_firewall_config->SetString("header",
751 l10n_util::GetStringUTF16(
752 IDS_ERRORPAGES_SUGGESTION_FIREWALL_CONFIG_HEADER));
753 suggest_firewall_config->SetString("body",
754 l10n_util::GetStringUTF16(
755 IDS_ERRORPAGES_SUGGESTION_FIREWALL_CONFIG_BODY));
756 suggestions->Append(suggest_firewall_config);
759 if (options.suggestions & SUGGEST_PROXY_CONFIG) {
760 base::DictionaryValue* suggest_proxy_config = GetStandardMenuItemsText();
761 suggest_proxy_config->SetString("header",
762 l10n_util::GetStringUTF16(
763 IDS_ERRORPAGES_SUGGESTION_PROXY_CONFIG_HEADER));
764 suggest_proxy_config->SetString("body",
765 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_SUGGESTION_PROXY_CONFIG_BODY,
766 l10n_util::GetStringUTF16(
767 IDS_ERRORPAGES_SUGGESTION_PROXY_DISABLE_PLATFORM)));
768 suggest_proxy_config->SetString("proxyTitle",
769 l10n_util::GetStringUTF16(IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON));
771 suggestions->Append(suggest_proxy_config);
774 if (options.suggestions & SUGGEST_DISABLE_EXTENSION) {
775 base::DictionaryValue* suggest_disable_extension =
776 new base::DictionaryValue;
777 // There's only a header for this suggestion.
778 suggest_disable_extension->SetString("header",
779 l10n_util::GetStringUTF16(
780 IDS_ERRORPAGES_SUGGESTION_DISABLE_EXTENSION_HEADER));
781 suggestions->Append(suggest_disable_extension);
784 if (options.suggestions & SUGGEST_VIEW_POLICIES) {
785 base::DictionaryValue* suggest_view_policies = new base::DictionaryValue;
786 suggest_view_policies->SetString(
787 "header",
788 l10n_util::GetStringUTF16(
789 IDS_ERRORPAGES_SUGGESTION_VIEW_POLICIES_HEADER));
790 suggest_view_policies->SetString(
791 "body",
792 l10n_util::GetStringUTF16(
793 IDS_ERRORPAGES_SUGGESTION_VIEW_POLICIES_BODY));
794 suggestions->Append(suggest_view_policies);
797 if (options.suggestions & SUGGEST_CONTACT_ADMINISTRATOR) {
798 base::DictionaryValue* suggest_contant_administrator =
799 new base::DictionaryValue;
800 suggest_contant_administrator->SetString(
801 "body",
802 l10n_util::GetStringUTF16(
803 IDS_ERRORPAGES_SUGGESTION_CONTACT_ADMINISTRATOR_BODY));
804 suggestions->Append(suggest_contant_administrator);
807 if (options.suggestions & SUGGEST_LEARNMORE) {
808 GURL learn_more_url;
809 switch (options.error_code) {
810 case net::ERR_TOO_MANY_REDIRECTS:
811 learn_more_url = GURL(kRedirectLoopLearnMoreUrl);
812 break;
813 case net::ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY:
814 learn_more_url = GURL(kWeakDHKeyLearnMoreUrl);
815 break;
816 default:
817 break;
820 if (learn_more_url.is_valid()) {
821 // Add the language parameter to the URL.
822 std::string query = learn_more_url.query() + "&hl=" + locale;
823 GURL::Replacements repl;
824 repl.SetQueryStr(query);
825 learn_more_url = learn_more_url.ReplaceComponents(repl);
827 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue;
828 // There's only a body for this suggestion.
829 suggest_learn_more->SetString("body",
830 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY));
831 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec());
832 suggestions->Append(suggest_learn_more);
837 base::string16 LocalizedError::GetErrorDetails(const blink::WebURLError& error,
838 bool is_post) {
839 const LocalizedErrorMap* error_map =
840 LookupErrorMap(error.domain.utf8(), error.reason, is_post);
841 if (error_map)
842 return l10n_util::GetStringUTF16(error_map->details_resource_id);
843 else
844 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN);
847 bool LocalizedError::HasStrings(const std::string& error_domain,
848 int error_code) {
849 // Whether or not the there are strings for an error does not depend on
850 // whether or not the page was be generated by a POST, so just claim it was
851 // not.
852 return LookupErrorMap(error_domain, error_code, /*is_post=*/false) != NULL;
855 #if defined(ENABLE_EXTENSIONS)
856 void LocalizedError::GetAppErrorStrings(
857 const GURL& display_url,
858 const extensions::Extension* app,
859 base::DictionaryValue* error_strings) {
860 DCHECK(app);
862 bool rtl = LocaleIsRTL();
863 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr");
865 base::string16 failed_url(base::ASCIIToUTF16(display_url.spec()));
866 // URLs are always LTR.
867 if (rtl)
868 base::i18n::WrapStringWithLTRFormatting(&failed_url);
869 error_strings->SetString(
870 "url", l10n_util::GetStringFUTF16(IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
871 failed_url.c_str()));
873 error_strings->SetString("title", app->name());
874 error_strings->SetString(
875 "icon",
876 extensions::IconsInfo::GetIconURL(
877 app,
878 extension_misc::EXTENSION_ICON_GIGANTOR,
879 ExtensionIconSet::MATCH_SMALLER).spec());
880 error_strings->SetString("name", app->name());
881 error_strings->SetString(
882 "msg",
883 l10n_util::GetStringUTF16(IDS_ERRORPAGES_APP_WARNING));
885 #if defined(OS_CHROMEOS)
886 GURL learn_more_url(kAppWarningLearnMoreUrl);
887 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue();
888 suggest_learn_more->SetString("msg",
889 l10n_util::GetStringUTF16(
890 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY));
891 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec());
892 error_strings->Set("suggestionsLearnMore", suggest_learn_more);
893 #endif // defined(OS_CHROMEOS)
895 #endif