Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / common / localized_error.cc
blobcc50bf3c0b97f93c9780714a1c206350a753472c
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 static const char kSSLv3FallbackUrl[] =
48 "https://code.google.com/p/chromium/issues/detail?id=418848";
49 #if defined(OS_CHROMEOS)
50 static const char kAppWarningLearnMoreUrl[] =
51 "chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"
52 "?answer=1721911";
53 #endif // defined(OS_CHROMEOS)
55 enum NAV_SUGGESTIONS {
56 SUGGEST_NONE = 0,
57 SUGGEST_RELOAD = 1 << 0,
58 SUGGEST_CHECK_CONNECTION = 1 << 1,
59 SUGGEST_DNS_CONFIG = 1 << 2,
60 SUGGEST_FIREWALL_CONFIG = 1 << 3,
61 SUGGEST_PROXY_CONFIG = 1 << 4,
62 SUGGEST_DISABLE_EXTENSION = 1 << 5,
63 SUGGEST_LEARNMORE = 1 << 6,
64 SUGGEST_VIEW_POLICIES = 1 << 7,
65 SUGGEST_CONTACT_ADMINISTRATOR = 1 << 8,
68 struct LocalizedErrorMap {
69 int error_code;
70 unsigned int title_resource_id;
71 unsigned int heading_resource_id;
72 // Detailed summary used when the error is in the main frame.
73 unsigned int summary_resource_id;
74 // Short one sentence description shown on mouse over when the error is in
75 // a frame.
76 unsigned int details_resource_id;
77 int suggestions; // Bitmap of SUGGEST_* values.
80 const LocalizedErrorMap net_error_options[] = {
81 {net::ERR_TIMED_OUT,
82 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
83 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
84 IDS_ERRORPAGES_SUMMARY_TIMED_OUT,
85 IDS_ERRORPAGES_DETAILS_TIMED_OUT,
86 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
87 SUGGEST_PROXY_CONFIG,
89 {net::ERR_CONNECTION_TIMED_OUT,
90 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
91 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
92 IDS_ERRORPAGES_SUMMARY_TIMED_OUT,
93 IDS_ERRORPAGES_DETAILS_TIMED_OUT,
94 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
95 SUGGEST_PROXY_CONFIG,
97 {net::ERR_CONNECTION_CLOSED,
98 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
99 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
100 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
101 IDS_ERRORPAGES_DETAILS_CONNECTION_CLOSED,
102 SUGGEST_RELOAD,
104 {net::ERR_CONNECTION_RESET,
105 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
106 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
107 IDS_ERRORPAGES_SUMMARY_CONNECTION_RESET,
108 IDS_ERRORPAGES_DETAILS_CONNECTION_RESET,
109 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
110 SUGGEST_PROXY_CONFIG,
112 {net::ERR_CONNECTION_REFUSED,
113 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
114 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
115 IDS_ERRORPAGES_SUMMARY_CONNECTION_REFUSED,
116 IDS_ERRORPAGES_DETAILS_CONNECTION_REFUSED,
117 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG |
118 SUGGEST_PROXY_CONFIG,
120 {net::ERR_CONNECTION_FAILED,
121 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
122 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
123 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
124 IDS_ERRORPAGES_DETAILS_CONNECTION_FAILED,
125 SUGGEST_RELOAD,
127 {net::ERR_NAME_NOT_RESOLVED,
128 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
129 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
130 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED,
131 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED,
132 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_DNS_CONFIG |
133 SUGGEST_FIREWALL_CONFIG | SUGGEST_PROXY_CONFIG,
135 {net::ERR_ADDRESS_UNREACHABLE,
136 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
137 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
138 IDS_ERRORPAGES_SUMMARY_ADDRESS_UNREACHABLE,
139 IDS_ERRORPAGES_DETAILS_ADDRESS_UNREACHABLE,
140 SUGGEST_RELOAD | SUGGEST_FIREWALL_CONFIG | SUGGEST_PROXY_CONFIG,
142 {net::ERR_NETWORK_ACCESS_DENIED,
143 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
144 IDS_ERRORPAGES_HEADING_NETWORK_ACCESS_DENIED,
145 IDS_ERRORPAGES_SUMMARY_NETWORK_ACCESS_DENIED,
146 IDS_ERRORPAGES_DETAILS_NETWORK_ACCESS_DENIED,
147 SUGGEST_FIREWALL_CONFIG,
149 {net::ERR_PROXY_CONNECTION_FAILED,
150 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
151 IDS_ERRORPAGES_HEADING_PROXY_CONNECTION_FAILED,
152 IDS_ERRORPAGES_SUMMARY_PROXY_CONNECTION_FAILED,
153 IDS_ERRORPAGES_DETAILS_PROXY_CONNECTION_FAILED,
154 SUGGEST_PROXY_CONFIG,
156 {net::ERR_INTERNET_DISCONNECTED,
157 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
158 IDS_ERRORPAGES_HEADING_INTERNET_DISCONNECTED,
159 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED,
160 IDS_ERRORPAGES_DETAILS_INTERNET_DISCONNECTED,
161 SUGGEST_NONE,
163 {net::ERR_FILE_NOT_FOUND,
164 IDS_ERRORPAGES_TITLE_NOT_FOUND,
165 IDS_ERRORPAGES_HEADING_NOT_FOUND,
166 IDS_ERRORPAGES_SUMMARY_NOT_FOUND,
167 IDS_ERRORPAGES_DETAILS_FILE_NOT_FOUND,
168 SUGGEST_NONE,
170 {net::ERR_CACHE_MISS,
171 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
172 IDS_ERRORPAGES_HEADING_CACHE_MISS,
173 IDS_ERRORPAGES_SUMMARY_CACHE_MISS,
174 IDS_ERRORPAGES_DETAILS_CACHE_MISS,
175 SUGGEST_RELOAD,
177 {net::ERR_CACHE_READ_FAILURE,
178 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
179 IDS_ERRORPAGES_HEADING_CACHE_READ_FAILURE,
180 IDS_ERRORPAGES_SUMMARY_CACHE_READ_FAILURE,
181 IDS_ERRORPAGES_DETAILS_CACHE_READ_FAILURE,
182 SUGGEST_RELOAD,
184 {net::ERR_NETWORK_IO_SUSPENDED,
185 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
186 IDS_ERRORPAGES_HEADING_NETWORK_IO_SUSPENDED,
187 IDS_ERRORPAGES_SUMMARY_NETWORK_IO_SUSPENDED,
188 IDS_ERRORPAGES_DETAILS_NETWORK_IO_SUSPENDED,
189 SUGGEST_RELOAD,
191 {net::ERR_TOO_MANY_REDIRECTS,
192 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
193 IDS_ERRORPAGES_HEADING_TOO_MANY_REDIRECTS,
194 IDS_ERRORPAGES_SUMMARY_TOO_MANY_REDIRECTS,
195 IDS_ERRORPAGES_DETAILS_TOO_MANY_REDIRECTS,
196 SUGGEST_RELOAD | SUGGEST_LEARNMORE,
198 {net::ERR_EMPTY_RESPONSE,
199 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
200 IDS_ERRORPAGES_HEADING_EMPTY_RESPONSE,
201 IDS_ERRORPAGES_SUMMARY_EMPTY_RESPONSE,
202 IDS_ERRORPAGES_DETAILS_EMPTY_RESPONSE,
203 SUGGEST_RELOAD,
205 {net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH,
206 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
207 IDS_ERRORPAGES_HEADING_DUPLICATE_HEADERS,
208 IDS_ERRORPAGES_SUMMARY_DUPLICATE_HEADERS,
209 IDS_ERRORPAGES_DETAILS_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH,
210 SUGGEST_NONE,
212 {net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION,
213 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
214 IDS_ERRORPAGES_HEADING_DUPLICATE_HEADERS,
215 IDS_ERRORPAGES_SUMMARY_DUPLICATE_HEADERS,
216 IDS_ERRORPAGES_DETAILS_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION,
217 SUGGEST_NONE,
219 {net::ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION,
220 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
221 IDS_ERRORPAGES_HEADING_DUPLICATE_HEADERS,
222 IDS_ERRORPAGES_SUMMARY_DUPLICATE_HEADERS,
223 IDS_ERRORPAGES_DETAILS_RESPONSE_HEADERS_MULTIPLE_LOCATION,
224 SUGGEST_NONE,
226 {net::ERR_CONTENT_LENGTH_MISMATCH,
227 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
228 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
229 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
230 IDS_ERRORPAGES_DETAILS_CONNECTION_CLOSED,
231 SUGGEST_RELOAD,
233 {net::ERR_INCOMPLETE_CHUNKED_ENCODING,
234 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
235 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
236 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
237 IDS_ERRORPAGES_DETAILS_CONNECTION_CLOSED,
238 SUGGEST_RELOAD,
240 {net::ERR_SSL_PROTOCOL_ERROR,
241 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
242 IDS_ERRORPAGES_HEADING_SSL_PROTOCOL_ERROR,
243 IDS_ERRORPAGES_SUMMARY_SSL_PROTOCOL_ERROR,
244 IDS_ERRORPAGES_DETAILS_SSL_PROTOCOL_ERROR,
245 SUGGEST_NONE,
247 {net::ERR_SSL_UNSAFE_NEGOTIATION,
248 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
249 IDS_ERRORPAGES_HEADING_SSL_PROTOCOL_ERROR,
250 IDS_ERRORPAGES_SUMMARY_SSL_PROTOCOL_ERROR,
251 IDS_ERRORPAGES_DETAILS_SSL_UNSAFE_NEGOTIATION,
252 SUGGEST_NONE,
254 {net::ERR_BAD_SSL_CLIENT_AUTH_CERT,
255 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
256 IDS_ERRORPAGES_HEADING_BAD_SSL_CLIENT_AUTH_CERT,
257 IDS_ERRORPAGES_SUMMARY_BAD_SSL_CLIENT_AUTH_CERT,
258 IDS_ERRORPAGES_DETAILS_BAD_SSL_CLIENT_AUTH_CERT,
259 SUGGEST_NONE,
261 {net::ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY,
262 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
263 IDS_ERRORPAGES_HEADING_WEAK_SERVER_EPHEMERAL_DH_KEY,
264 IDS_ERRORPAGES_SUMMARY_WEAK_SERVER_EPHEMERAL_DH_KEY,
265 IDS_ERRORPAGES_DETAILS_SSL_PROTOCOL_ERROR,
266 SUGGEST_LEARNMORE,
268 {net::ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN,
269 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
270 IDS_ERRORPAGES_HEADING_PINNING_FAILURE,
271 IDS_ERRORPAGES_SUMMARY_PINNING_FAILURE,
272 IDS_ERRORPAGES_DETAILS_PINNING_FAILURE,
273 SUGGEST_NONE,
275 {net::ERR_TEMPORARILY_THROTTLED,
276 IDS_ERRORPAGES_TITLE_ACCESS_DENIED,
277 IDS_ERRORPAGES_HEADING_ACCESS_DENIED,
278 IDS_ERRORPAGES_SUMMARY_TEMPORARILY_THROTTLED,
279 IDS_ERRORPAGES_DETAILS_TEMPORARILY_THROTTLED,
280 SUGGEST_NONE,
282 {net::ERR_BLOCKED_BY_CLIENT,
283 IDS_ERRORPAGES_TITLE_BLOCKED,
284 IDS_ERRORPAGES_HEADING_BLOCKED,
285 IDS_ERRORPAGES_SUMMARY_BLOCKED,
286 IDS_ERRORPAGES_DETAILS_BLOCKED,
287 SUGGEST_RELOAD | SUGGEST_DISABLE_EXTENSION,
289 {net::ERR_NETWORK_CHANGED,
290 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
291 IDS_ERRORPAGES_HEADING_NETWORK_ACCESS_DENIED,
292 IDS_ERRORPAGES_SUMMARY_NETWORK_CHANGED,
293 IDS_ERRORPAGES_DETAILS_NETWORK_CHANGED,
294 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION,
296 {net::ERR_BLOCKED_BY_ADMINISTRATOR,
297 IDS_ERRORPAGES_TITLE_BLOCKED,
298 IDS_ERRORPAGES_HEADING_BLOCKED_BY_ADMINISTRATOR,
299 IDS_ERRORPAGES_SUMMARY_BLOCKED_BY_ADMINISTRATOR,
300 IDS_ERRORPAGES_DETAILS_BLOCKED_BY_ADMINISTRATOR,
301 SUGGEST_VIEW_POLICIES | SUGGEST_CONTACT_ADMINISTRATOR,
303 {net::ERR_BLOCKED_ENROLLMENT_CHECK_PENDING,
304 IDS_ERRORPAGES_TITLE_BLOCKED,
305 IDS_ERRORPAGES_HEADING_BLOCKED_BY_ADMINISTRATOR,
306 IDS_ERRORPAGES_SUMMARY_BLOCKED_ENROLLMENT_CHECK_PENDING,
307 IDS_ERRORPAGES_DETAILS_BLOCKED_ENROLLMENT_CHECK_PENDING,
308 SUGGEST_CHECK_CONNECTION,
310 {net::ERR_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
311 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
312 IDS_ERRORPAGES_HEADING_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
313 IDS_ERRORPAGES_SUMMARY_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
314 IDS_ERRORPAGES_DETAILS_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
315 SUGGEST_LEARNMORE,
319 // Special error page to be used in the case of navigating back to a page
320 // generated by a POST. LocalizedError::HasStrings expects this net error code
321 // to also appear in the array above.
322 const LocalizedErrorMap repost_error = {
323 net::ERR_CACHE_MISS,
324 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
325 IDS_HTTP_POST_WARNING_TITLE,
326 IDS_ERRORPAGES_HTTP_POST_WARNING,
327 IDS_ERRORPAGES_DETAILS_CACHE_MISS,
328 SUGGEST_RELOAD,
331 const LocalizedErrorMap http_error_options[] = {
332 {403,
333 IDS_ERRORPAGES_TITLE_ACCESS_DENIED,
334 IDS_ERRORPAGES_HEADING_ACCESS_DENIED,
335 IDS_ERRORPAGES_SUMMARY_FORBIDDEN,
336 IDS_ERRORPAGES_DETAILS_FORBIDDEN,
337 SUGGEST_NONE,
339 {410,
340 IDS_ERRORPAGES_TITLE_NOT_FOUND,
341 IDS_ERRORPAGES_HEADING_NOT_FOUND,
342 IDS_ERRORPAGES_SUMMARY_GONE,
343 IDS_ERRORPAGES_DETAILS_GONE,
344 SUGGEST_NONE,
347 {500,
348 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
349 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
350 IDS_ERRORPAGES_SUMMARY_INTERNAL_SERVER_ERROR,
351 IDS_ERRORPAGES_DETAILS_INTERNAL_SERVER_ERROR,
352 SUGGEST_RELOAD,
354 {501,
355 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
356 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
357 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE,
358 IDS_ERRORPAGES_DETAILS_NOT_IMPLEMENTED,
359 SUGGEST_NONE,
361 {502,
362 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
363 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
364 IDS_ERRORPAGES_SUMMARY_BAD_GATEWAY,
365 IDS_ERRORPAGES_DETAILS_BAD_GATEWAY,
366 SUGGEST_RELOAD,
368 {503,
369 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
370 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
371 IDS_ERRORPAGES_SUMMARY_SERVICE_UNAVAILABLE,
372 IDS_ERRORPAGES_DETAILS_SERVICE_UNAVAILABLE,
373 SUGGEST_RELOAD,
375 {504,
376 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
377 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
378 IDS_ERRORPAGES_SUMMARY_GATEWAY_TIMEOUT,
379 IDS_ERRORPAGES_DETAILS_GATEWAY_TIMEOUT,
380 SUGGEST_RELOAD,
382 {505,
383 IDS_ERRORPAGES_TITLE_LOAD_FAILED,
384 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR,
385 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE,
386 IDS_ERRORPAGES_DETAILS_HTTP_VERSION_NOT_SUPPORTED,
387 SUGGEST_NONE,
391 const LocalizedErrorMap dns_probe_error_options[] = {
392 {chrome_common_net::DNS_PROBE_POSSIBLE,
393 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
394 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
395 IDS_ERRORPAGES_SUMMARY_DNS_PROBE_RUNNING,
396 IDS_ERRORPAGES_DETAILS_DNS_PROBE_RUNNING,
397 SUGGEST_RELOAD,
400 // DNS_PROBE_NOT_RUN is not here; NetErrorHelper will restore the original
401 // error, which might be one of several DNS-related errors.
403 {chrome_common_net::DNS_PROBE_STARTED,
404 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
405 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
406 IDS_ERRORPAGES_SUMMARY_DNS_PROBE_RUNNING,
407 IDS_ERRORPAGES_DETAILS_DNS_PROBE_RUNNING,
408 // Include SUGGEST_RELOAD so the More button doesn't jump when we update.
409 SUGGEST_RELOAD,
412 // DNS_PROBE_FINISHED_UNKNOWN is not here; NetErrorHelper will restore the
413 // original error, which might be one of several DNS-related errors.
415 {chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET,
416 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
417 IDS_ERRORPAGES_HEADING_INTERNET_DISCONNECTED,
418 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED,
419 IDS_ERRORPAGES_DETAILS_INTERNET_DISCONNECTED,
420 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG,
422 {chrome_common_net::DNS_PROBE_FINISHED_BAD_CONFIG,
423 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
424 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
425 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED,
426 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED,
427 SUGGEST_RELOAD | SUGGEST_DNS_CONFIG | SUGGEST_FIREWALL_CONFIG,
429 {chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN,
430 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
431 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
432 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED,
433 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED,
434 SUGGEST_RELOAD,
438 const LocalizedErrorMap* FindErrorMapInArray(const LocalizedErrorMap* maps,
439 size_t num_maps,
440 int error_code) {
441 for (size_t i = 0; i < num_maps; ++i) {
442 if (maps[i].error_code == error_code)
443 return &maps[i];
445 return NULL;
448 const LocalizedErrorMap* LookupErrorMap(const std::string& error_domain,
449 int error_code, bool is_post) {
450 if (error_domain == net::kErrorDomain) {
451 // Display a different page in the special case of navigating through the
452 // history to an uncached page created by a POST.
453 if (is_post && error_code == net::ERR_CACHE_MISS)
454 return &repost_error;
455 return FindErrorMapInArray(net_error_options,
456 arraysize(net_error_options),
457 error_code);
458 } else if (error_domain == LocalizedError::kHttpErrorDomain) {
459 return FindErrorMapInArray(http_error_options,
460 arraysize(http_error_options),
461 error_code);
462 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) {
463 const LocalizedErrorMap* map =
464 FindErrorMapInArray(dns_probe_error_options,
465 arraysize(dns_probe_error_options),
466 error_code);
467 DCHECK(map);
468 return map;
469 } else {
470 NOTREACHED();
471 return NULL;
475 bool LocaleIsRTL() {
476 return base::i18n::IsRTL();
479 // Returns a dictionary containing the strings for the settings menu under the
480 // wrench, and the advanced settings button.
481 base::DictionaryValue* GetStandardMenuItemsText() {
482 base::DictionaryValue* standard_menu_items_text = new base::DictionaryValue();
483 standard_menu_items_text->SetString("settingsTitle",
484 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE));
485 standard_menu_items_text->SetString("advancedTitle",
486 l10n_util::GetStringUTF16(IDS_SETTINGS_SHOW_ADVANCED_SETTINGS));
487 return standard_menu_items_text;
490 // Gets the icon class for a given |error_domain| and |error_code|.
491 const char* GetIconClassForError(const std::string& error_domain,
492 int error_code) {
493 if ((error_code == net::ERR_INTERNET_DISCONNECTED &&
494 error_domain == net::kErrorDomain) ||
495 (error_code == chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET &&
496 error_domain == chrome_common_net::kDnsProbeErrorDomain))
497 return "icon-offline";
499 return "icon-generic";
502 } // namespace
504 const char LocalizedError::kHttpErrorDomain[] = "http";
506 void LocalizedError::GetStrings(int error_code,
507 const std::string& error_domain,
508 const GURL& failed_url,
509 bool is_post,
510 bool show_stale_load_button,
511 const std::string& locale,
512 const std::string& accept_languages,
513 scoped_ptr<error_page::ErrorPageParams> params,
514 base::DictionaryValue* error_strings) {
515 bool rtl = LocaleIsRTL();
516 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr");
517 webui::SetFontAndTextDirection(error_strings);
519 // Grab the strings and settings that depend on the error type. Init
520 // options with default values.
521 LocalizedErrorMap options = {
523 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
524 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE,
525 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE,
526 kErrorPagesNoDetails,
527 SUGGEST_NONE,
530 const LocalizedErrorMap* error_map = LookupErrorMap(error_domain, error_code,
531 is_post);
532 if (error_map)
533 options = *error_map;
535 // If we got "access denied" but the url was a file URL, then we say it was a
536 // file instead of just using the "not available" default message. Just adding
537 // ERR_ACCESS_DENIED to the map isn't sufficient, since that message may be
538 // generated by some OSs when the operation doesn't involve a file URL.
539 if (error_domain == net::kErrorDomain &&
540 error_code == net::ERR_ACCESS_DENIED &&
541 failed_url.scheme() == "file") {
542 options.title_resource_id = IDS_ERRORPAGES_TITLE_ACCESS_DENIED;
543 options.heading_resource_id = IDS_ERRORPAGES_HEADING_FILE_ACCESS_DENIED;
544 options.summary_resource_id = IDS_ERRORPAGES_SUMMARY_FILE_ACCESS_DENIED;
545 options.details_resource_id = IDS_ERRORPAGES_DETAILS_FILE_ACCESS_DENIED;
546 options.suggestions = SUGGEST_NONE;
549 base::string16 failed_url_string(net::FormatUrl(
550 failed_url, accept_languages, net::kFormatUrlOmitNothing,
551 net::UnescapeRule::NORMAL, NULL, NULL, NULL));
552 // URLs are always LTR.
553 if (rtl)
554 base::i18n::WrapStringWithLTRFormatting(&failed_url_string);
555 error_strings->SetString("title",
556 l10n_util::GetStringFUTF16(options.title_resource_id, failed_url_string));
557 error_strings->SetString("heading",
558 l10n_util::GetStringUTF16(options.heading_resource_id));
560 std::string icon_class = GetIconClassForError(error_domain, error_code);
561 error_strings->SetString("iconClass", icon_class);
563 base::DictionaryValue* summary = new base::DictionaryValue;
565 // For offline show a summary message underneath the heading.
566 if (error_code == net::ERR_INTERNET_DISCONNECTED ||
567 error_code == chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET) {
568 error_strings->SetString("primaryParagraph",
569 l10n_util::GetStringUTF16(options.summary_resource_id));
570 } else {
571 // Set summary message in the details.
572 summary->SetString("msg",
573 l10n_util::GetStringUTF16(options.summary_resource_id));
575 summary->SetString("failedUrl", failed_url_string);
576 summary->SetString("hostName", net::IDNToUnicode(failed_url.host(),
577 accept_languages));
578 summary->SetString("productName",
579 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
581 error_strings->SetString(
582 "details", l10n_util::GetStringUTF16(IDS_ERRORPAGE_NET_BUTTON_DETAILS));
583 error_strings->SetString(
584 "hideDetails", l10n_util::GetStringUTF16(
585 IDS_ERRORPAGE_NET_BUTTON_HIDE_DETAILS));
586 error_strings->Set("summary", summary);
588 if (options.details_resource_id != kErrorPagesNoDetails) {
589 error_strings->SetString(
590 "errorDetails", l10n_util::GetStringUTF16(options.details_resource_id));
593 base::string16 error_string;
594 if (error_domain == net::kErrorDomain) {
595 // Non-internationalized error string, for debugging Chrome itself.
596 error_string = base::ASCIIToUTF16(net::ErrorToShortString(error_code));
597 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) {
598 std::string ascii_error_string =
599 chrome_common_net::DnsProbeStatusToString(error_code);
600 error_string = base::ASCIIToUTF16(ascii_error_string);
601 } else {
602 DCHECK_EQ(LocalizedError::kHttpErrorDomain, error_domain);
603 error_string = base::IntToString16(error_code);
605 error_strings->SetString("errorCode",
606 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_ERROR_CODE, error_string));
608 // Platform specific information for diagnosing network issues on OSX and
609 // Windows.
610 #if defined(OS_MACOSX) || defined(OS_WIN)
611 if (error_domain == net::kErrorDomain &&
612 error_code == net::ERR_INTERNET_DISCONNECTED) {
613 int platform_string_id =
614 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM;
615 #if defined(OS_WIN)
616 // Different versions of Windows have different instructions.
617 base::win::Version windows_version = base::win::GetVersion();
618 if (windows_version < base::win::VERSION_VISTA) {
619 // XP, XP64, and Server 2003.
620 platform_string_id =
621 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_XP;
622 } else if (windows_version == base::win::VERSION_VISTA) {
623 // Vista
624 platform_string_id =
625 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_PLATFORM_VISTA;
627 #endif // defined(OS_WIN)
628 // Platform dependent portion of the summary section.
629 summary->SetString("msg",
630 l10n_util::GetStringFUTF16(
631 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_INSTRUCTIONS_TEMPLATE,
632 l10n_util::GetStringUTF16(platform_string_id)));
634 #endif // defined(OS_MACOSX) || defined(OS_WIN)
636 // If no parameters were provided, use the defaults.
637 if (!params) {
638 params.reset(new error_page::ErrorPageParams());
639 params->suggest_reload = !!(options.suggestions & SUGGEST_RELOAD);
642 base::ListValue* suggestions = NULL;
643 bool use_default_suggestions = true;
644 if (!params->override_suggestions) {
645 suggestions = new base::ListValue();
646 } else {
647 suggestions = params->override_suggestions.release();
648 use_default_suggestions = false;
651 error_strings->Set("suggestions", suggestions);
653 if (params->search_url.is_valid()) {
654 error_strings->SetString("searchHeader",
655 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_GOOGLE_SEARCH));
656 error_strings->SetString("searchUrl", params->search_url.spec());
657 error_strings->SetString("searchTerms", params->search_terms);
658 error_strings->SetInteger("searchTrackingId", params->search_tracking_id);
661 // Add the reload suggestion, if needed.
662 if (params->suggest_reload) {
663 if (!is_post) {
664 base::DictionaryValue* reload_button = new base::DictionaryValue;
665 reload_button->SetString(
666 "msg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD));
667 reload_button->SetString("reloadUrl", failed_url.spec());
668 error_strings->Set("reloadButton", reload_button);
669 reload_button->SetInteger("reloadTrackingId", params->reload_tracking_id);
670 } else {
671 // If the page was created by a post, it can't be reloaded in the same
672 // way, so just add a suggestion instead.
673 // TODO(mmenke): Make the reload button bring up the repost confirmation
674 // dialog for pages resulting from posts.
675 base::DictionaryValue* suggest_reload_repost = new base::DictionaryValue;
676 suggest_reload_repost->SetString("header",
677 l10n_util::GetStringUTF16(
678 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_HEADER));
679 suggest_reload_repost->SetString("body",
680 l10n_util::GetStringUTF16(
681 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_BODY));
682 // Add at the front, so it appears before other suggestions, in the case
683 // suggestions are being overridden by |params|.
684 suggestions->Insert(0, suggest_reload_repost);
688 // If not using the default suggestions, nothing else to do.
689 if (!use_default_suggestions)
690 return;
692 if (show_stale_load_button) {
693 base::DictionaryValue* stale_load_button = new base::DictionaryValue;
694 stale_load_button->SetString(
695 "msg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_LOAD_STALE));
696 stale_load_button->SetString(
697 "title",
698 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_LOAD_STALE_HELP));
699 error_strings->Set("staleLoadButton", stale_load_button);
702 #if defined(OS_CHROMEOS)
703 error_strings->SetString(
704 "diagnose", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_DIAGNOSE));
705 #endif // defined(OS_CHROMEOS)
707 if (options.suggestions & SUGGEST_CHECK_CONNECTION) {
708 base::DictionaryValue* suggest_check_connection = new base::DictionaryValue;
709 suggest_check_connection->SetString("header",
710 l10n_util::GetStringUTF16(
711 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER));
712 suggest_check_connection->SetString("body",
713 l10n_util::GetStringUTF16(
714 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_BODY));
715 suggestions->Append(suggest_check_connection);
718 if (options.suggestions & SUGGEST_DNS_CONFIG) {
719 base::DictionaryValue* suggest_dns_config = new base::DictionaryValue;
720 suggest_dns_config->SetString("header",
721 l10n_util::GetStringUTF16(
722 IDS_ERRORPAGES_SUGGESTION_DNS_CONFIG_HEADER));
723 suggest_dns_config->SetString("body",
724 l10n_util::GetStringUTF16(
725 IDS_ERRORPAGES_SUGGESTION_DNS_CONFIG_BODY));
726 suggestions->Append(suggest_dns_config);
728 base::DictionaryValue* suggest_network_prediction =
729 GetStandardMenuItemsText();
730 suggest_network_prediction->SetString("header",
731 l10n_util::GetStringUTF16(
732 IDS_ERRORPAGES_SUGGESTION_NETWORK_PREDICTION_HEADER));
733 suggest_network_prediction->SetString("body",
734 l10n_util::GetStringUTF16(
735 IDS_ERRORPAGES_SUGGESTION_NETWORK_PREDICTION_BODY));
736 suggest_network_prediction->SetString(
737 "noNetworkPredictionTitle",
738 l10n_util::GetStringUTF16(
739 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION));
740 suggestions->Append(suggest_network_prediction);
743 if (options.suggestions & SUGGEST_FIREWALL_CONFIG) {
744 base::DictionaryValue* suggest_firewall_config = new base::DictionaryValue;
745 suggest_firewall_config->SetString("header",
746 l10n_util::GetStringUTF16(
747 IDS_ERRORPAGES_SUGGESTION_FIREWALL_CONFIG_HEADER));
748 suggest_firewall_config->SetString("body",
749 l10n_util::GetStringUTF16(
750 IDS_ERRORPAGES_SUGGESTION_FIREWALL_CONFIG_BODY));
751 suggestions->Append(suggest_firewall_config);
754 if (options.suggestions & SUGGEST_PROXY_CONFIG) {
755 base::DictionaryValue* suggest_proxy_config = GetStandardMenuItemsText();
756 suggest_proxy_config->SetString("header",
757 l10n_util::GetStringUTF16(
758 IDS_ERRORPAGES_SUGGESTION_PROXY_CONFIG_HEADER));
759 suggest_proxy_config->SetString("body",
760 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_SUGGESTION_PROXY_CONFIG_BODY,
761 l10n_util::GetStringUTF16(
762 IDS_ERRORPAGES_SUGGESTION_PROXY_DISABLE_PLATFORM)));
763 suggest_proxy_config->SetString("proxyTitle",
764 l10n_util::GetStringUTF16(IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON));
766 suggestions->Append(suggest_proxy_config);
769 if (options.suggestions & SUGGEST_DISABLE_EXTENSION) {
770 base::DictionaryValue* suggest_disable_extension =
771 new base::DictionaryValue;
772 // There's only a header for this suggestion.
773 suggest_disable_extension->SetString("header",
774 l10n_util::GetStringUTF16(
775 IDS_ERRORPAGES_SUGGESTION_DISABLE_EXTENSION_HEADER));
776 suggestions->Append(suggest_disable_extension);
779 if (options.suggestions & SUGGEST_VIEW_POLICIES) {
780 base::DictionaryValue* suggest_view_policies = new base::DictionaryValue;
781 suggest_view_policies->SetString(
782 "header",
783 l10n_util::GetStringUTF16(
784 IDS_ERRORPAGES_SUGGESTION_VIEW_POLICIES_HEADER));
785 suggest_view_policies->SetString(
786 "body",
787 l10n_util::GetStringUTF16(
788 IDS_ERRORPAGES_SUGGESTION_VIEW_POLICIES_BODY));
789 suggestions->Append(suggest_view_policies);
792 if (options.suggestions & SUGGEST_CONTACT_ADMINISTRATOR) {
793 base::DictionaryValue* suggest_contant_administrator =
794 new base::DictionaryValue;
795 suggest_contant_administrator->SetString(
796 "body",
797 l10n_util::GetStringUTF16(
798 IDS_ERRORPAGES_SUGGESTION_CONTACT_ADMINISTRATOR_BODY));
799 suggestions->Append(suggest_contant_administrator);
802 if (options.suggestions & SUGGEST_LEARNMORE) {
803 GURL learn_more_url;
804 switch (options.error_code) {
805 case net::ERR_TOO_MANY_REDIRECTS:
806 learn_more_url = GURL(kRedirectLoopLearnMoreUrl);
807 break;
808 case net::ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY:
809 learn_more_url = GURL(kWeakDHKeyLearnMoreUrl);
810 break;
811 case net::ERR_SSL_FALLBACK_BEYOND_MINIMUM_VERSION:
812 learn_more_url = GURL(kSSLv3FallbackUrl);
813 break;
814 default:
815 break;
818 if (learn_more_url.is_valid()) {
819 // Add the language parameter to the URL.
820 std::string query = learn_more_url.query() + "&hl=" + locale;
821 GURL::Replacements repl;
822 repl.SetQueryStr(query);
823 learn_more_url = learn_more_url.ReplaceComponents(repl);
825 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue;
826 // There's only a body for this suggestion.
827 suggest_learn_more->SetString("body",
828 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY));
829 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec());
830 suggestions->Append(suggest_learn_more);
835 base::string16 LocalizedError::GetErrorDetails(const blink::WebURLError& error,
836 bool is_post) {
837 const LocalizedErrorMap* error_map =
838 LookupErrorMap(error.domain.utf8(), error.reason, is_post);
839 if (error_map)
840 return l10n_util::GetStringUTF16(error_map->details_resource_id);
841 else
842 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN);
845 bool LocalizedError::HasStrings(const std::string& error_domain,
846 int error_code) {
847 // Whether or not the there are strings for an error does not depend on
848 // whether or not the page was be generated by a POST, so just claim it was
849 // not.
850 return LookupErrorMap(error_domain, error_code, /*is_post=*/false) != NULL;
853 #if defined(ENABLE_EXTENSIONS)
854 void LocalizedError::GetAppErrorStrings(
855 const GURL& display_url,
856 const extensions::Extension* app,
857 base::DictionaryValue* error_strings) {
858 DCHECK(app);
860 bool rtl = LocaleIsRTL();
861 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr");
863 base::string16 failed_url(base::ASCIIToUTF16(display_url.spec()));
864 // URLs are always LTR.
865 if (rtl)
866 base::i18n::WrapStringWithLTRFormatting(&failed_url);
867 error_strings->SetString(
868 "url", l10n_util::GetStringFUTF16(IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
869 failed_url.c_str()));
871 error_strings->SetString("title", app->name());
872 error_strings->SetString(
873 "icon",
874 extensions::IconsInfo::GetIconURL(
875 app,
876 extension_misc::EXTENSION_ICON_GIGANTOR,
877 ExtensionIconSet::MATCH_SMALLER).spec());
878 error_strings->SetString("name", app->name());
879 error_strings->SetString(
880 "msg",
881 l10n_util::GetStringUTF16(IDS_ERRORPAGES_APP_WARNING));
883 #if defined(OS_CHROMEOS)
884 GURL learn_more_url(kAppWarningLearnMoreUrl);
885 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue();
886 suggest_learn_more->SetString("msg",
887 l10n_util::GetStringUTF16(
888 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY));
889 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec());
890 error_strings->Set("suggestionsLearnMore", suggest_learn_more);
891 #endif // defined(OS_CHROMEOS)
893 #endif