Roll third_party/hunspell_dictionaries version.
[chromium-blink-merge.git] / chrome / common / localized_error.cc
blob5472b778567b20b01b83a26fdb3b89f29467a38d
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 // Returns a dictionary containing the strings for the settings menu under the
481 // wrench, and the advanced settings button.
482 base::DictionaryValue* GetStandardMenuItemsText() {
483 base::DictionaryValue* standard_menu_items_text = new base::DictionaryValue();
484 standard_menu_items_text->SetString("settingsTitle",
485 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE));
486 standard_menu_items_text->SetString("advancedTitle",
487 l10n_util::GetStringUTF16(IDS_SETTINGS_SHOW_ADVANCED_SETTINGS));
488 return standard_menu_items_text;
491 // Gets the icon class for a given |error_domain| and |error_code|.
492 const char* GetIconClassForError(const std::string& error_domain,
493 int error_code) {
494 if ((error_code == net::ERR_INTERNET_DISCONNECTED &&
495 error_domain == net::kErrorDomain) ||
496 (error_code == chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET &&
497 error_domain == chrome_common_net::kDnsProbeErrorDomain))
498 return "icon-offline";
500 return "icon-generic";
503 } // namespace
505 const char LocalizedError::kHttpErrorDomain[] = "http";
507 void LocalizedError::GetStrings(int error_code,
508 const std::string& error_domain,
509 const GURL& failed_url,
510 bool is_post,
511 bool show_stale_load_button,
512 const std::string& locale,
513 const std::string& accept_languages,
514 scoped_ptr<error_page::ErrorPageParams> params,
515 base::DictionaryValue* error_strings) {
516 webui::SetLoadTimeDataDefaults(locale, error_strings);
518 // Grab the strings and settings that depend on the error type. Init
519 // options with default values.
520 LocalizedErrorMap options = {
522 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
523 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
524 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
525 kErrorPagesNoDetails,
526 SUGGEST_NONE,
529 const LocalizedErrorMap* error_map = LookupErrorMap(error_domain, error_code,
530 is_post);
531 if (error_map)
532 options = *error_map;
534 // If we got "access denied" but the url was a file URL, then we say it was a
535 // file instead of just using the "not available" default message. Just adding
536 // ERR_ACCESS_DENIED to the map isn't sufficient, since that message may be
537 // generated by some OSs when the operation doesn't involve a file URL.
538 if (error_domain == net::kErrorDomain &&
539 error_code == net::ERR_ACCESS_DENIED &&
540 failed_url.scheme() == "file") {
541 options.title_resource_id = IDS_ERRORPAGES_TITLE_ACCESS_DENIED;
542 options.heading_resource_id = IDS_ERRORPAGES_HEADING_FILE_ACCESS_DENIED;
543 options.summary_resource_id = IDS_ERRORPAGES_SUMMARY_FILE_ACCESS_DENIED;
544 options.details_resource_id = IDS_ERRORPAGES_DETAILS_FILE_ACCESS_DENIED;
545 options.suggestions = SUGGEST_NONE;
548 base::string16 failed_url_string(net::FormatUrl(
549 failed_url, accept_languages, net::kFormatUrlOmitNothing,
550 net::UnescapeRule::NORMAL, NULL, NULL, NULL));
551 // URLs are always LTR.
552 if (base::i18n::IsRTL())
553 base::i18n::WrapStringWithLTRFormatting(&failed_url_string);
554 error_strings->SetString("title",
555 l10n_util::GetStringFUTF16(options.title_resource_id, failed_url_string));
556 error_strings->SetString("heading",
557 l10n_util::GetStringUTF16(options.heading_resource_id));
559 std::string icon_class = GetIconClassForError(error_domain, error_code);
560 error_strings->SetString("iconClass", icon_class);
562 base::DictionaryValue* summary = new base::DictionaryValue;
564 // For offline show a summary message underneath the heading.
565 if (error_code == net::ERR_INTERNET_DISCONNECTED ||
566 error_code == chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET) {
567 error_strings->SetString("primaryParagraph",
568 l10n_util::GetStringUTF16(options.summary_resource_id));
569 } else {
570 // Set summary message in the details.
571 summary->SetString("msg",
572 l10n_util::GetStringUTF16(options.summary_resource_id));
574 summary->SetString("failedUrl", failed_url_string);
575 summary->SetString("hostName", net::IDNToUnicode(failed_url.host(),
576 accept_languages));
577 summary->SetString("productName",
578 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
580 error_strings->SetString(
581 "details", l10n_util::GetStringUTF16(IDS_ERRORPAGE_NET_BUTTON_DETAILS));
582 error_strings->SetString(
583 "hideDetails", l10n_util::GetStringUTF16(
584 IDS_ERRORPAGE_NET_BUTTON_HIDE_DETAILS));
585 error_strings->Set("summary", summary);
587 if (options.details_resource_id != kErrorPagesNoDetails) {
588 error_strings->SetString(
589 "errorDetails", l10n_util::GetStringUTF16(options.details_resource_id));
592 base::string16 error_string;
593 if (error_domain == net::kErrorDomain) {
594 // Non-internationalized error string, for debugging Chrome itself.
595 error_string = base::ASCIIToUTF16(net::ErrorToShortString(error_code));
596 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) {
597 std::string ascii_error_string =
598 chrome_common_net::DnsProbeStatusToString(error_code);
599 error_string = base::ASCIIToUTF16(ascii_error_string);
600 } else {
601 DCHECK_EQ(LocalizedError::kHttpErrorDomain, error_domain);
602 error_string = base::IntToString16(error_code);
604 error_strings->SetString("errorCode",
605 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_ERROR_CODE, error_string));
607 // Platform specific information for diagnosing network issues on OSX and
608 // Windows.
609 #if defined(OS_MACOSX) || defined(OS_WIN)
610 if (error_domain == net::kErrorDomain &&
611 error_code == net::ERR_INTERNET_DISCONNECTED) {
612 int platform_string_id =
613 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM;
614 #if defined(OS_WIN)
615 // Different versions of Windows have different instructions.
616 base::win::Version windows_version = base::win::GetVersion();
617 if (windows_version < base::win::VERSION_VISTA) {
618 // XP, XP64, and Server 2003.
619 platform_string_id =
620 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_XP;
621 } else if (windows_version == base::win::VERSION_VISTA) {
622 // Vista
623 platform_string_id =
624 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_VISTA;
626 #endif // defined(OS_WIN)
627 // Platform dependent portion of the summary section.
628 summary->SetString("msg",
629 l10n_util::GetStringFUTF16(
630 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_INSTRUCTIONS_TEMPLATE,
631 l10n_util::GetStringUTF16(platform_string_id)));
633 #endif // defined(OS_MACOSX) || defined(OS_WIN)
635 // If no parameters were provided, use the defaults.
636 if (!params) {
637 params.reset(new error_page::ErrorPageParams());
638 params->suggest_reload = !!(options.suggestions & SUGGEST_RELOAD);
641 base::ListValue* suggestions = NULL;
642 bool use_default_suggestions = true;
643 if (!params->override_suggestions) {
644 suggestions = new base::ListValue();
645 } else {
646 suggestions = params->override_suggestions.release();
647 use_default_suggestions = false;
650 error_strings->Set("suggestions", suggestions);
652 if (params->search_url.is_valid()) {
653 error_strings->SetString("searchHeader",
654 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_GOOGLE_SEARCH));
655 error_strings->SetString("searchUrl", params->search_url.spec());
656 error_strings->SetString("searchTerms", params->search_terms);
657 error_strings->SetInteger("searchTrackingId", params->search_tracking_id);
660 // Add the reload suggestion, if needed.
661 if (params->suggest_reload) {
662 if (!is_post) {
663 base::DictionaryValue* reload_button = new base::DictionaryValue;
664 reload_button->SetString(
665 "msg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD));
666 reload_button->SetString("reloadUrl", failed_url.spec());
667 error_strings->Set("reloadButton", reload_button);
668 reload_button->SetInteger("reloadTrackingId", params->reload_tracking_id);
669 } else {
670 // If the page was created by a post, it can't be reloaded in the same
671 // way, so just add a suggestion instead.
672 // TODO(mmenke): Make the reload button bring up the repost confirmation
673 // dialog for pages resulting from posts.
674 base::DictionaryValue* suggest_reload_repost = new base::DictionaryValue;
675 suggest_reload_repost->SetString("header",
676 l10n_util::GetStringUTF16(
677 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_HEADER));
678 suggest_reload_repost->SetString("body",
679 l10n_util::GetStringUTF16(
680 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_BODY));
681 // Add at the front, so it appears before other suggestions, in the case
682 // suggestions are being overridden by |params|.
683 suggestions->Insert(0, suggest_reload_repost);
687 // If not using the default suggestions, nothing else to do.
688 if (!use_default_suggestions)
689 return;
691 if (show_stale_load_button) {
692 base::DictionaryValue* stale_load_button = new base::DictionaryValue;
693 stale_load_button->SetString(
694 "msg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_LOAD_STALE));
695 stale_load_button->SetString(
696 "title",
697 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_LOAD_STALE_HELP));
698 error_strings->Set("staleLoadButton", stale_load_button);
701 #if defined(OS_CHROMEOS)
702 error_strings->SetString(
703 "diagnose", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_DIAGNOSE));
704 #endif // defined(OS_CHROMEOS)
706 if (options.suggestions & SUGGEST_CHECK_CONNECTION) {
707 base::DictionaryValue* suggest_check_connection = new base::DictionaryValue;
708 suggest_check_connection->SetString("header",
709 l10n_util::GetStringUTF16(
710 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER));
711 suggest_check_connection->SetString("body",
712 l10n_util::GetStringUTF16(
713 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_BODY));
714 suggestions->Append(suggest_check_connection);
717 if (options.suggestions & SUGGEST_DNS_CONFIG) {
718 base::DictionaryValue* suggest_dns_config = new base::DictionaryValue;
719 suggest_dns_config->SetString("header",
720 l10n_util::GetStringUTF16(
721 IDS_ERRORPAGES_SUGGESTION_DNS_CONFIG_HEADER));
722 suggest_dns_config->SetString("body",
723 l10n_util::GetStringUTF16(
724 IDS_ERRORPAGES_SUGGESTION_DNS_CONFIG_BODY));
725 suggestions->Append(suggest_dns_config);
727 base::DictionaryValue* suggest_network_prediction =
728 GetStandardMenuItemsText();
729 suggest_network_prediction->SetString("header",
730 l10n_util::GetStringUTF16(
731 IDS_ERRORPAGES_SUGGESTION_NETWORK_PREDICTION_HEADER));
732 suggest_network_prediction->SetString("body",
733 l10n_util::GetStringUTF16(
734 IDS_ERRORPAGES_SUGGESTION_NETWORK_PREDICTION_BODY));
735 suggest_network_prediction->SetString(
736 "noNetworkPredictionTitle",
737 l10n_util::GetStringUTF16(
738 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION));
739 suggestions->Append(suggest_network_prediction);
742 if (options.suggestions & SUGGEST_FIREWALL_CONFIG) {
743 base::DictionaryValue* suggest_firewall_config = new base::DictionaryValue;
744 suggest_firewall_config->SetString("header",
745 l10n_util::GetStringUTF16(
746 IDS_ERRORPAGES_SUGGESTION_FIREWALL_CONFIG_HEADER));
747 suggest_firewall_config->SetString("body",
748 l10n_util::GetStringUTF16(
749 IDS_ERRORPAGES_SUGGESTION_FIREWALL_CONFIG_BODY));
750 suggestions->Append(suggest_firewall_config);
753 if (options.suggestions & SUGGEST_PROXY_CONFIG) {
754 base::DictionaryValue* suggest_proxy_config = GetStandardMenuItemsText();
755 suggest_proxy_config->SetString("header",
756 l10n_util::GetStringUTF16(
757 IDS_ERRORPAGES_SUGGESTION_PROXY_CONFIG_HEADER));
758 suggest_proxy_config->SetString("body",
759 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_SUGGESTION_PROXY_CONFIG_BODY,
760 l10n_util::GetStringUTF16(
761 IDS_ERRORPAGES_SUGGESTION_PROXY_DISABLE_PLATFORM)));
762 suggest_proxy_config->SetString("proxyTitle",
763 l10n_util::GetStringUTF16(IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON));
765 suggestions->Append(suggest_proxy_config);
768 if (options.suggestions & SUGGEST_DISABLE_EXTENSION) {
769 base::DictionaryValue* suggest_disable_extension =
770 new base::DictionaryValue;
771 // There's only a header for this suggestion.
772 suggest_disable_extension->SetString("header",
773 l10n_util::GetStringUTF16(
774 IDS_ERRORPAGES_SUGGESTION_DISABLE_EXTENSION_HEADER));
775 suggestions->Append(suggest_disable_extension);
778 if (options.suggestions & SUGGEST_VIEW_POLICIES) {
779 base::DictionaryValue* suggest_view_policies = new base::DictionaryValue;
780 suggest_view_policies->SetString(
781 "header",
782 l10n_util::GetStringUTF16(
783 IDS_ERRORPAGES_SUGGESTION_VIEW_POLICIES_HEADER));
784 suggest_view_policies->SetString(
785 "body",
786 l10n_util::GetStringUTF16(
787 IDS_ERRORPAGES_SUGGESTION_VIEW_POLICIES_BODY));
788 suggestions->Append(suggest_view_policies);
791 if (options.suggestions & SUGGEST_CONTACT_ADMINISTRATOR) {
792 base::DictionaryValue* suggest_contant_administrator =
793 new base::DictionaryValue;
794 suggest_contant_administrator->SetString(
795 "body",
796 l10n_util::GetStringUTF16(
797 IDS_ERRORPAGES_SUGGESTION_CONTACT_ADMINISTRATOR_BODY));
798 suggestions->Append(suggest_contant_administrator);
801 if (options.suggestions & SUGGEST_LEARNMORE) {
802 GURL learn_more_url;
803 switch (options.error_code) {
804 case net::ERR_TOO_MANY_REDIRECTS:
805 learn_more_url = GURL(kRedirectLoopLearnMoreUrl);
806 break;
807 case net::ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY:
808 learn_more_url = GURL(kWeakDHKeyLearnMoreUrl);
809 break;
810 default:
811 break;
814 if (learn_more_url.is_valid()) {
815 // Add the language parameter to the URL.
816 std::string query = learn_more_url.query() + "&hl=" + locale;
817 GURL::Replacements repl;
818 repl.SetQueryStr(query);
819 learn_more_url = learn_more_url.ReplaceComponents(repl);
821 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue;
822 // There's only a body for this suggestion.
823 suggest_learn_more->SetString("body",
824 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY));
825 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec());
826 suggestions->Append(suggest_learn_more);
831 base::string16 LocalizedError::GetErrorDetails(const blink::WebURLError& error,
832 bool is_post) {
833 const LocalizedErrorMap* error_map =
834 LookupErrorMap(error.domain.utf8(), error.reason, is_post);
835 if (error_map)
836 return l10n_util::GetStringUTF16(error_map->details_resource_id);
837 else
838 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN);
841 bool LocalizedError::HasStrings(const std::string& error_domain,
842 int error_code) {
843 // Whether or not the there are strings for an error does not depend on
844 // whether or not the page was be generated by a POST, so just claim it was
845 // not.
846 return LookupErrorMap(error_domain, error_code, /*is_post=*/false) != NULL;
849 #if defined(ENABLE_EXTENSIONS)
850 void LocalizedError::GetAppErrorStrings(
851 const GURL& display_url,
852 const extensions::Extension* app,
853 const std::string& locale,
854 base::DictionaryValue* error_strings) {
855 DCHECK(app);
857 webui::SetLoadTimeDataDefaults(locale, error_strings);
859 base::string16 failed_url(base::ASCIIToUTF16(display_url.spec()));
860 // URLs are always LTR.
861 if (base::i18n::IsRTL())
862 base::i18n::WrapStringWithLTRFormatting(&failed_url);
863 error_strings->SetString(
864 "url", l10n_util::GetStringFUTF16(IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
865 failed_url.c_str()));
867 error_strings->SetString("title", app->name());
868 error_strings->SetString(
869 "icon",
870 extensions::IconsInfo::GetIconURL(
871 app,
872 extension_misc::EXTENSION_ICON_GIGANTOR,
873 ExtensionIconSet::MATCH_SMALLER).spec());
874 error_strings->SetString("name", app->name());
875 error_strings->SetString(
876 "msg",
877 l10n_util::GetStringUTF16(IDS_ERRORPAGES_APP_WARNING));
879 #if defined(OS_CHROMEOS)
880 GURL learn_more_url(kAppWarningLearnMoreUrl);
881 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue();
882 suggest_learn_more->SetString("msg",
883 l10n_util::GetStringUTF16(
884 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY));
885 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec());
886 error_strings->Set("suggestionsLearnMore", suggest_learn_more);
887 #endif // defined(OS_CHROMEOS)
889 #endif