Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / common / localized_error.cc
blobd85428cb382c5ef3d37189afc80d2eee442bfbc4
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/common/extensions/extension_constants.h"
15 #include "chrome/common/extensions/extension_icon_set.h"
16 #include "chrome/common/extensions/manifest_handlers/icons_handler.h"
17 #include "chrome/common/net/net_error_info.h"
18 #include "grit/chromium_strings.h"
19 #include "grit/generated_resources.h"
20 #include "net/base/escape.h"
21 #include "net/base/net_errors.h"
22 #include "net/base/net_util.h"
23 #include "third_party/WebKit/public/platform/WebURLError.h"
24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/webui/web_ui_util.h"
26 #include "url/gurl.h"
28 #if defined(OS_WIN)
29 #include "base/win/windows_version.h"
30 #endif
32 using blink::WebURLError;
34 // Some error pages have no details.
35 const unsigned int kErrorPagesNoDetails = 0;
37 namespace {
39 static const char kRedirectLoopLearnMoreUrl[] =
40 "https://www.google.com/support/chrome/bin/answer.py?answer=95626";
41 static const char kWeakDHKeyLearnMoreUrl[] =
42 "http://sites.google.com/a/chromium.org/dev/"
43 "err_ssl_weak_server_ephemeral_dh_key";
44 #if defined(OS_CHROMEOS)
45 static const char kAppWarningLearnMoreUrl[] =
46 "chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"
47 "?answer=1721911";
48 #endif // defined(OS_CHROMEOS)
50 enum NAV_SUGGESTIONS {
51 SUGGEST_NONE = 0,
52 SUGGEST_RELOAD = 1 << 0,
53 SUGGEST_CHECK_CONNECTION = 1 << 1,
54 SUGGEST_DNS_CONFIG = 1 << 2,
55 SUGGEST_FIREWALL_CONFIG = 1 << 3,
56 SUGGEST_PROXY_CONFIG = 1 << 4,
57 SUGGEST_DISABLE_EXTENSION = 1 << 5,
58 SUGGEST_LEARNMORE = 1 << 6,
59 SUGGEST_VIEW_POLICIES = 1 << 7,
60 SUGGEST_CONTACT_ADMINISTRATOR = 1 << 8,
63 struct LocalizedErrorMap {
64 int error_code;
65 unsigned int title_resource_id;
66 unsigned int heading_resource_id;
67 // Detailed summary used when the error is in the main frame.
68 unsigned int summary_resource_id;
69 // Short one sentence description shown on mouse over when the error is in
70 // a frame.
71 unsigned int details_resource_id;
72 int suggestions; // Bitmap of SUGGEST_* values.
75 const LocalizedErrorMap net_error_options[] = {
76 {net::ERR_TIMED_OUT,
77 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
78 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
79 IDS_ERRORPAGES_SUMMARY_TIMED_OUT,
80 IDS_ERRORPAGES_DETAILS_TIMED_OUT,
81 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
82 SUGGEST_PROXY_CONFIG,
84 {net::ERR_CONNECTION_TIMED_OUT,
85 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
86 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
87 IDS_ERRORPAGES_SUMMARY_TIMED_OUT,
88 IDS_ERRORPAGES_DETAILS_TIMED_OUT,
89 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
90 SUGGEST_PROXY_CONFIG,
92 {net::ERR_CONNECTION_CLOSED,
93 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
94 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
95 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
96 IDS_ERRORPAGES_DETAILS_CONNECTION_CLOSED,
97 SUGGEST_RELOAD,
99 {net::ERR_CONNECTION_RESET,
100 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
101 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
102 IDS_ERRORPAGES_SUMMARY_CONNECTION_RESET,
103 IDS_ERRORPAGES_DETAILS_CONNECTION_RESET,
104 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
105 SUGGEST_PROXY_CONFIG,
107 {net::ERR_CONNECTION_REFUSED,
108 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
109 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
110 IDS_ERRORPAGES_SUMMARY_CONNECTION_REFUSED,
111 IDS_ERRORPAGES_DETAILS_CONNECTION_REFUSED,
112 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
113 SUGGEST_PROXY_CONFIG,
115 {net::ERR_CONNECTION_FAILED,
116 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
117 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
118 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
119 IDS_ERRORPAGES_DETAILS_CONNECTION_FAILED,
120 SUGGEST_RELOAD,
122 {net::ERR_NAME_NOT_RESOLVED,
123 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
124 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
125 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED,
126 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED,
127 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_DNS_CONFIG |
128 SUGGEST_FIREWALL_CONFIG | SUGGEST_PROXY_CONFIG,
130 {net::ERR_ADDRESS_UNREACHABLE,
131 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
132 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
133 IDS_ERRORPAGES_SUMMARY_ADDRESS_UNREACHABLE,
134 IDS_ERRORPAGES_DETAILS_ADDRESS_UNREACHABLE,
135 SUGGEST_RELOAD | SUGGEST_FIREWALL_CONFIG | SUGGEST_PROXY_CONFIG,
137 {net::ERR_NETWORK_ACCESS_DENIED,
138 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
139 IDS_ERRORPAGES_HEADING_NETWORK_ACCESS_DENIED,
140 IDS_ERRORPAGES_SUMMARY_NETWORK_ACCESS_DENIED,
141 IDS_ERRORPAGES_DETAILS_NETWORK_ACCESS_DENIED,
142 SUGGEST_FIREWALL_CONFIG,
144 {net::ERR_PROXY_CONNECTION_FAILED,
145 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
146 IDS_ERRORPAGES_HEADING_PROXY_CONNECTION_FAILED,
147 IDS_ERRORPAGES_SUMMARY_PROXY_CONNECTION_FAILED,
148 IDS_ERRORPAGES_DETAILS_PROXY_CONNECTION_FAILED,
149 SUGGEST_PROXY_CONFIG,
151 {net::ERR_INTERNET_DISCONNECTED,
152 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
153 IDS_ERRORPAGES_HEADING_INTERNET_DISCONNECTED,
154 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED,
155 IDS_ERRORPAGES_DETAILS_INTERNET_DISCONNECTED,
156 SUGGEST_NONE,
158 {net::ERR_FILE_NOT_FOUND,
159 IDS_ERRORPAGES_TITLE_NOT_FOUND,
160 IDS_ERRORPAGES_HEADING_NOT_FOUND,
161 IDS_ERRORPAGES_SUMMARY_NOT_FOUND,
162 IDS_ERRORPAGES_DETAILS_FILE_NOT_FOUND,
163 SUGGEST_NONE,
165 {net::ERR_CACHE_MISS,
166 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
167 IDS_ERRORPAGES_HEADING_CACHE_MISS,
168 IDS_ERRORPAGES_SUMMARY_CACHE_MISS,
169 IDS_ERRORPAGES_DETAILS_CACHE_MISS,
170 SUGGEST_RELOAD,
172 {net::ERR_CACHE_READ_FAILURE,
173 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
174 IDS_ERRORPAGES_HEADING_CACHE_READ_FAILURE,
175 IDS_ERRORPAGES_SUMMARY_CACHE_READ_FAILURE,
176 IDS_ERRORPAGES_DETAILS_CACHE_READ_FAILURE,
177 SUGGEST_RELOAD,
179 {net::ERR_NETWORK_IO_SUSPENDED,
180 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
181 IDS_ERRORPAGES_HEADING_NETWORK_IO_SUSPENDED,
182 IDS_ERRORPAGES_SUMMARY_NETWORK_IO_SUSPENDED,
183 IDS_ERRORPAGES_DETAILS_NETWORK_IO_SUSPENDED,
184 SUGGEST_RELOAD,
186 {net::ERR_TOO_MANY_REDIRECTS,
187 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
188 IDS_ERRORPAGES_HEADING_TOO_MANY_REDIRECTS,
189 IDS_ERRORPAGES_SUMMARY_TOO_MANY_REDIRECTS,
190 IDS_ERRORPAGES_DETAILS_TOO_MANY_REDIRECTS,
191 SUGGEST_RELOAD | SUGGEST_LEARNMORE,
193 {net::ERR_EMPTY_RESPONSE,
194 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
195 IDS_ERRORPAGES_HEADING_EMPTY_RESPONSE,
196 IDS_ERRORPAGES_SUMMARY_EMPTY_RESPONSE,
197 IDS_ERRORPAGES_DETAILS_EMPTY_RESPONSE,
198 SUGGEST_RELOAD,
200 {net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH,
201 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
202 IDS_ERRORPAGES_HEADING_DUPLICATE_HEADERS,
203 IDS_ERRORPAGES_SUMMARY_DUPLICATE_HEADERS,
204 IDS_ERRORPAGES_DETAILS_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH,
205 SUGGEST_NONE,
207 {net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION,
208 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
209 IDS_ERRORPAGES_HEADING_DUPLICATE_HEADERS,
210 IDS_ERRORPAGES_SUMMARY_DUPLICATE_HEADERS,
211 IDS_ERRORPAGES_DETAILS_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION,
212 SUGGEST_NONE,
214 {net::ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION,
215 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
216 IDS_ERRORPAGES_HEADING_DUPLICATE_HEADERS,
217 IDS_ERRORPAGES_SUMMARY_DUPLICATE_HEADERS,
218 IDS_ERRORPAGES_DETAILS_RESPONSE_HEADERS_MULTIPLE_LOCATION,
219 SUGGEST_NONE,
221 {net::ERR_CONTENT_LENGTH_MISMATCH,
222 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
223 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
224 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
225 IDS_ERRORPAGES_DETAILS_CONNECTION_CLOSED,
226 SUGGEST_RELOAD,
228 {net::ERR_INCOMPLETE_CHUNKED_ENCODING,
229 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
230 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
231 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
232 IDS_ERRORPAGES_DETAILS_CONNECTION_CLOSED,
233 SUGGEST_RELOAD,
235 {net::ERR_SSL_PROTOCOL_ERROR,
236 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
237 IDS_ERRORPAGES_HEADING_SSL_PROTOCOL_ERROR,
238 IDS_ERRORPAGES_SUMMARY_SSL_PROTOCOL_ERROR,
239 IDS_ERRORPAGES_DETAILS_SSL_PROTOCOL_ERROR,
240 SUGGEST_NONE,
242 {net::ERR_SSL_UNSAFE_NEGOTIATION,
243 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
244 IDS_ERRORPAGES_HEADING_SSL_PROTOCOL_ERROR,
245 IDS_ERRORPAGES_SUMMARY_SSL_PROTOCOL_ERROR,
246 IDS_ERRORPAGES_DETAILS_SSL_UNSAFE_NEGOTIATION,
247 SUGGEST_NONE,
249 {net::ERR_BAD_SSL_CLIENT_AUTH_CERT,
250 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
251 IDS_ERRORPAGES_HEADING_BAD_SSL_CLIENT_AUTH_CERT,
252 IDS_ERRORPAGES_SUMMARY_BAD_SSL_CLIENT_AUTH_CERT,
253 IDS_ERRORPAGES_DETAILS_BAD_SSL_CLIENT_AUTH_CERT,
254 SUGGEST_NONE,
256 {net::ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY,
257 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
258 IDS_ERRORPAGES_HEADING_WEAK_SERVER_EPHEMERAL_DH_KEY,
259 IDS_ERRORPAGES_SUMMARY_WEAK_SERVER_EPHEMERAL_DH_KEY,
260 IDS_ERRORPAGES_DETAILS_SSL_PROTOCOL_ERROR,
261 SUGGEST_LEARNMORE,
263 {net::ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN,
264 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
265 IDS_ERRORPAGES_HEADING_PINNING_FAILURE,
266 IDS_ERRORPAGES_SUMMARY_PINNING_FAILURE,
267 IDS_ERRORPAGES_DETAILS_PINNING_FAILURE,
268 SUGGEST_NONE,
270 {net::ERR_TEMPORARILY_THROTTLED,
271 IDS_ERRORPAGES_TITLE_ACCESS_DENIED,
272 IDS_ERRORPAGES_HEADING_ACCESS_DENIED,
273 IDS_ERRORPAGES_SUMMARY_TEMPORARILY_THROTTLED,
274 IDS_ERRORPAGES_DETAILS_TEMPORARILY_THROTTLED,
275 SUGGEST_NONE,
277 {net::ERR_BLOCKED_BY_CLIENT,
278 IDS_ERRORPAGES_TITLE_BLOCKED,
279 IDS_ERRORPAGES_HEADING_BLOCKED,
280 IDS_ERRORPAGES_SUMMARY_BLOCKED,
281 IDS_ERRORPAGES_DETAILS_BLOCKED,
282 SUGGEST_RELOAD | SUGGEST_DISABLE_EXTENSION,
284 {net::ERR_NETWORK_CHANGED,
285 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
286 IDS_ERRORPAGES_HEADING_NETWORK_ACCESS_DENIED,
287 IDS_ERRORPAGES_SUMMARY_NETWORK_CHANGED,
288 IDS_ERRORPAGES_DETAILS_NETWORK_CHANGED,
289 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION,
291 {net::ERR_BLOCKED_BY_ADMINISTRATOR,
292 IDS_ERRORPAGES_TITLE_BLOCKED,
293 IDS_ERRORPAGES_HEADING_BLOCKED_BY_ADMINISTRATOR,
294 IDS_ERRORPAGES_SUMMARY_BLOCKED_BY_ADMINISTRATOR,
295 IDS_ERRORPAGES_DETAILS_BLOCKED_BY_ADMINISTRATOR,
296 SUGGEST_VIEW_POLICIES | SUGGEST_CONTACT_ADMINISTRATOR,
300 // Special error page to be used in the case of navigating back to a page
301 // generated by a POST. LocalizedError::HasStrings expects this net error code
302 // to also appear in the array above.
303 const LocalizedErrorMap repost_error = {
304 net::ERR_CACHE_MISS,
305 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
306 IDS_HTTP_POST_WARNING_TITLE,
307 IDS_ERRORPAGES_HTTP_POST_WARNING,
308 IDS_ERRORPAGES_DETAILS_CACHE_MISS,
309 SUGGEST_RELOAD,
312 const LocalizedErrorMap http_error_options[] = {
313 {403,
314 IDS_ERRORPAGES_TITLE_ACCESS_DENIED,
315 IDS_ERRORPAGES_HEADING_ACCESS_DENIED,
316 IDS_ERRORPAGES_SUMMARY_FORBIDDEN,
317 IDS_ERRORPAGES_DETAILS_FORBIDDEN,
318 SUGGEST_NONE,
320 {410,
321 IDS_ERRORPAGES_TITLE_NOT_FOUND,
322 IDS_ERRORPAGES_HEADING_NOT_FOUND,
323 IDS_ERRORPAGES_SUMMARY_GONE,
324 IDS_ERRORPAGES_DETAILS_GONE,
325 SUGGEST_NONE,
328 {500,
329 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
330 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
331 IDS_ERRORPAGES_SUMMARY_INTERNAL_SERVER_ERROR,
332 IDS_ERRORPAGES_DETAILS_INTERNAL_SERVER_ERROR,
333 SUGGEST_RELOAD,
335 {501,
336 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
337 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
338 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE,
339 IDS_ERRORPAGES_DETAILS_NOT_IMPLEMENTED,
340 SUGGEST_NONE,
342 {502,
343 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
344 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
345 IDS_ERRORPAGES_SUMMARY_BAD_GATEWAY,
346 IDS_ERRORPAGES_DETAILS_BAD_GATEWAY,
347 SUGGEST_RELOAD,
349 {503,
350 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
351 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
352 IDS_ERRORPAGES_SUMMARY_SERVICE_UNAVAILABLE,
353 IDS_ERRORPAGES_DETAILS_SERVICE_UNAVAILABLE,
354 SUGGEST_RELOAD,
356 {504,
357 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
358 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
359 IDS_ERRORPAGES_SUMMARY_GATEWAY_TIMEOUT,
360 IDS_ERRORPAGES_DETAILS_GATEWAY_TIMEOUT,
361 SUGGEST_RELOAD,
363 {505,
364 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
365 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
366 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE,
367 IDS_ERRORPAGES_DETAILS_HTTP_VERSION_NOT_SUPPORTED,
368 SUGGEST_NONE,
372 const LocalizedErrorMap dns_probe_error_options[] = {
373 {chrome_common_net::DNS_PROBE_POSSIBLE,
374 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
375 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
376 IDS_ERRORPAGES_SUMMARY_DNS_PROBE_RUNNING,
377 IDS_ERRORPAGES_DETAILS_DNS_PROBE_RUNNING,
378 SUGGEST_RELOAD,
381 // DNS_PROBE_NOT_RUN is not here; NetErrorHelper will restore the original
382 // error, which might be one of several DNS-related errors.
384 {chrome_common_net::DNS_PROBE_STARTED,
385 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
386 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
387 IDS_ERRORPAGES_SUMMARY_DNS_PROBE_RUNNING,
388 IDS_ERRORPAGES_DETAILS_DNS_PROBE_RUNNING,
389 // Include SUGGEST_RELOAD so the More button doesn't jump when we update.
390 SUGGEST_RELOAD,
393 // DNS_PROBE_FINISHED_UNKNOWN is not here; NetErrorHelper will restore the
394 // original error, which might be one of several DNS-related errors.
396 {chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET,
397 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
398 IDS_ERRORPAGES_HEADING_INTERNET_DISCONNECTED,
399 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED,
400 IDS_ERRORPAGES_DETAILS_INTERNET_DISCONNECTED,
401 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG,
403 {chrome_common_net::DNS_PROBE_FINISHED_BAD_CONFIG,
404 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
405 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
406 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED,
407 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED,
408 SUGGEST_RELOAD | SUGGEST_DNS_CONFIG | SUGGEST_FIREWALL_CONFIG,
410 {chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN,
411 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
412 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
413 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED,
414 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED,
415 SUGGEST_RELOAD,
419 const LocalizedErrorMap* FindErrorMapInArray(const LocalizedErrorMap* maps,
420 size_t num_maps,
421 int error_code) {
422 for (size_t i = 0; i < num_maps; ++i) {
423 if (maps[i].error_code == error_code)
424 return &maps[i];
426 return NULL;
429 const LocalizedErrorMap* LookupErrorMap(const std::string& error_domain,
430 int error_code, bool is_post) {
431 if (error_domain == net::kErrorDomain) {
432 // Display a different page in the special case of navigating through the
433 // history to an uncached page created by a POST.
434 if (is_post && error_code == net::ERR_CACHE_MISS)
435 return &repost_error;
436 return FindErrorMapInArray(net_error_options,
437 arraysize(net_error_options),
438 error_code);
439 } else if (error_domain == LocalizedError::kHttpErrorDomain) {
440 return FindErrorMapInArray(http_error_options,
441 arraysize(http_error_options),
442 error_code);
443 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) {
444 const LocalizedErrorMap* map =
445 FindErrorMapInArray(dns_probe_error_options,
446 arraysize(dns_probe_error_options),
447 error_code);
448 DCHECK(map);
449 return map;
450 } else {
451 NOTREACHED();
452 return NULL;
456 bool LocaleIsRTL() {
457 #if defined(TOOLKIT_GTK)
458 // base::i18n::IsRTL() uses the GTK text direction, which doesn't work within
459 // the renderer sandbox.
460 return base::i18n::ICUIsRTL();
461 #else
462 return base::i18n::IsRTL();
463 #endif
466 // Returns a dictionary containing the strings for the settings menu under the
467 // wrench, and the advanced settings button.
468 base::DictionaryValue* GetStandardMenuItemsText() {
469 base::DictionaryValue* standard_menu_items_text = new base::DictionaryValue();
470 standard_menu_items_text->SetString("settingsTitle",
471 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE));
472 standard_menu_items_text->SetString("advancedTitle",
473 l10n_util::GetStringUTF16(IDS_SETTINGS_SHOW_ADVANCED_SETTINGS));
474 return standard_menu_items_text;
477 // Gets the icon class for a given |error_domain| and |error_code|.
478 const char* GetIconClassForError(const std::string& error_domain,
479 int error_code) {
480 if ((error_code == net::ERR_INTERNET_DISCONNECTED &&
481 error_domain == net::kErrorDomain) ||
482 (error_code == chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET &&
483 error_domain == chrome_common_net::kDnsProbeErrorDomain))
484 return "icon-offline";
486 return "icon-generic";
489 } // namespace
491 const char LocalizedError::kHttpErrorDomain[] = "http";
493 void LocalizedError::GetStrings(int error_code,
494 const std::string& error_domain,
495 const GURL& failed_url,
496 bool is_post,
497 const std::string& locale,
498 const std::string& accept_languages,
499 base::DictionaryValue* error_strings) {
500 bool rtl = LocaleIsRTL();
501 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr");
503 // Grab the strings and settings that depend on the error type. Init
504 // options with default values.
505 LocalizedErrorMap options = {
507 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
508 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
509 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
510 kErrorPagesNoDetails,
511 SUGGEST_NONE,
514 const LocalizedErrorMap* error_map = LookupErrorMap(error_domain, error_code,
515 is_post);
516 if (error_map)
517 options = *error_map;
519 // If we got "access denied" but the url was a file URL, then we say it was a
520 // file instead of just using the "not available" default message. Just adding
521 // ERR_ACCESS_DENIED to the map isn't sufficient, since that message may be
522 // generated by some OSs when the operation doesn't involve a file URL.
523 if (error_domain == net::kErrorDomain &&
524 error_code == net::ERR_ACCESS_DENIED &&
525 failed_url.scheme() == "file") {
526 options.title_resource_id = IDS_ERRORPAGES_TITLE_ACCESS_DENIED;
527 options.heading_resource_id = IDS_ERRORPAGES_HEADING_FILE_ACCESS_DENIED;
528 options.summary_resource_id = IDS_ERRORPAGES_SUMMARY_FILE_ACCESS_DENIED;
529 options.details_resource_id = IDS_ERRORPAGES_DETAILS_FILE_ACCESS_DENIED;
530 options.suggestions = SUGGEST_NONE;
533 base::string16 failed_url_string(net::FormatUrl(
534 failed_url, accept_languages, net::kFormatUrlOmitNothing,
535 net::UnescapeRule::NORMAL, NULL, NULL, NULL));
536 // URLs are always LTR.
537 if (rtl)
538 base::i18n::WrapStringWithLTRFormatting(&failed_url_string);
539 error_strings->SetString("title",
540 l10n_util::GetStringFUTF16(options.title_resource_id, failed_url_string));
541 error_strings->SetString("heading",
542 l10n_util::GetStringUTF16(options.heading_resource_id));
544 std::string icon_class = GetIconClassForError(error_domain, error_code);
545 error_strings->SetString("iconClass", icon_class);
547 base::DictionaryValue* summary = new base::DictionaryValue;
548 summary->SetString("msg",
549 l10n_util::GetStringUTF16(options.summary_resource_id));
550 summary->SetString("failedUrl", failed_url_string);
551 summary->SetString("hostName", net::IDNToUnicode(failed_url.host(),
552 accept_languages));
553 summary->SetString("productName",
554 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
556 error_strings->SetString(
557 "more", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_MORE));
558 error_strings->SetString(
559 "less", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_LESS));
560 error_strings->Set("summary", summary);
561 #if defined(OS_CHROMEOS)
562 error_strings->SetString(
563 "diagnose", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_DIAGNOSE));
564 #endif // defined(OS_CHROMEOS)
566 if (options.details_resource_id != kErrorPagesNoDetails) {
567 error_strings->SetString(
568 "errorDetails", l10n_util::GetStringUTF16(options.details_resource_id));
571 base::string16 error_string;
572 if (error_domain == net::kErrorDomain) {
573 // Non-internationalized error string, for debugging Chrome itself.
574 std::string ascii_error_string = net::ErrorToString(error_code);
575 // Remove the leading "net::" from the returned string.
576 base::RemoveChars(ascii_error_string, "net:", &ascii_error_string);
577 error_string = base::ASCIIToUTF16(ascii_error_string);
578 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) {
579 std::string ascii_error_string =
580 chrome_common_net::DnsProbeStatusToString(error_code);
581 error_string = base::ASCIIToUTF16(ascii_error_string);
582 } else {
583 DCHECK_EQ(LocalizedError::kHttpErrorDomain, error_domain);
584 error_string = base::IntToString16(error_code);
586 error_strings->SetString("errorCode",
587 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_ERROR_CODE, error_string));
589 base::ListValue* suggestions = new base::ListValue();
591 // Platform specific instructions for diagnosing network issues on OSX and
592 // Windows.
593 #if defined(OS_MACOSX) || defined(OS_WIN)
594 if (error_domain == net::kErrorDomain &&
595 error_code == net::ERR_INTERNET_DISCONNECTED) {
596 int platform_string_id =
597 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM;
598 #if defined(OS_WIN)
599 // Different versions of Windows have different instructions.
600 base::win::Version windows_version = base::win::GetVersion();
601 if (windows_version < base::win::VERSION_VISTA) {
602 // XP, XP64, and Server 2003.
603 platform_string_id =
604 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_XP;
605 } else if (windows_version == base::win::VERSION_VISTA) {
606 // Vista
607 platform_string_id =
608 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_VISTA;
610 #endif // defined(OS_WIN)
611 // Lead with the general error description, and suffix with the platform
612 // dependent portion of the summary section.
613 summary->SetString("msg",
614 l10n_util::GetStringFUTF16(
615 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_INSTRUCTIONS_TEMPLATE,
616 l10n_util::GetStringUTF16(options.summary_resource_id),
617 l10n_util::GetStringUTF16(platform_string_id)));
619 #endif // defined(OS_MACOSX) || defined(OS_WIN)
621 if (options.suggestions & SUGGEST_RELOAD) {
622 if (!is_post) {
623 base::DictionaryValue* reload_button = new base::DictionaryValue;
624 reload_button->SetString("msg",
625 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD));
626 reload_button->SetString("reloadUrl", failed_url.spec());
627 error_strings->Set("reload", reload_button);
628 } else {
629 // If the page was created by a post, it can't be reloaded in the same
630 // way, so just add a suggestion instead.
631 // TODO(mmenke): Make the reload button bring up the repost confirmation
632 // dialog for pages resulting from posts.
633 base::DictionaryValue* suggest_reload_repost = new base::DictionaryValue;
634 suggest_reload_repost->SetString("header",
635 l10n_util::GetStringUTF16(
636 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_HEADER));
637 suggest_reload_repost->SetString("body",
638 l10n_util::GetStringUTF16(
639 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_BODY));
640 suggestions->Append(suggest_reload_repost);
644 if (options.suggestions & SUGGEST_CHECK_CONNECTION) {
645 base::DictionaryValue* suggest_check_connection = new base::DictionaryValue;
646 suggest_check_connection->SetString("header",
647 l10n_util::GetStringUTF16(
648 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER));
649 suggest_check_connection->SetString("body",
650 l10n_util::GetStringUTF16(
651 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_BODY));
652 suggestions->Append(suggest_check_connection);
655 if (options.suggestions & SUGGEST_DNS_CONFIG) {
656 base::DictionaryValue* suggest_dns_config = new base::DictionaryValue;
657 suggest_dns_config->SetString("header",
658 l10n_util::GetStringUTF16(
659 IDS_ERRORPAGES_SUGGESTION_DNS_CONFIG_HEADER));
660 suggest_dns_config->SetString("body",
661 l10n_util::GetStringUTF16(
662 IDS_ERRORPAGES_SUGGESTION_DNS_CONFIG_BODY));
663 suggestions->Append(suggest_dns_config);
665 base::DictionaryValue* suggest_network_prediction =
666 GetStandardMenuItemsText();
667 suggest_network_prediction->SetString("header",
668 l10n_util::GetStringUTF16(
669 IDS_ERRORPAGES_SUGGESTION_NETWORK_PREDICTION_HEADER));
670 suggest_network_prediction->SetString("body",
671 l10n_util::GetStringUTF16(
672 IDS_ERRORPAGES_SUGGESTION_NETWORK_PREDICTION_BODY));
673 suggest_network_prediction->SetString(
674 "noNetworkPredictionTitle",
675 l10n_util::GetStringUTF16(
676 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION));
677 suggestions->Append(suggest_network_prediction);
680 if (options.suggestions & SUGGEST_FIREWALL_CONFIG) {
681 base::DictionaryValue* suggest_firewall_config = new base::DictionaryValue;
682 suggest_firewall_config->SetString("header",
683 l10n_util::GetStringUTF16(
684 IDS_ERRORPAGES_SUGGESTION_FIREWALL_CONFIG_HEADER));
685 suggest_firewall_config->SetString("body",
686 l10n_util::GetStringUTF16(
687 IDS_ERRORPAGES_SUGGESTION_FIREWALL_CONFIG_BODY));
688 suggestions->Append(suggest_firewall_config);
691 if (options.suggestions & SUGGEST_PROXY_CONFIG) {
692 base::DictionaryValue* suggest_proxy_config = GetStandardMenuItemsText();
693 suggest_proxy_config->SetString("header",
694 l10n_util::GetStringUTF16(
695 IDS_ERRORPAGES_SUGGESTION_PROXY_CONFIG_HEADER));
696 suggest_proxy_config->SetString("body",
697 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_SUGGESTION_PROXY_CONFIG_BODY,
698 l10n_util::GetStringUTF16(
699 IDS_ERRORPAGES_SUGGESTION_PROXY_DISABLE_PLATFORM)));
700 suggest_proxy_config->SetString("proxyTitle",
701 l10n_util::GetStringUTF16(IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON));
703 suggestions->Append(suggest_proxy_config);
706 if (options.suggestions & SUGGEST_DISABLE_EXTENSION) {
707 base::DictionaryValue* suggest_disable_extension =
708 new base::DictionaryValue;
709 // There's only a header for this suggestion.
710 suggest_disable_extension->SetString("header",
711 l10n_util::GetStringUTF16(
712 IDS_ERRORPAGES_SUGGESTION_DISABLE_EXTENSION_HEADER));
713 suggestions->Append(suggest_disable_extension);
716 if (options.suggestions & SUGGEST_VIEW_POLICIES) {
717 base::DictionaryValue* suggest_view_policies = new base::DictionaryValue;
718 suggest_view_policies->SetString(
719 "header",
720 l10n_util::GetStringUTF16(
721 IDS_ERRORPAGES_SUGGESTION_VIEW_POLICIES_HEADER));
722 suggest_view_policies->SetString(
723 "body",
724 l10n_util::GetStringUTF16(
725 IDS_ERRORPAGES_SUGGESTION_VIEW_POLICIES_BODY));
726 suggestions->Append(suggest_view_policies);
729 if (options.suggestions & SUGGEST_CONTACT_ADMINISTRATOR) {
730 base::DictionaryValue* suggest_contant_administrator =
731 new base::DictionaryValue;
732 suggest_contant_administrator->SetString(
733 "body",
734 l10n_util::GetStringUTF16(
735 IDS_ERRORPAGES_SUGGESTION_CONTACT_ADMINISTRATOR_BODY));
736 suggestions->Append(suggest_contant_administrator);
739 if (options.suggestions & SUGGEST_LEARNMORE) {
740 GURL learn_more_url;
741 switch (options.error_code) {
742 case net::ERR_TOO_MANY_REDIRECTS:
743 learn_more_url = GURL(kRedirectLoopLearnMoreUrl);
744 break;
745 case net::ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY:
746 learn_more_url = GURL(kWeakDHKeyLearnMoreUrl);
747 break;
748 default:
749 break;
752 if (learn_more_url.is_valid()) {
753 // Add the language parameter to the URL.
754 std::string query = learn_more_url.query() + "&hl=" + locale;
755 GURL::Replacements repl;
756 repl.SetQueryStr(query);
757 learn_more_url = learn_more_url.ReplaceComponents(repl);
759 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue;
760 // There's only a body for this suggestion.
761 suggest_learn_more->SetString("body",
762 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY));
763 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec());
764 suggestions->Append(suggest_learn_more);
768 error_strings->Set("suggestions", suggestions);
771 base::string16 LocalizedError::GetErrorDetails(const blink::WebURLError& error,
772 bool is_post) {
773 const LocalizedErrorMap* error_map =
774 LookupErrorMap(error.domain.utf8(), error.reason, is_post);
775 if (error_map)
776 return l10n_util::GetStringUTF16(error_map->details_resource_id);
777 else
778 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN);
781 bool LocalizedError::HasStrings(const std::string& error_domain,
782 int error_code) {
783 // Whether or not the there are strings for an error does not depend on
784 // whether or not the page was be generated by a POST, so just claim it was
785 // not.
786 return LookupErrorMap(error_domain, error_code, /*is_post=*/false) != NULL;
789 void LocalizedError::GetAppErrorStrings(
790 const GURL& display_url,
791 const extensions::Extension* app,
792 base::DictionaryValue* error_strings) {
793 DCHECK(app);
795 bool rtl = LocaleIsRTL();
796 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr");
798 base::string16 failed_url(base::ASCIIToUTF16(display_url.spec()));
799 // URLs are always LTR.
800 if (rtl)
801 base::i18n::WrapStringWithLTRFormatting(&failed_url);
802 error_strings->SetString(
803 "url", l10n_util::GetStringFUTF16(IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
804 failed_url.c_str()));
806 error_strings->SetString("title", app->name());
807 error_strings->SetString(
808 "icon",
809 extensions::IconsInfo::GetIconURL(
810 app,
811 extension_misc::EXTENSION_ICON_GIGANTOR,
812 ExtensionIconSet::MATCH_SMALLER).spec());
813 error_strings->SetString("name", app->name());
814 error_strings->SetString(
815 "msg",
816 l10n_util::GetStringUTF16(IDS_ERRORPAGES_APP_WARNING));
818 #if defined(OS_CHROMEOS)
819 GURL learn_more_url(kAppWarningLearnMoreUrl);
820 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue();
821 suggest_learn_more->SetString("msg",
822 l10n_util::GetStringUTF16(
823 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY));
824 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec());
825 error_strings->Set("suggestionsLearnMore", suggest_learn_more);
826 #endif // defined(OS_CHROMEOS)