OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/common/localized_error.h" | 5 #include "chrome/common/localized_error.h" |
6 | 6 |
7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/common/extensions/extension_constants.h" | 14 #include "chrome/common/extensions/extension_constants.h" |
15 #include "chrome/common/extensions/extension_icon_set.h" | 15 #include "chrome/common/extensions/extension_icon_set.h" |
16 #include "chrome/common/extensions/extension_set.h" | 16 #include "chrome/common/extensions/extension_set.h" |
17 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" | 17 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" |
| 18 #include "chrome/common/net/net_error_info.h" |
18 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
19 #include "grit/chromium_strings.h" | 20 #include "grit/chromium_strings.h" |
20 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
21 #include "net/base/escape.h" | 22 #include "net/base/escape.h" |
22 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
23 #include "third_party/WebKit/public/platform/WebURLError.h" | 24 #include "third_party/WebKit/public/platform/WebURLError.h" |
24 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
25 #include "ui/webui/web_ui_util.h" | 26 #include "ui/webui/web_ui_util.h" |
26 #include "webkit/glue/webkit_glue.h" | 27 #include "webkit/glue/webkit_glue.h" |
27 | 28 |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 }, | 363 }, |
363 {505, | 364 {505, |
364 IDS_ERRORPAGES_TITLE_LOAD_FAILED, | 365 IDS_ERRORPAGES_TITLE_LOAD_FAILED, |
365 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR, | 366 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR, |
366 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE, | 367 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE, |
367 IDS_ERRORPAGES_DETAILS_HTTP_VERSION_NOT_SUPPORTED, | 368 IDS_ERRORPAGES_DETAILS_HTTP_VERSION_NOT_SUPPORTED, |
368 SUGGEST_NONE, | 369 SUGGEST_NONE, |
369 }, | 370 }, |
370 }; | 371 }; |
371 | 372 |
| 373 const LocalizedErrorMap dns_probe_error_options[] = { |
| 374 {chrome_common_net::DNS_PROBE_POSSIBLE, |
| 375 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, |
| 376 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, |
| 377 IDS_ERRORPAGES_SUMMARY_DNS_PROBE_RUNNING, |
| 378 IDS_ERRORPAGES_DETAILS_DNS_PROBE_RUNNING, |
| 379 SUGGEST_RELOAD, |
| 380 }, |
| 381 |
| 382 // DNS_PROBE_NOT_RUN is not here; NetErrorHelper will restore the original |
| 383 // error, which might be one of several DNS-related errors. |
| 384 |
| 385 {chrome_common_net::DNS_PROBE_STARTED, |
| 386 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, |
| 387 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, |
| 388 IDS_ERRORPAGES_SUMMARY_DNS_PROBE_RUNNING, |
| 389 IDS_ERRORPAGES_DETAILS_DNS_PROBE_RUNNING, |
| 390 // Include SUGGEST_RELOAD so the More button doesn't jump when we update. |
| 391 SUGGEST_RELOAD, |
| 392 }, |
| 393 |
| 394 // DNS_PROBE_FINISHED_UNKNOWN is not here; NetErrorHelper will restore the |
| 395 // original error, which might be one of several DNS-related errors. |
| 396 |
| 397 {chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET, |
| 398 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, |
| 399 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, |
| 400 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED, |
| 401 IDS_ERRORPAGES_DETAILS_INTERNET_DISCONNECTED, |
| 402 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG, |
| 403 }, |
| 404 {chrome_common_net::DNS_PROBE_FINISHED_BAD_CONFIG, |
| 405 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, |
| 406 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, |
| 407 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED, |
| 408 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED, |
| 409 SUGGEST_RELOAD | SUGGEST_DNS_CONFIG | SUGGEST_FIREWALL_CONFIG, |
| 410 }, |
| 411 {chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN, |
| 412 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, |
| 413 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, |
| 414 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED, |
| 415 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED, |
| 416 SUGGEST_RELOAD, |
| 417 }, |
| 418 }; |
| 419 |
372 const LocalizedErrorMap* FindErrorMapInArray(const LocalizedErrorMap* maps, | 420 const LocalizedErrorMap* FindErrorMapInArray(const LocalizedErrorMap* maps, |
373 size_t num_maps, | 421 size_t num_maps, |
374 int error_code) { | 422 int error_code) { |
375 for (size_t i = 0; i < num_maps; ++i) { | 423 for (size_t i = 0; i < num_maps; ++i) { |
376 if (maps[i].error_code == error_code) | 424 if (maps[i].error_code == error_code) |
377 return &maps[i]; | 425 return &maps[i]; |
378 } | 426 } |
379 return NULL; | 427 return NULL; |
380 } | 428 } |
381 | 429 |
382 const LocalizedErrorMap* LookupErrorMap(const std::string& error_domain, | 430 const LocalizedErrorMap* LookupErrorMap(const std::string& error_domain, |
383 int error_code, bool is_post) { | 431 int error_code, bool is_post) { |
384 if (error_domain == net::kErrorDomain) { | 432 if (error_domain == net::kErrorDomain) { |
385 // Display a different page in the special case of navigating through the | 433 // Display a different page in the special case of navigating through the |
386 // history to an uncached page created by a POST. | 434 // history to an uncached page created by a POST. |
387 if (is_post && error_code == net::ERR_CACHE_MISS) | 435 if (is_post && error_code == net::ERR_CACHE_MISS) |
388 return &repost_error; | 436 return &repost_error; |
389 return FindErrorMapInArray(net_error_options, | 437 return FindErrorMapInArray(net_error_options, |
390 arraysize(net_error_options), | 438 arraysize(net_error_options), |
391 error_code); | 439 error_code); |
392 } else if (error_domain == LocalizedError::kHttpErrorDomain) { | 440 } else if (error_domain == LocalizedError::kHttpErrorDomain) { |
393 return FindErrorMapInArray(http_error_options, | 441 return FindErrorMapInArray(http_error_options, |
394 arraysize(http_error_options), | 442 arraysize(http_error_options), |
395 error_code); | 443 error_code); |
| 444 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) { |
| 445 const LocalizedErrorMap* map = |
| 446 FindErrorMapInArray(dns_probe_error_options, |
| 447 arraysize(dns_probe_error_options), |
| 448 error_code); |
| 449 DCHECK(map); |
| 450 return map; |
396 } else { | 451 } else { |
397 NOTREACHED(); | 452 NOTREACHED(); |
398 return NULL; | 453 return NULL; |
399 } | 454 } |
400 } | 455 } |
401 | 456 |
402 bool LocaleIsRTL() { | 457 bool LocaleIsRTL() { |
403 #if defined(TOOLKIT_GTK) | 458 #if defined(TOOLKIT_GTK) |
404 // base::i18n::IsRTL() uses the GTK text direction, which doesn't work within | 459 // base::i18n::IsRTL() uses the GTK text direction, which doesn't work within |
405 // the renderer sandbox. | 460 // the renderer sandbox. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 "errorDetails", l10n_util::GetStringUTF16(options.details_resource_id)); | 550 "errorDetails", l10n_util::GetStringUTF16(options.details_resource_id)); |
496 } | 551 } |
497 | 552 |
498 string16 error_string; | 553 string16 error_string; |
499 if (error_domain == net::kErrorDomain) { | 554 if (error_domain == net::kErrorDomain) { |
500 // Non-internationalized error string, for debugging Chrome itself. | 555 // Non-internationalized error string, for debugging Chrome itself. |
501 std::string ascii_error_string = net::ErrorToString(error_code); | 556 std::string ascii_error_string = net::ErrorToString(error_code); |
502 // Remove the leading "net::" from the returned string. | 557 // Remove the leading "net::" from the returned string. |
503 RemoveChars(ascii_error_string, "net:", &ascii_error_string); | 558 RemoveChars(ascii_error_string, "net:", &ascii_error_string); |
504 error_string = ASCIIToUTF16(ascii_error_string); | 559 error_string = ASCIIToUTF16(ascii_error_string); |
| 560 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) { |
| 561 std::string ascii_error_string = |
| 562 chrome_common_net::DnsProbeStatusToString(error_code); |
| 563 error_string = ASCIIToUTF16(ascii_error_string); |
505 } else { | 564 } else { |
506 DCHECK_EQ(LocalizedError::kHttpErrorDomain, error_domain); | 565 DCHECK_EQ(LocalizedError::kHttpErrorDomain, error_domain); |
507 error_string = base::IntToString16(error_code); | 566 error_string = base::IntToString16(error_code); |
508 } | 567 } |
509 error_strings->SetString("errorCode", | 568 error_strings->SetString("errorCode", |
510 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_ERROR_CODE, error_string)); | 569 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_ERROR_CODE, error_string)); |
511 | 570 |
512 base::ListValue* suggestions = new base::ListValue(); | 571 base::ListValue* suggestions = new base::ListValue(); |
513 | 572 |
514 // Platform specific instructions for diagnosing network issues on OSX and | 573 // Platform specific instructions for diagnosing network issues on OSX and |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 #if defined(OS_CHROMEOS) | 798 #if defined(OS_CHROMEOS) |
740 GURL learn_more_url(kAppWarningLearnMoreUrl); | 799 GURL learn_more_url(kAppWarningLearnMoreUrl); |
741 DictionaryValue* suggest_learn_more = new DictionaryValue(); | 800 DictionaryValue* suggest_learn_more = new DictionaryValue(); |
742 suggest_learn_more->SetString("msg", | 801 suggest_learn_more->SetString("msg", |
743 l10n_util::GetStringUTF16( | 802 l10n_util::GetStringUTF16( |
744 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); | 803 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); |
745 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); | 804 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); |
746 error_strings->Set("suggestionsLearnMore", suggest_learn_more); | 805 error_strings->Set("suggestionsLearnMore", suggest_learn_more); |
747 #endif // defined(OS_CHROMEOS) | 806 #endif // defined(OS_CHROMEOS) |
748 } | 807 } |
OLD | NEW |