| 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" | |
| 19 #include "grit/chromium_strings.h" | 18 #include "grit/chromium_strings.h" |
| 20 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 21 #include "net/base/escape.h" | 20 #include "net/base/escape.h" |
| 22 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
| 23 #include "third_party/WebKit/public/platform/WebURLError.h" | 22 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "ui/webui/web_ui_util.h" | 24 #include "ui/webui/web_ui_util.h" |
| 26 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 27 #include "webkit/glue/webkit_glue.h" | 26 #include "webkit/glue/webkit_glue.h" |
| 28 | 27 |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 }, | 362 }, |
| 364 {505, | 363 {505, |
| 365 IDS_ERRORPAGES_TITLE_LOAD_FAILED, | 364 IDS_ERRORPAGES_TITLE_LOAD_FAILED, |
| 366 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR, | 365 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR, |
| 367 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE, | 366 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE, |
| 368 IDS_ERRORPAGES_DETAILS_HTTP_VERSION_NOT_SUPPORTED, | 367 IDS_ERRORPAGES_DETAILS_HTTP_VERSION_NOT_SUPPORTED, |
| 369 SUGGEST_NONE, | 368 SUGGEST_NONE, |
| 370 }, | 369 }, |
| 371 }; | 370 }; |
| 372 | 371 |
| 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 | |
| 420 const LocalizedErrorMap* FindErrorMapInArray(const LocalizedErrorMap* maps, | 372 const LocalizedErrorMap* FindErrorMapInArray(const LocalizedErrorMap* maps, |
| 421 size_t num_maps, | 373 size_t num_maps, |
| 422 int error_code) { | 374 int error_code) { |
| 423 for (size_t i = 0; i < num_maps; ++i) { | 375 for (size_t i = 0; i < num_maps; ++i) { |
| 424 if (maps[i].error_code == error_code) | 376 if (maps[i].error_code == error_code) |
| 425 return &maps[i]; | 377 return &maps[i]; |
| 426 } | 378 } |
| 427 return NULL; | 379 return NULL; |
| 428 } | 380 } |
| 429 | 381 |
| 430 const LocalizedErrorMap* LookupErrorMap(const std::string& error_domain, | 382 const LocalizedErrorMap* LookupErrorMap(const std::string& error_domain, |
| 431 int error_code, bool is_post) { | 383 int error_code, bool is_post) { |
| 432 if (error_domain == net::kErrorDomain) { | 384 if (error_domain == net::kErrorDomain) { |
| 433 // Display a different page in the special case of navigating through the | 385 // Display a different page in the special case of navigating through the |
| 434 // history to an uncached page created by a POST. | 386 // history to an uncached page created by a POST. |
| 435 if (is_post && error_code == net::ERR_CACHE_MISS) | 387 if (is_post && error_code == net::ERR_CACHE_MISS) |
| 436 return &repost_error; | 388 return &repost_error; |
| 437 return FindErrorMapInArray(net_error_options, | 389 return FindErrorMapInArray(net_error_options, |
| 438 arraysize(net_error_options), | 390 arraysize(net_error_options), |
| 439 error_code); | 391 error_code); |
| 440 } else if (error_domain == LocalizedError::kHttpErrorDomain) { | 392 } else if (error_domain == LocalizedError::kHttpErrorDomain) { |
| 441 return FindErrorMapInArray(http_error_options, | 393 return FindErrorMapInArray(http_error_options, |
| 442 arraysize(http_error_options), | 394 arraysize(http_error_options), |
| 443 error_code); | 395 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; | |
| 451 } else { | 396 } else { |
| 452 NOTREACHED(); | 397 NOTREACHED(); |
| 453 return NULL; | 398 return NULL; |
| 454 } | 399 } |
| 455 } | 400 } |
| 456 | 401 |
| 457 bool LocaleIsRTL() { | 402 bool LocaleIsRTL() { |
| 458 #if defined(TOOLKIT_GTK) | 403 #if defined(TOOLKIT_GTK) |
| 459 // base::i18n::IsRTL() uses the GTK text direction, which doesn't work within | 404 // base::i18n::IsRTL() uses the GTK text direction, which doesn't work within |
| 460 // the renderer sandbox. | 405 // the renderer sandbox. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 "errorDetails", l10n_util::GetStringUTF16(options.details_resource_id)); | 495 "errorDetails", l10n_util::GetStringUTF16(options.details_resource_id)); |
| 551 } | 496 } |
| 552 | 497 |
| 553 string16 error_string; | 498 string16 error_string; |
| 554 if (error_domain == net::kErrorDomain) { | 499 if (error_domain == net::kErrorDomain) { |
| 555 // Non-internationalized error string, for debugging Chrome itself. | 500 // Non-internationalized error string, for debugging Chrome itself. |
| 556 std::string ascii_error_string = net::ErrorToString(error_code); | 501 std::string ascii_error_string = net::ErrorToString(error_code); |
| 557 // Remove the leading "net::" from the returned string. | 502 // Remove the leading "net::" from the returned string. |
| 558 RemoveChars(ascii_error_string, "net:", &ascii_error_string); | 503 RemoveChars(ascii_error_string, "net:", &ascii_error_string); |
| 559 error_string = ASCIIToUTF16(ascii_error_string); | 504 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); | |
| 564 } else { | 505 } else { |
| 565 DCHECK_EQ(LocalizedError::kHttpErrorDomain, error_domain); | 506 DCHECK_EQ(LocalizedError::kHttpErrorDomain, error_domain); |
| 566 error_string = base::IntToString16(error_code); | 507 error_string = base::IntToString16(error_code); |
| 567 } | 508 } |
| 568 error_strings->SetString("errorCode", | 509 error_strings->SetString("errorCode", |
| 569 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_ERROR_CODE, error_string)); | 510 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_ERROR_CODE, error_string)); |
| 570 | 511 |
| 571 base::ListValue* suggestions = new base::ListValue(); | 512 base::ListValue* suggestions = new base::ListValue(); |
| 572 | 513 |
| 573 // Platform specific instructions for diagnosing network issues on OSX and | 514 // Platform specific instructions for diagnosing network issues on OSX and |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 #if defined(OS_CHROMEOS) | 742 #if defined(OS_CHROMEOS) |
| 802 GURL learn_more_url(kAppWarningLearnMoreUrl); | 743 GURL learn_more_url(kAppWarningLearnMoreUrl); |
| 803 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue(); | 744 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue(); |
| 804 suggest_learn_more->SetString("msg", | 745 suggest_learn_more->SetString("msg", |
| 805 l10n_util::GetStringUTF16( | 746 l10n_util::GetStringUTF16( |
| 806 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); | 747 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); |
| 807 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); | 748 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); |
| 808 error_strings->Set("suggestionsLearnMore", suggest_learn_more); | 749 error_strings->Set("suggestionsLearnMore", suggest_learn_more); |
| 809 #endif // defined(OS_CHROMEOS) | 750 #endif // defined(OS_CHROMEOS) |
| 810 } | 751 } |
| OLD | NEW |